0
0
DSA Cprogramming~10 mins

Why Graphs Exist and What Trees Cannot Model in DSA C - Test Your Knowledge

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

Complete the code to declare a graph adjacency list in C.

DSA C
int [1][MAX_NODES][MAX_NODES];
Drag options to blanks, or click blank then click option'
Atree
Bgraph
CadjacencyList
DadjacencyMatrix
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'tree' as the variable name which is misleading.
Using a 1D array instead of 2D for adjacency matrix.
2fill in blank
medium

Complete the code to add an edge between two nodes in an undirected graph.

DSA C
graph[u][v] = 1;
graph[[1]][[2]] = 1;
Drag options to blanks, or click blank then click option'
Au
Bv
Cw
Dx
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same node 'u' for both indices in the second line.
Using an unrelated variable like 'w' or 'x'.
3fill in blank
hard

Fix the error in the code that tries to detect cycles in a graph using DFS.

DSA C
if (visited[[1]] && parent != [1]) {
    return 1;
}
Drag options to blanks, or click blank then click option'
Anode
Bparent
Cneighbor
Dcurrent
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'parent' inside visited[] which is incorrect.
Using 'current' instead of the neighbor node.
4fill in blank
hard

Fill the blank to complete the function that prints all neighbors of a node in an adjacency matrix.

DSA C
for (int [1] = 0; [1] < numNodes; [1]++) {
    if (adjList[node][[1]] == 1) {
        printf("%d ", [1]);
    }
}
Drag options to blanks, or click blank then click option'
AnumNodes
Bi
Cnode
Dj
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'node' or 'numNodes' as loop variables.
5fill in blank
hard

Fill all three blanks to complete the code that initializes a graph with no edges.

DSA C
for (int [1] = 0; [1] < [2]; [1]++) {
    for (int [3] = 0; [3] < numNodes; [3]++) {
        graph[i][j] = 0;
    }
}
Drag options to blanks, or click blank then click option'
Ai
BnumNodes
Cj
Dnode
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'node' as a loop variable which is confusing.
Using inconsistent variable names for loops.