0
0
DSA Cprogramming~10 mins

Adjacency Matrix Representation in DSA C - Interactive Practice

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

Complete the code to declare a 2D adjacency matrix for 4 vertices.

DSA C
int adjacencyMatrix[4][4] = [1];
Drag options to blanks, or click blank then click option'
A{{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
B{{0}}
C0
DNULL
Attempts:
3 left
💡 Hint
Common Mistakes
Using a single zero instead of a 2D array initializer.
Using NULL which is invalid for integer arrays.
2fill in blank
medium

Complete the code to add an edge from vertex 1 to vertex 3 in the adjacency matrix.

DSA C
adjacencyMatrix[1][[1]] = 1;
Drag options to blanks, or click blank then click option'
A2
B3
C1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 3 as index which is out of bounds for vertex 3.
Confusing vertex numbers with array indices.
3fill in blank
hard

Fix the error in the code to correctly check if there is an edge from vertex 2 to vertex 0.

DSA C
if (adjacencyMatrix[2][[1]] == 1) {
    printf("Edge exists\n");
}
Drag options to blanks, or click blank then click option'
A3
B2
C1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using vertex number directly as index without subtracting 1.
Using an index out of bounds like 3.
4fill in blank
hard

Fill both blanks to complete the nested loops that print the adjacency matrix.

DSA C
for (int i = 0; i [1] 4; i++) {
    for (int j = 0; j [2] 4; j++) {
        printf("%d ", adjacencyMatrix[i][j]);
    }
    printf("\n");
}
Drag options to blanks, or click blank then click option'
A<
B<=
C>
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' causes out of bounds access.
Using '>' or '>=' causes loops not to run.
5fill in blank
hard

Fill all three blanks to create a function that initializes the adjacency matrix to zero.

DSA C
void initializeMatrix(int matrix[4][4]) {
    for (int [1] = 0; [2] < 4; [3]++) {
        for (int j = 0; j < 4; j++) {
            matrix[i][j] = 0;
        }
    }
}
Drag options to blanks, or click blank then click option'
Ai
Ci++
Dj
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'j' in outer loop which conflicts with inner loop.
Missing increment expression causes infinite loop.