Lecture topic-BruteForce

Be implemented on a stack how about breadth first

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: g h Depth-first search could be implemented on a stack How about breadth-first search Design and Analysis of Algorithms – Chapter 4 18 Breadth-first search algorithm bfs(v) count := count + 1 mark v with count mark for each vertex v∈ V initialize queue with v initialize do do while queue is not empty do if v is marked if a := front of queue with 0 for each vertex w adjacent to a do for BFS(G) count :=0 mark each vertex with 0 bfs(v) bfs(v) if w is marked with 0 if count := count + 1 count mark w with count mark add w to the end of the queue add remove a from the front of the queue remove from Design and Analysis of Algorithms – Chapter 4 19 Breadth-first search: Notes a BFS has same efficiency as DFS and can be BFS implemented with graphs represented as: implemented • • Adjacency matrices: Θ(V2) Adjacency Adjacency linked lists: Θ(V+E) Adjacency Design and Analysis of Algorithms – Chapter 4 20 In-class exercise In-class a Exercise 3.2.3 Gadget testing • A firm wants to determine the highest floor of firm its n-story headquarters from which a gadget can fall with no imp...
View Full Document

Ask a homework question - tutors are online