{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# 09 - Queues Stacks Graph Traversing Data Structures and...

This preview shows pages 1–7. Sign up to view the full content.

Queues, Stacks, Graph Traversing Data Structures and Algorithms Andrei Bulatov

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Algorithms – Queues, Stacks, Graph Traversing 9-2 Graph Reminder Vertices and edges Nodes and arcs Representation of graphs: -- adjacency matrix -- adjacency lists Degrees of vertices, indegree, outdegree; regular graphs Walks, paths, and cycles; lengths Connectivity, connected components Trees, root, leaves, parent and child, descendant and ancestor
Algorithms – Queues, Stacks, Graph Traversing 9-3 Graph Traversing Often we need to visit every vertex of a graph There are many ways to do that, two are most usual: breadth first search and depth first search In both cases we start with some vertex s For BFS: - visit neighbors of s - then visit neighbors of neighbors in turn - this data structure is called a queue s t u w v x t u v w x

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Algorithms – Queues, Stacks, Graph Traversing 9-4 Graph Traversing: BFS Breadth First Search(G,s) set Discov[s]:=true and Discov[v]:=false for v s Enqueue(Q,s) while Q is not empty do set u:=Dequeue(Q) for each (u,v) E do if Discov[v]=false then do set Discov[v]:=true; Enqueue(Q,v) endif endfor endwhile
Algorithms – Queues, Stacks, Graph Traversing 9-5 Example s t u w v x

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Algorithms – Queues, Stacks, Graph Traversing 9-6 Queues Through Array If we store a queue in an array, we need two pointers to the head and to the tail of the queue 7 2 4 6 8 3 9 6 8 5 head tail tail head
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}