lecture6 - CS 473: Algorithms Chandra Chekuri...

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

View Full Document Right Arrow Icon
CS 473: Algorithms Chandra Chekuri [email protected] 3228 Siebel Center University of Illinois, Urbana-Champaign Fall 2009 Chekuri CS473ug
Background image of page 1

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

View Full DocumentRight Arrow Icon
Part I Breadth First Search Chekuri CS473ug
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
Queue Data Structure Queues A queue is a list of elements which supports the following operations Chekuri CS473ug
Background image of page 4
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
Background image of page 5

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

View Full DocumentRight Arrow Icon
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
Background image of page 6
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 first-in first-out (FIFO) order, i.e., elements are picked in the order in which they were inserted. Chekuri CS473ug
Background image of page 7

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

View Full DocumentRight Arrow Icon
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
Background image of page 8
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
Background image of page 9

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

View Full DocumentRight Arrow Icon
BFS: An Example in Undirected Graphs 1 2 3 4 5 6 7 8 1 1. [1] Chekuri CS473ug
Background image of page 10
BFS: An Example in Undirected Graphs 1 2 3 4 5 6 7 8 1 2 3 1. [1] 2. [2,3] Chekuri CS473ug
Background image of page 11

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

View Full DocumentRight Arrow Icon
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
Background image of page 12
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
Background image of page 13

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

View Full DocumentRight Arrow Icon
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
Background image of page 14
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
Background image of page 15

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

View Full DocumentRight Arrow Icon
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
Background image of page 16
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
Background image of page 17

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

View Full DocumentRight Arrow Icon
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
Background image of page 18
BFS: An Example in Undirected Graphs 1 2
Background image of page 19

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

View Full DocumentRight Arrow Icon
Image of page 20
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 Right Arrow Icon
Ask a homework question - tutors are online