# lecture6 - CS 473: Algorithms Chandra Chekuri...

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

CS 473: Algorithms Chandra Chekuri [email protected] 3228 Siebel Center University of Illinois, Urbana-Champaign Fall 2009 Chekuri CS473ug

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

View Full Document
Part I Breadth First Search Chekuri CS473ug
Breadth First Search (BFS) Overview BFS is obtained from BasicSearch by processing edges using a data structure called a queue . It processes the vertices in the graph in the order of their shortest distance from the vertex s (the start vertex). DFS good for exploring graph structure BFS good for exploring distances Chekuri CS473ug

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

View Full Document
Queue Data Structure Queues A queue is a list of elements which supports the following operations Chekuri CS473ug
Queue Data Structure Queues A queue is a list of elements which supports the following operations enqueue : Adds an element to the end of the list Chekuri CS473ug

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

View Full Document
Queue Data Structure Queues A queue is a list of elements which supports the following operations enqueue : Adds an element to the end of the list dequeue : Removes an element from the front of the list Chekuri CS473ug
Queue Data Structure Queues A queue is a list of elements which supports the following operations enqueue : Adds an element to the end of the list dequeue : Removes an element from the front of the list Elements are extracted in ﬁrst-in ﬁrst-out (FIFO) order, i.e., elements are picked in the order in which they were inserted. Chekuri CS473ug

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

View Full Document
BFS Algorithm Given (undirected or directed) graph G = ( V , E ) and node s V BFS(s) Mark all vertices as unvisited Initialize search tree T to be empty Mark vertex s as visited set Q to be the empty queue enq(s) while Q is nonempty u = deq(Q) for each vertex v in Adj(u) if v is not visited add edge (u,v) to T Mark v as visited and enq(v) Analysis The algorithm runs in time Chekuri CS473ug
BFS Algorithm Given (undirected or directed) graph G = ( V , E ) and node s V BFS(s) Mark all vertices as unvisited Initialize search tree T to be empty Mark vertex s as visited set Q to be the empty queue enq(s) while Q is nonempty u = deq(Q) for each vertex v in Adj(u) if v is not visited add edge (u,v) to T Mark v as visited and enq(v) Analysis The algorithm runs in time O ( n + m ). Chekuri CS473ug

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

View Full Document
BFS: An Example in Undirected Graphs 1 2 3 4 5 6 7 8 1 1. [1] Chekuri CS473ug
BFS: An Example in Undirected Graphs 1 2 3 4 5 6 7 8 1 2 3 1. [1] 2. [2,3] Chekuri CS473ug

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

View Full Document
BFS: An Example in Undirected Graphs 1 2 3 4 5 6 7 8 1 2 3 4 5 1. [1] 2. [2,3] 3. [3,4,5] Chekuri CS473ug
BFS: An Example in Undirected Graphs 1 2 3 4 5 6 7 8 1 2 3 4 5 7 8 1. [1] 4. [4,5,7,8] 2. [2,3] 3. [3,4,5] Chekuri CS473ug

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

View Full Document
BFS: An Example in Undirected Graphs 1 2 3 4 5 6 7 8 1 2 3 4 5 7 8 1. [1] 4. [4,5,7,8] 2. [2,3] 5. [5,7,8] 3. [3,4,5] Chekuri CS473ug
BFS: An Example in Undirected Graphs 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1. [1] 4. [4,5,7,8] 2. [2,3] 5. [5,7,8] 3. [3,4,5] 6. [7,8,6] Chekuri CS473ug

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

View Full Document
BFS: An Example in Undirected Graphs 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1. [1] 4. [4,5,7,8] 7. [8,6] 2. [2,3] 5. [5,7,8] 3. [3,4,5] 6. [7,8,6] Chekuri CS473ug
BFS: An Example in Undirected Graphs 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1. [1] 4. [4,5,7,8] 7. [8,6] 2. [2,3] 5. [5,7,8] 8. [6] 3. [3,4,5] 6. [7,8,6] Chekuri CS473ug

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

View Full Document
BFS: An Example in Undirected Graphs 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 1. [1] 4. [4,5,7,8] 7. [8,6] 2. [2,3] 5. [5,7,8] 8. [6] 3. [3,4,5] 6. [7,8,6] 9. [] Chekuri CS473ug
BFS: An Example in Undirected Graphs 1 2

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

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

## This note was uploaded on 01/22/2012 for the course CS 573 taught by Professor Chekuri,c during the Fall '08 term at University of Illinois, Urbana Champaign.

### Page1 / 109

lecture6 - CS 473: Algorithms Chandra Chekuri...

This preview shows document pages 1 - 20. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online