سوال ۵۸ کنکور ارشد مهندسی کامپیوتر ۱۴۰۳
فرض کنید ، یک گراف همبند وزندار باشد. چند مورد از گزارههای زیر درست است؟
- اگر وزن تمام یالهای گراف با هم برابر باشد، میتوان درخت فراگیر کمینه آن را با الگوریتمی از مرتبه بدست آورد.
- اگر گراف جهتدار باشد، یافتن دور در این گراف را میتوان در مرتبه محاسبه کرد.
- چنانچه وزن یالهای گراف دوبهدو متمایز باشند، الگوریتم پریم و کروسکال دارای جواب یکسانی هستند.
- الگوریتم پریم را میتوان بهنحوی پیادهسازی کرد که همواره مرتبه آن بدتر از الگوریتم کروسکال نباشد.
پاسخ صحیح: گزینهٔ D — ۴
Check each statement on a connected weighted graph . Connectivity guarantees , so and .
Statement 1 — TRUE. When every edge has the same weight, every spanning tree has the same total weight, so any spanning tree is a minimum spanning tree. A spanning tree of a connected graph is produced by a single BFS or DFS in , which equals here. No heap or sorting is needed.
Statement 2 — TRUE. A cycle in a directed graph is detected by a single DFS: a back edge to a vertex currently on the recursion stack (gray vertex) signals a cycle. DFS runs in .
Statement 3 — TRUE. If all edge weights are pairwise distinct, the minimum spanning tree is unique. Both Prim and Kruskal are correct MST algorithms, so each returns this same unique tree. (The MST can fail to be unique only when ties among edge weights exist.)
Statement 4 — TRUE. Kruskal's algorithm costs (dominated by sorting the edges). Prim's algorithm with a Fibonacci heap costs , and with a binary heap . Since Prim (Fibonacci-heap version) is never asymptotically worse than Kruskal — and is strictly better on dense graphs. So an implementation of Prim meeting the claim exists.
All four statements are correct, so the count is , which is option 4.
Exam trick: "Pairwise-distinct edge weights unique MST" is the key fact behind statement 3; ties are the only source of multiple MSTs. And remember Prim-with-Fibonacci-heap matches or beats Kruskal's .