Download presentation

Presentation is loading. Please wait.

Published byAiden Graves Modified over 3 years ago

3
EXAMPLE: X Y Z T 5 VERTICES 6 EDGES S

4
Collection List Set ArrayList LinkedList SortedSet HashSet TreeSet

8
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?

10
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?

11
Collection List Set ArrayList LinkedList SortedSet HashSet TreeSet THIS UNDIRECTED GRAPH IS ACYCLIC.

21
Collection List Set ArrayList LinkedList SortedSet HashSet TreeSet

31
x v Y Z T S ASSUME THE VERTICES ARE ENTERED IN ALPHABETICAL ORDER. PERFORM A BREADTH-FIRST ITERATION FROM S.

39
X V Y Z T S

40
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.

41
vertex_queue vertex where iterator returned by ++ is positioned S T, ZS Z, YT Y, V, XZ V, XY XV X

42
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( ).

44
Collection List Set ArrayList LinkedList SortedSet HashSet TreeSet

46
A STACK!

49
X V Y Z T S

50
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.

51
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.

Similar presentations

Presentation is loading. Please wait....

OK

Using Search in Problem Solving

Using Search in Problem Solving

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google