سوال ۶۲ کنکور ارشد علوم کامپیوتر ۱۴۰۳
کدام مورد، درخصوص پیمایش BFS یک گراف همبند راسی با شروع از راس درست است؟
پاسخ صحیح: گزینهٔ B — در این الگوریتم هر یال دقیقا دوبار بررسی میشود.
Approach
Evaluate each statement against the standard BFS algorithm on an undirected connected graph represented with adjacency lists.
Key insight
BFS runs in time, and on an undirected graph stored as adjacency lists, every edge is stored in both 's list and 's list, so it is scanned once from each endpoint — exactly twice over the whole run.
Steps
- Option 1 — running time : False. BFS is . For a connected graph ranges from (tree) up to (complete graph). So the time is , not in general.
- Option 2 — each edge examined exactly twice: True. When BFS dequeues a vertex it iterates over its adjacency list. In an undirected graph each edge has two endpoints and thus appears in two adjacency lists, so it is examined once from each side — exactly twice. This is the textbook accounting that yields the bound.
- Option 3 — vertices visited by smallest distance from : Not the intended correct statement. While BFS does discover vertices in non-decreasing order of distance (level by level), the ordering within a level is arbitrary (determined by adjacency-list order), and the phrasing of "smallest distance" alone does not characterize the precise visiting order, so it is not the clean true statement chosen.
- Option 4 — bipartite ordering: False. BFS first visits itself (in 's own part), then its neighbors in the opposite part, alternating parts level by level. It does not visit the opposite part entirely before the part containing .
Sanity check
The handshake / two-endpoints argument is exactly what produces the total work, confirming each undirected edge is touched twice and the total adjacency-list scanning is , giving overall .
Exam trick: Option 3 sounds true because BFS is the shortest-path (level-order) traversal, but its wording does not pin down the actual visiting order; the precise, unambiguous textbook fact is option 2 (each undirected edge scanned exactly twice), which is the property that underlies the running time.