Graphs Graphs Definitions Implementation/Representation of graphs - - PowerPoint PPT Presentation

graphs graphs
SMART_READER_LITE
LIVE PREVIEW

Graphs Graphs Definitions Implementation/Representation of graphs - - PowerPoint PPT Presentation

CS171 Introduction to Computer Science II Science II Graphs Graphs Definitions Implementation/Representation of graphs Search Traversing graphs Graph traversal: visit each vertex in the graph exactly once There are in


slide-1
SLIDE 1

CS171 Introduction to Computer Science II Science II

Graphs

slide-2
SLIDE 2

Graphs

Definitions Implementation/Representation of graphs Search

slide-3
SLIDE 3
slide-4
SLIDE 4

Traversing graphs

Graph traversal: visit each vertex in the graph exactly once There are in general two ways to traverse a graph

Depth-first search (DFS): Uses a Stack or recursion Depth-first search (DFS): Uses a Stack or recursion

Begins at a node, explores as far as possible along each branch before backtracking

Breath-first search (BFS): uses a Queue

Begins at a node, explores all its neighboring nodes. Then for each of those nodes, explores their unexplored neighbor nodes, and so on

slide-5
SLIDE 5
slide-6
SLIDE 6
slide-7
SLIDE 7
slide-8
SLIDE 8
slide-9
SLIDE 9
slide-10
SLIDE 10

Depth-First Search (DFS) – Nonrecursive algorithm

Visit an unvisited neighbor of the current node if possible, push it on the stack Pop a node from the stack, make it current Pop a node from the stack, make it current node, repeat the above Done when the stack is empty

slide-11
SLIDE 11
slide-12
SLIDE 12
slide-13
SLIDE 13
slide-14
SLIDE 14
slide-15
SLIDE 15
slide-16
SLIDE 16

Graph Search

Depth-first search Breadth-first search