سوال ۵۷ کنکور ارشد مهندسی کامپیوتر ۱۴۰۵
آرایه A به طول n بهصورت حلقوی مرتب است. یعنی اگر ابتدا و انتهای A را به هم بچسبانیم از یک درایه به بعد آرایه مرتب است. برای مثال آرایه [۶۰, ۷۰, ۸۰, ۱۰, ۲۰, ۳۰, ۴۰, ۵۰] بهصورت حلقوی مرتب است. بهترین الگوریتم برای یافتن کوچکترین عنصر A از چه مرتبهای است؟
پاسخ صحیح: گزینهٔ C —
The array is a rotated sorted array with distinct keys: a strictly increasing sequence that has been cyclically shifted. Its minimum is the unique rotation point — the single index where (with wrap-around). Everywhere else the array is increasing.
Because there is exactly one such "drop," we can locate it with binary search rather than scanning all elements.
Invariant. Maintain a window guaranteed to contain the minimum, and at each step compare the middle element with the right end :
- If : the drop lies to the right of , so set .
- Otherwise (): the segment is already increasing, so the minimum is at or to its left — set .
Each step halves the window and does work, giving
For the example this converges onto the minimum in probes. So the best achievable order is — option 3. A full linear scan (option 4) works but is not optimal, while and are not attainable for this comparison problem.
Pitfall: The bound assumes distinct keys. If equal elements are allowed, an tie leaves the decision ambiguous and the worst case degrades to . The example here has distinct values, so binary search applies.