Challenge - 5 Problems
Graph Terminology Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of adjacency list for an undirected weighted graph
What is the printed adjacency list after running this code for an undirected weighted graph?
DSA Python
graph = {
'A': [('B', 3), ('C', 5)],
'B': [('A', 3), ('C', 1)],
'C': [('A', 5), ('B', 1)]
}
for vertex, edges in graph.items():
print(f"{vertex} -> {edges}")Attempts:
2 left
💡 Hint
Remember that in an undirected graph, edges appear in both connected vertices' lists.
✗ Incorrect
In an undirected weighted graph, each edge is stored twice: once for each vertex it connects, with the same weight.
❓ Predict Output
intermediateOutput of adjacency list for a directed graph
What is the printed adjacency list after running this code for a directed graph?
DSA Python
graph = {
'X': ['Y', 'Z'],
'Y': ['Z'],
'Z': []
}
for vertex, edges in graph.items():
print(f"{vertex} -> {edges}")Attempts:
2 left
💡 Hint
In a directed graph, edges go only one way from source to destination.
✗ Incorrect
The adjacency list for a directed graph shows edges only from the source vertex to its neighbors, not the other way around.
🧠 Conceptual
advancedIdentify the type of graph from description
Which type of graph is described by: "Edges have directions and weights, and edges only go one way from one vertex to another"?
Attempts:
2 left
💡 Hint
Edges have direction and weights, so both properties matter.
✗ Incorrect
A graph with edges that have direction and weights is called a directed weighted graph.
🔧 Debug
advancedFind the error in this graph representation
What error will this code cause when representing an undirected graph?
DSA Python
graph = {
'P': ['Q'],
'Q': []
}
# Adding edge from Q to P missing
for vertex, edges in graph.items():
print(f"{vertex} -> {edges}")Attempts:
2 left
💡 Hint
Check if edges appear in both vertices for undirected graphs.
✗ Incorrect
The code runs fine but misses the edge from 'Q' to 'P', so the undirected edge is incomplete.
🚀 Application
expertNumber of edges in a weighted undirected graph
Given this weighted undirected graph adjacency list, how many unique edges does it have?
DSA Python
graph = {
'M': [('N', 2), ('O', 4)],
'N': [('M', 2), ('O', 3)],
'O': [('M', 4), ('N', 3)]
}Attempts:
2 left
💡 Hint
Count each edge only once since the graph is undirected.
✗ Incorrect
Each edge appears twice in the adjacency list, once for each vertex. Counting unique edges gives 3.
