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 graph
What is the printed adjacency list after adding edges to an undirected graph with vertices 1, 2, 3?
DSA Javascript
class Graph { constructor() { this.adjList = {}; } addVertex(v) { if (!this.adjList[v]) this.adjList[v] = []; } addEdge(v, w) { this.adjList[v].push(w); this.adjList[w].push(v); } } const g = new Graph(); g.addVertex(1); g.addVertex(2); g.addVertex(3); g.addEdge(1, 2); g.addEdge(2, 3); console.log(g.adjList);
Attempts:
2 left
💡 Hint
Remember that in an undirected graph, edges are added both ways between vertices.
✗ Incorrect
The addEdge method adds each vertex to the other's adjacency list, so vertex 1 connects to 2, vertex 2 connects to 1 and 3, and vertex 3 connects to 2.
❓ Predict Output
intermediateOutput of adjacency list for a directed weighted graph
What is the printed adjacency list after adding weighted edges to a directed graph with vertices 'A', 'B', 'C'?
DSA Javascript
class Graph { constructor() { this.adjList = {}; } addVertex(v) { if (!this.adjList[v]) this.adjList[v] = []; } addEdge(v, w, weight) { this.adjList[v].push({node: w, weight}); } } const g = new Graph(); g.addVertex('A'); g.addVertex('B'); g.addVertex('C'); g.addEdge('A', 'B', 5); g.addEdge('B', 'C', 3); console.log(g.adjList);
Attempts:
2 left
💡 Hint
In a directed weighted graph, edges have direction and weights stored as objects.
✗ Incorrect
Edges are stored only from source to destination with weight. 'A' connects to 'B' with weight 5, 'B' connects to 'C' with weight 3, 'C' has no outgoing edges.
🧠 Conceptual
advancedIdentify the graph type from description
Which graph type is described as having edges with no direction and weights assigned to each edge?
Attempts:
2 left
💡 Hint
Edges without direction mean connections go both ways.
✗ Incorrect
An undirected weighted graph has edges that connect vertices both ways and each edge has a weight.
❓ Predict Output
advancedOutput of adjacency matrix for directed graph
What is the adjacency matrix after adding edges (0->1), (1->2), (2->0) to a directed graph with 3 vertices?
DSA Javascript
const vertices = 3; const matrix = Array(vertices).fill(null).map(() => Array(vertices).fill(0)); function addEdge(m, from, to) { m[from][to] = 1; } addEdge(matrix, 0, 1); addEdge(matrix, 1, 2); addEdge(matrix, 2, 0); console.log(matrix);
Attempts:
2 left
💡 Hint
In adjacency matrix for directed graph, only the [from][to] cell is set to 1.
✗ Incorrect
Edges 0->1, 1->2, 2->0 set matrix[0][1], matrix[1][2], matrix[2][0] to 1. Others remain 0.
🧠 Conceptual
expertNumber of edges in a complete undirected graph
How many edges are there in a complete undirected graph with 7 vertices?
Attempts:
2 left
💡 Hint
Use the formula n*(n-1)/2 for edges in a complete undirected graph.
✗ Incorrect
A complete undirected graph with n vertices has n*(n-1)/2 edges. For n=7, edges = 7*6/2 = 21.
