Complete the code to declare a graph adjacency list in C.
int [1][MAX_NODES][MAX_NODES];The adjacency matrix is a 2D array representing edges between nodes in a graph.
Complete the code to add an edge between two nodes in an undirected graph.
graph[u][v] = 1; graph[[1]][[2]] = 1;
For undirected graphs, edges are bidirectional, so we mark both graph[u][v] and graph[v][u] as 1.
Fix the error in the code that tries to detect cycles in a graph using DFS.
if (visited[[1]] && parent != [1]) { return 1; }
The condition checks if the neighbor is visited and is not the parent to detect a cycle.
Fill the blank to complete the function that prints all neighbors of a node in an adjacency matrix.
for (int [1] = 0; [1] < numNodes; [1]++) { if (adjList[node][[1]] == 1) { printf("%d ", [1]); } }
The loop variable 'i' is used to iterate over possible neighbors, check if adjList[node][i] == 1, and print i if connected.
Fill all three blanks to complete the code that initializes a graph with no edges.
for (int [1] = 0; [1] < [2]; [1]++) { for (int [3] = 0; [3] < numNodes; [3]++) { graph[i][j] = 0; } }
We use 'i' and 'j' as loop variables and 'numNodes' as the limit to initialize all edges to 0.