Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC 172 DATA STRUCTURES.

Similar presentations


Presentation on theme: "CSC 172 DATA STRUCTURES."— Presentation transcript:

1 CSC 172 DATA STRUCTURES

2 Traversing graphs Depth-First Search Breath-First Search
like a post-order traversal of a tree Breath-First Search Less like tree traversal

3 Traversing graphs Depth-First Search Breath-First Search
like a post-order traversal of a tree Breath-First Search Less like tree traversal Priority-First Search Good for Shortest Path Dijkstra's Algorithm

4 Breadth-First Search Unweighted Shortest Path
Starting vertex has level 0 (anchor vertex) Visit (mark) all vertices that are only one edge away mark each vertex with its “level” One edge away from level 0 is level 1 One edge away from level 1 is level 2 Etc

5 Example A B C D E F G H I J K L M N O P

6 Example A B C D E F G H I J K L M N O P

7 Example A B C D E F G H I J K L M N O P

8 Example 1 A B C D E F G H I J K L M N O P

9 Example 1 A B C D E F G H I J K L M N O P

10 Example 2 1 A B C D E F G H I J K L M N O P

11 Example 2 1 A B C D E F G H I J K L M N O P

12 Example 2 1 3 A B C D E F G H I J K L M N O P

13 Example 2 1 3 A B C D E F G H I J K L M N O P

14 Example 2 1 3 A B C D E F G H I J K 4 L M N O P

15 Example 2 1 3 A B C D E F G H I J K 4 L M N O P

16 Example 2 1 3 A B C D E F G H I J K 4 L M N O P

17 Example 2 1 3 A B C D E F G H I J K 4 L M N O P

18 Example 2 1 3 A B C D E F G H I J K 4 L 5 M N O P

19 Example 2 1 3 A B C D E F G H I J K 4 L 5 M N O P

20 BFS Tree 2 1 3 A B C D E F G H I J K 4 L 5 M N O P

21 Dijkstra's Algorithm // for each Vertex v { v.dist = infinity ;
v.known = false ; }

22 Dijkstra's Algorithm while (there is an unknown vertex) {
v = delMin() ; // get the next one off the queue v.known = true ; for each Vertex w adjacent to v { if (!w.known) { if (v.dist + dist_v2w < w.dist){ w.dist = vdist + dist_v2w ; enqueue(w) ]


Download ppt "CSC 172 DATA STRUCTURES."

Similar presentations


Ads by Google