Graph Algorithms Flashcards
Graph Algorithms
Graph algorithms deal with problems related to graphs, which consist of nodes (vertices) connected by edges. Examples include Shortest Path algorithms (Dijkstra’s and Bellman-Ford), Minimum Spanning Tree algorithms (Prim’s and Kruskal’s), and Topological Sorting.
Shortest Path Algorithms (Dijkstra’s, Bellman-Ford)
Shortest Path Algorithms are used to find the shortest path from a source node to all other nodes in a weighted graph. Two common algorithms for this purpose are:
Dijkstra’s Algorithm: It finds the shortest path in a graph with non-negative edge weights and produces the shortest paths from a single source to all other nodes.
Bellman-Ford Algorithm: It can handle graphs with negative edge weights and detects negative weight cycles. It finds the shortest paths from a single source to all other nodes.
Minimum Spanning Tree (Prim’s, Kruskal’s)
Minimum Spanning Tree (MST) Algorithms are used to find a subset of edges that connects all nodes in a graph with minimum total edge weight. Two common MST algorithms are:
Prim’s Algorithm: It starts with an arbitrary node and grows the MST by adding the nearest node at each step.
Kruskal’s Algorithm: It builds the MST by iteratively selecting the smallest edge that doesn’t create a cycle.
Topological Sorting
Topological Sorting is a linear ordering of nodes in a directed acyclic graph (DAG) such that for every directed edge (u, v), node u comes before node v in the ordering. It is commonly used in tasks such as scheduling and dependency resolution, where tasks or dependencies must be executed in a specific order.