A network crawler keeps a frontier, the queue of records awaiting processing. It runs on a connected, undirected graph with VVV vertices and EEE edges, with no self-loops or parallel edges. Each edge counts as one hop, and the graph is stored using adjacency lists.
Compare two breadth-first search variants. Both use a first-in, first-out queue. Early marks each vertex seen when it is enqueued, records its distance then, and enqueues only unseen neighbours. Late instead runs the following code:
from collections import deque queue = deque([(start, 0)]) seen = set() distance = {} while queue: vertex, hops = queue.popleft() if vertex in seen: continue seen.add(vertex) distance[vertex] = hops for neighbour in adjacency[vertex]: if neighbour not in seen: queue.append((neighbour, hops + 1))
Assume the adjacency lists already exist and each set or queue operation shown takes constant time. Which statements are true? Select every true statement.
Late uses O(V)O(V)O(V) queue space because each vertex's neighbour list is scanned only once.
Late can take Θ(VE)\Theta(VE)Θ(VE) time because every duplicate record triggers another scan of its neighbour list.
Both variants assign shortest-path distances in edges to every vertex reached from the starting vertex.
Late takes O(V+E)O(V+E)O(V+E) time but can hold Θ(E)\Theta(E)Θ(E) queue records simultaneously on some graphs.
Unlock full course notes by signing up
Counting the work of breadth-first search
A connected, undirected road network has 1,200 intersections (vertices) and 4,500 road segments (edges), with no self-loops or repeated edges. You run one breadth-first search from a single start intersection, marking each vertex as visited when it is added to the queue.
Give each answer as an exact whole number:
the total number of adjacency-list entries the search reads when the graph is stored as adjacency lists;
Discovery and finish times on a directed graph
The directed graph below has six vertices. Its adjacency lists, each already in alphabetical order, are:
A: B, D
B: C, E