Overview.Pairwise connections between items play a critical role in a vast array of computational applications. The relationships implied by these connections lead to a host of natural questions: Is there a way to connect one item to another by following the connections? How many other items are connected to a given item? What is the shortest chain of connections between this item and this other item? The table below illustrates the diversity of applications that involve graph processing.
We progress through the four most important types of graph models: undirected graphs (with simple connections), digraphs graphs (where the direction of each connection is significant), edge-weighted graphs (where each connection has an software associated weight), and edge-weighted digraphs (where each connection has both a direction and a weight).
- 4.1 Undirected Graphs introduces the graph data type, including depth-first search and breadth-first search.
- 4.2 Directed Graphs introduces the digraph data type, including topological sort and strong components.
- 4.3 Minimum Spanning Trees describes the minimum spanning tree problem and two classic algorithms for solving it: Prim and Kruskal.
- 4.4 Shortest Paths introduces the shortest path problem and two classic algorithms for solving it: Dijkstra's algorithm and Bellman-Ford.
Java programs in this chapter.Below is a list of Java programs in this chapter. Click on the program name to access the Java code; click on the reference number for a brief description; read the textbook for a full discussion.
REF PROGRAM DESCRIPTION / JAVADOC 4.1 Graph.java undirected graph - DepthFirstSearch.java depth-first search in a graph 4.2 DepthFirstPaths.java paths in a graph (DFS) 4.3 BreadthFirstPaths.java paths in a graph (BFS) 4.4 CC.java connected components of a graph - Bipartite.java bipartite or odd cycle - Cycle.java cycle in a graph - SymbolGraph.java symbol graph - DegreesOfSeparation.java degrees of separation 4.5 Digraph.java directed graph - DigraphGenerator.java generate random digraphs 4.4 DirectedDFS.java depth-first search in a digraph - DepthFirstDirectedPaths.java paths in a digraph (DFS) - DirectedCycle.java cycle in a digraph - DepthFirstOrder.java depth-first order in a digraph 4.5 Topological.java topological order in a DAG - BreadthFirstDirectedPaths.java paths in a digraph (BFS) - TransitiveClosure.java transitive closure - SymbolDigraph.java symbol digraph 4.6 KosarajuSharirSCC.java strong components in a digraph 4.7 EdgeWeightedGraph.java edge-weighted graph - Edge.java weighted edge 4.8 LazyPrimMST.java MST (lazy Prim) - PrimMST.java MST (Prim) 4.9 KruskalMST.java MST (Kruskal) - BoruvkaMST.java MST (Boruvka) 4.10 EdgeWeightedDigraph.java edge-weighted digraph - DirectedEdge.java weighted, directed edge 4.11 DijkstraSP.java shortest paths (Dijkstra) - DijkstraAllPairsSP.java all-pairs shortest paths 4.12 AcyclicSP.java shortest paths in a DAG - AcyclicLP.java longest paths in a DAG - CPM.java critical path method 4.13 BellmanFordSP.java shortest paths (Bellman-Ford) - EdgeWeightedDirectedCycle.java cycle in an edge-weighted digraph 4.15 Arbitrage.java arbitrage detection - FloydWarshall.java all-pairs shortest paths (dense) - AdjMatrixEdgeWeightedDigraph.java edge-weighted graph (dense)