Which of the following scenarios cannot be accurately represented by a tree structure?
Think about whether nodes can have multiple parents or connections.
Trees have a strict hierarchy where each node has only one parent. Social networks have many-to-many connections, which trees cannot represent.
What is the printed adjacency list after adding edges in this Go graph code?
package main import "fmt" func main() { graph := make(map[int][]int) graph[1] = append(graph[1], 2) graph[2] = append(graph[2], 3) graph[3] = append(graph[3], 1) // cycle here fmt.Println(graph) }
Check which edges are added and if cycles appear in adjacency lists.
The code adds edges 1->2, 2->3, and 3->1, creating a cycle. The adjacency list shows these connections exactly.
What will be the output of this Go code that tries to detect a cycle in a directed graph?
package main import "fmt" var graph = map[int][]int{ 1: {2}, 2: {3}, 3: {4}, 4: {2}, } var visited = map[int]bool{} var recStack = map[int]bool{} func dfs(node int) bool { if recStack[node] { return true } if visited[node] { return false } visited[node] = true recStack[node] = true for _, neighbor := range graph[node] { if dfs(neighbor) { return true } } recStack[node] = false return false } func main() { fmt.Println(dfs(1)) }
Look for cycles in the graph edges and how recursion stack is used.
The graph has a cycle 2->3->4->2. The dfs detects this cycle and returns true.
Which option contains a syntax error when adding edges to a graph adjacency list in Go?
graph := make(map[int][]int) graph[1] = append(graph[1], 2)
Check for missing assignment or wrong syntax in append usage.
Option A misses the '=' sign before append, causing a syntax error.
You want to model a transportation network where stations connect to multiple others in various directions, including loops. Which data structure best fits this?
Think about multiple connections and loops in the network.
Graphs can represent multiple connections and cycles, unlike trees or lists.
