EXAMPLE: X Y Z T 5 VERTICES 6 EDGES S
Collection List Set ArrayList LinkedList SortedSet HashSet TreeSet
X Y Z T X, Y, T, Z, S HAS LENGTH 4. SHORTEST PATH FROM X to S = ? S IN GENERAL, HOW CAN THE SMALLEST PATH BETWEEN 2 VERTICES BE DETERMINED?
X Y Z T X, Y, T, Z, X IS A CYCLE. Y, T, S, T, Y IS NOT A CYCLE. S IS Y, Z, T, S, Z, X, Y A CYCLE?
Collection List Set ArrayList LinkedList SortedSet HashSet TreeSet THIS UNDIRECTED GRAPH IS ACYCLIC.
Collection List Set ArrayList LinkedList SortedSet HashSet TreeSet
x v Y Z T S ASSUME THE VERTICES ARE ENTERED IN ALPHABETICAL ORDER. PERFORM A BREADTH-FIRST ITERATION FROM S.
X V Y Z T S
ASSUME THE EDGES ARE INSERTED INTO THE GRAPH AS FOLLOWS: S, T (SAME AS T, S) S, Z T, Y T, Z V, Y V, Z X, Y X, Z PERFORM A BREADTH-FIRST ITERATION FROM S.
vertex_queue vertex where iterator returned by ++ is positioned S T, ZS Z, YT Y, V, XZ V, XY XV X
NOTE: FOR A BREADTH-FIRST ITERATION OF A DIRECTED GRAPH, THE ALGORITHM IS THE SAME, BUT NEIGHBOR TAKES INTO ACCOUNT THE DIRECTION OF THE ARROW. A B C D FOR A BREADTH-FIRST ITERATION STARTING AT A, THE NEIGHBORS OF A ARE B AND C, BUT NOT D. D NEVER GETS ENQUEUED, AND NEVER GETS RETURNED BY next( ).
Collection List Set ArrayList LinkedList SortedSet HashSet TreeSet
A STACK!
X V Y Z T S
ASSUME THE EDGES ARE INSERTED INTO THE GRAPH AS FOLLOWS: S, T // SAME AS T, S S, Z T, Y T, Z V, Y V, Z X, Y X, Z PERFORM A DEPTH-FIRST ITERATION FROM S.
stack (top vertex is leftmost) vertex where iterator returned by ++ is positioned S Z, T S X, V, TZ Y, V, TX V, TY T V T TOP OF STACK IS LEFTMOST.