Package com.javaholics
Class GraphAlgorithms
java.lang.Object
com.javaholics.GraphAlgorithms
- All Implemented Interfaces:
GraphAlgorithmsInterface<String>
Provides graph algorithms for traversing a graph.
This class implements the GraphAlgorithmsInterface and provides methods for
performing breadth-first and depth-first traversals of a graph.
- Author:
- Lindsay Kislingbury, Lea Wiranatha
-
Constructor Summary
ConstructorDescriptionGraphAlgorithms
(Graph graph) Constructs a new GraphAlgorithms object for the given graph. -
Method Summary
Modifier and TypeMethodDescriptiongetBreadthFirstTraversal
(String origin) Performs a breadth-first traversal of this graph, starting at the given origin vertex.getDepthFirstTraversal
(String origin) Performs a depth-first traversal of this graph, starting at the given origin vertex.
-
Constructor Details
-
GraphAlgorithms
Constructs a new GraphAlgorithms object for the given graph.- Parameters:
graph
- The graph to traverse.
-
-
Method Details
-
getBreadthFirstTraversal
Performs a breadth-first traversal of this graph, starting at the given origin vertex. This method uses a queue to keep track of the vertices to visit next.- Specified by:
getBreadthFirstTraversal
in interfaceGraphAlgorithmsInterface<String>
- Parameters:
origin
- A string that labels the origin vertex of the traversal.- Returns:
- A queue containing the labels of the vertices in the order they were visited
-
getDepthFirstTraversal
Performs a depth-first traversal of this graph, starting at the given origin vertex. This method uses a stack to keep track of the vertices to visit next. This method returns a queue containing the labels of the vertices in the order they were visited.- Specified by:
getDepthFirstTraversal
in interfaceGraphAlgorithmsInterface<String>
- Parameters:
origin
- A string that labels the origin vertex of the traversal.- Returns:
- A queue containing the labels of the vertices in the order they were visited
-