Java Algorithms for Graph Theory
On this site you can find the source code of java classes that implement various data structures and algorithms presented at the courses
- Teoria Grafurilor si Combinatorica - year 2, IR
- Advanced Data Structures - year 2, IE
A zip file with all these classes can be downloaded from here. It contains
- the source code of the classes listed below (package ro.cs.uvt.graphs)
- sample files for graphs, which are used to test the functionality of the classes.
List of the classes implemented so far:
[This list may grow]
Graphs: General-purpose
- IGraph: interface to work with arbitrary graphs. It is implemented by the classes Graph and Digraph.
- Graph: implementation an undirected graph of vertices named 0 through V –1, using adjacency-lists representation.
- Digraph: implementation a digraph of vertices named 0 through V –1, using adjacency-lists representation.
- Edge: representation of an edge as a pair of nodes.
Graphs: BFS/DFS/Applications
- CC: DFS-based implementation of an algorithm to detect (1) the connected components of an undirected graph and (2) cycles, if any.
- SCC: DFS-based implementation of an algorithm to detect the strongly connected components of a digraph. It implements the Kosaraju-Sharir algorithm.
- DCycle: DFS-based implementation of an algorithm to detect cycles in digraphs.
- DepthFirstOrder: Computation of the preorder, postorder and reverse-postorder orderings od nodes induced by a depth-first-search traversal of a graph.
- SSPaths: abstract class with API to traverse a graph starting from a source node. It is implemented by the classes DFS and BFS
- DFS: subclass of GraphSearch which implements depth-first search for graph traversal.
- BFS: subclass of GraphSearch which implements breadth-first search for graph traversal.
- Topologic: DFS-based implementation of an algorithm to compute a topological sort of a directed acyclic graph (DAG).
Weighted graphs: General-purpose
- WeighedEdge: representation of an outgoinf edge in a weighted graph.
- WeighedEdge: representation of an outgoinf edge in a weighted graph.
- IWeightedGraph: interface to work with arbitrary weighted graphs. It is implemented by the classes WeightedGraph and WeightedDigraph.
- WeightedGraph: implementation an undirected weighted graph of vertices named 0 through V –1, using adjacency-lists representation.
- WeightedDigraph: implementation a weighted digraph of vertices named 0 through V –1, using adjacency-lists representation.
Weighted graphs
APIs for single-source paths with minimum weight:
- WeightedSSPaths: abstract class with API to find the paths with minimum weights from a source node in a weighted graph. It is implemented by the classes BellmanFord and Dijkstra
- BellmanFord: implementation of Bellman-Ford algorithm
- Dijkstra: implementation of Dijkstra algorithm
APIs for all-pairs paths with minimum weight:
-
Note
Note: The java library algs4.jar contains classes named Graph, Digraph and Edge. They are different from the classes defined here.Whenever a class is defined both here and in an external java library, you are advised to use the class defined here.