Unit 8Graphs
Follows IGNOU MCS-208, Unit 8
A graph is a set of points (vertices) joined by lines (edges). Road maps, airline routes, computer networks, web links, friendships on social media and dependencies between tasks are all graphs. This unit gives the vocabulary and the two standard ways to store a graph, then the classic graph algorithms: shortest paths from one source (Dijkstra’s algorithm, plus what to do with negative edges and acyclic graphs), shortest paths between all pairs (Floyd–Warshall), minimum spanning trees (Kruskal and Prim), the two basic traversals (breadth-first and depth-first search), and strongly connected components.
In this unit you will learn to
- define graphs, digraphs and their basic terms: path, cycle, degree, connectivity;
- store a graph as an adjacency matrix and as adjacency lists, and choose between them;
- find single-source shortest paths with Dijkstra’s algorithm and explain why it needs non-negative weights;
- handle negative edges with Bellman–Ford and acyclic graphs with topological order;
- find shortest paths between all pairs with the Floyd–Warshall algorithm;
- build minimum spanning trees with Kruskal’s and Prim’s algorithms;
- traverse a graph with BFS and DFS and record discovery and finishing times;
- find the strongly connected components of a directed graph.
Sections in this unit
- 8.1Graphs: Definitions and TerminologyWhat a graph is, directed and undirected graphs, paths, cycles, degree, connected, strongly connected and complete graphs.10 min
- 8.2Representing Graphs: Adjacency Matrix and Adjacency ListsStoring a graph as an adjacency matrix or as adjacency lists, their space and time costs, the corrected matrix of Figure 8.2 and CYP 1.7 min
- 8.3Single-Source Shortest Paths: Dijkstra's AlgorithmThe single-source shortest path problem, edge relaxation, Dijkstra's greedy algorithm traced step by step, and its running time.9 min
- 8.4Negative Edge Weights and Acyclic GraphsWhy negative edges break Dijkstra, negative-weight cycles, the Bellman-Ford algorithm, and fast shortest paths in DAGs by topological order.10 min
- 8.5All-Pairs Shortest Paths: Floyd–WarshallComputing shortest paths between every pair of vertices with the Floyd-Warshall dynamic programming algorithm in O(n cubed), with path recovery.9 min
- 8.6Minimum Cost Spanning Trees: Kruskal and PrimSpanning trees, minimum spanning trees, Kruskal's algorithm with union-find, Prim's algorithm, their costs and correct applications.11 min
- 8.7Breadth-First and Depth-First SearchTraversing a graph level by level with BFS and a queue, or deeply with DFS and recursion, discovery and finishing times, and their running times.8 min
- 8.8Strongly Connected ComponentsStrongly connected components of a digraph, the transpose graph, and the two-pass DFS algorithm (Kosaraju) with a worked example.11 min