Complete the code to declare a graph adjacency list in Java.
Map<Integer, List<Integer>> graph = new [1]<>();We use HashMap to store adjacency lists for each node in a graph.
Complete the code to add an edge from node u to node v in the graph.
graph.get(u).[1](v);We use add() to append v to the adjacency list of u.
Fix the error in the code to check if the graph contains a cycle.
if (visited[node] && [1][node]) { return true; }
recStack tracks nodes in the current recursion stack to detect cycles.
Fill both blanks to complete the BFS traversal starting from node s.
Queue<Integer> queue = new [1]<>(); queue.[2](s);
We use LinkedList as a queue and add() to enqueue the start node.
Fill all three blanks to complete the code that models a graph with cycles, which trees cannot represent.
graph.putIfAbsent([1], new ArrayList<>()); graph.get([2]).add([3]);
We ensure node 1 exists, then add node 2 as its neighbor, allowing cycles.
