Download presentation
Presentation is loading. Please wait.
1
How to navigate a maze? Can we go from s to t? Shortest route? How fast can we compute this?
2
A first attempt ExploreMaze(before, here) If here != t Let there be next reachable square in clock-wise order after before ExploreMaze(there, here)
3
ExploreMaze(here) Mark here as visited For every square there adjacent to here If there has not been visited ExploreMaze(there) A second attempt
4
How to navigate a graph? Can we go from s to t? Shortest route? How fast can we compute this?
5
DFS traversal DFS(G) counter = 0 For u in V[G] Mark u as not visited For u in V[G] If u was not visited parent[u] = nil DFS-visit(u) Mark u as visited counter = counter + 1 d[u] = counter For v adjacent to u If v was not visited parent[v] = u DFS-visit(v) counter = counter + 1 f[u] = counter
6
L 1 : nodes reachable by one edge from s L i+1 : nodes not in L 1,…,L i reachable by one edge from L i BFS traversal Compute layers L 1, L 2,… such that nodes in layer L k are at distance k from s.
7
BFS(G,s) For u in V[G] Mark u as not discovered Q = empty queue Mark s as discovered dist[s] = 0 parent[s] = nil Add(Q,s) BFS traversal While Q is not empty u = RemoveFirst(Q) For v adjacent to u If v was not discovered Mark v as discovered dist[v] = dist[u] + 1 parent[v] = u Add(Q,v)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.