0
0
DSA Cprogramming~10 mins

Adjacency List vs Matrix When to Choose Which in DSA C - Interactive Comparison Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare an adjacency matrix for a graph with 5 vertices.

DSA C
int graph[5][5] = [1];
Drag options to blanks, or click blank then click option'
A{{5}}
B{{1}}
C{{-1}}
D{{0}}
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 0 initializes all edges as present.
Using -1 is invalid for adjacency matrix initialization.
2fill in blank
medium

Complete the code to add an edge from vertex 2 to vertex 4 in an adjacency matrix.

DSA C
graph[2][[1]] = 1;
Drag options to blanks, or click blank then click option'
A4
B3
C2
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using index 5 causes out-of-bounds error.
Using index 3 adds edge to wrong vertex.
3fill in blank
hard

Fix the error in the adjacency list insertion code to add vertex 3 to vertex 1's list.

DSA C
adjList[1].push_back([1]);
Drag options to blanks, or click blank then click option'
A3
B1
C0
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Pushing the source vertex instead of the destination.
Using an invalid vertex index.
4fill in blank
hard

Fill both blanks to create an adjacency list for a graph with 4 vertices.

DSA C
std::vector<int> adjList[[1]];

adjList[0].push_back([2]);
Drag options to blanks, or click blank then click option'
A4
B3
C1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong size for adjacency list array.
Pushing incorrect vertex number.
5fill in blank
hard

Fill all three blanks to check if an edge exists from vertex 2 to vertex 3 in an adjacency matrix.

DSA C
if (graph[[1]][[2]] [3] 1) {
    printf("Edge exists\n");
}
Drag options to blanks, or click blank then click option'
A2
B3
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong indices for vertices.
Using '!=' instead of '==' causing wrong condition.