Kursinhalt
Breadth First Search
Breadth First Search
1. What is BFS
3. Improve Your Code
4. Solving the Problems using BFS
Find All Connected Components
BFS find all connected components
Complicate the problem: find all components in a graph.
Some hints for you:
- When you’re done with the first component, save it, and start traversing again with some nodes that haven’t been visited yet.
- To split your components, you can use an upgraded
visited
list: put0
if vertex is not visited yet, or putk
if vertex is ink
th component. - Return tuple of lists of vertex numbers, one list for each component. Create it by using an upgraded
visited
list.
Aufgabe
Swipe to start coding
Implement getComponents()
function.
War alles klar?
Danke für Ihr Feedback!
Abschnitt 2. Kapitel 5
Find All Connected Components
BFS find all connected components
Complicate the problem: find all components in a graph.
Some hints for you:
- When you’re done with the first component, save it, and start traversing again with some nodes that haven’t been visited yet.
- To split your components, you can use an upgraded
visited
list: put0
if vertex is not visited yet, or putk
if vertex is ink
th component. - Return tuple of lists of vertex numbers, one list for each component. Create it by using an upgraded
visited
list.
Aufgabe
Swipe to start coding
Implement getComponents()
function.
War alles klar?
Danke für Ihr Feedback!
Abschnitt 2. Kapitel 5