# Distance0 distance1 distance2 distance3

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

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

Unformatted text preview: order Finds connected component Finds shortest number of edges between start node and all other nodes Fast/Efficient Example Run Example Run Breadth­First Search from vertex 8. Example Run Example Run Breadth­First Search from vertex 8. Distance 0 Distance 1 Distance 2 Distance 3 Breadth First Search Breadth First Search BFS intuition. Explore outward from s in all possible directions, adding nodes one "layer" at a time. s L1 L2 L n­1 BFS algorithm. – L0 = { s }. – L1 = all neighbors of L0. – L2 = all nodes that do not belong to L0 or L1, and that have an edge to a node in L1. – Li+1 = all nodes that do not belong to an earlier layer, and that have an edge to a node in Li. FACT: For each i, Li consists of all nodes at distance exactly i from s. There is a path from s to t only if t appears in some layer. “Computer’s view” 1: 2,3 2: 1,3,4,5 3: 1,2,5,7,8 4: 2,5 5: 2,3,4,6 6: 5 7: 3,8 8: 3,7 9: 10 10: 9 11: 12 12: 11,13 13: 12 “Computer’s view” Mark 8 as “visited”; put 3 and 7 on the list V={8} L = {3,7} Take next thing on list (3), move to V, and put it’s neighbors on list if not in V or L yet. V = {8, 3} L = {7, 1, 2, 5} Take next thing on list (7), move to V, and put it’s neighbors on list if not in V or L yet V = {8, 3 ,7} L = {1, 2, 5} 1: 2,3 2: 1,3,4,5 3: 1,2,5,7,8 4: 2,5 5: 2,3,4,6 6: 5 7: 3,8 8: 3,7 9: 10 10: 9 11: 12 12: 11,13 13: 12 “Computer’s view” V = {8, 3 ,7} L = {1, 2, 5} Mark 1 as “visited”; no new neighbors V={8, 3, 7, 1} L = {2, 5} Take next thing on list (2), move to V, and put it’s neighbors on list if not in V or L yet. V = {8, 3, 7, 1, 2} L = {5, 4} Take next thing on list (5), move to V, and put it’s neighbors on list if not in V or L yet V = {8, 3, 7, 1, 2, 5} L = {4, 6} 1: 2,3 2: 1,3,4,5 3: 1,2,5,7,8 4: 2,5 5: 2,3,4,6 6: 5 7: 3,8 8: 3,7 9: 10 10: 9 11: 12 12: 11,13 13: 12 “Computer...
View Full Document

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern