

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 6
click for more info
Not enough gems
Cost: 6 gems
1: Graphs
incomplete
2: Graph Review
incomplete
3: Adjacency List
incomplete
4: Representing Graphs
incomplete
5: Adjacent Nodes
incomplete
6: Unconnected Vertices
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
In the first assignment, we created a graph using an adjacency matrix:
| 0 | 1 | 2 | 3 | 4 | |
|---|---|---|---|---|---|
| 0 | False | True | False | False | True |
| 1 | True | False | True | True | True |
| 2 | False | True | False | True | False |
| 3 | False | True | True | False | True |
| 4 | True | True | False | True | False |
Through the rest of this course, we'll primarily be using an adjacency list instead. An adjacency list stores a list of vertices for each vertex that indicates where the connections are:
| 0 | connects with | 1 | 4 | ||
| 1 | connects with | 0 | 2 | 3 | 4 |
| 2 | connects with | 1 | 3 | ||
| 3 | connects with | 1 | 2 | 4 | |
| 4 | connects with | 0 | 1 | 3 |
Let's rebuild our Graph class using an adjacency list.
graph as a data member.result = {0: {1, 4}, 1: {0, 2, 3, 4}, 2: {1, 3}, 3: {1, 2, 4}, 4: {0, 1, 3}}