سوال ۶۳ کنکور ارشد مهندسی کامپیوتر ۱۴۰۰
چند مورد از داده ساختارهای زیر نمیشود ساخت که اعمال گفته شده را در زمان خواسته شده انجام دهد؟
- عملهای ، ، و را در انجام دهد.
- عملهای ، و را در انجام دهد.
- عملهای ، را در انجام دهد.
پاسخ صحیح: گزینهٔ B — یک
Check each requested data structure independently. The hard constraint is that every listed operation must run in (worst-case constant time).
Structure 1 — , , , all . Achievable. Keep the data in a stack and maintain two auxiliary stacks, one tracking the running minimum and one the running maximum. On also push and ; on pop all three; just read the tops. Every operation is . So this one can be built.
Structure 2 — , , all . Impossible. removes the minimum element (not the top), so the min may sit in the middle and the auxiliary-stack trick collapses. More fundamentally, suppose both and ran in . Then inserting keys costs and calling times also costs , yielding the keys in sorted order in total time:
That contradicts the comparison-sort lower bound . So this one cannot be built.
Structure 3 — , all . Achievable. This is just an ordinary stack (array- or list-backed): both operations are . So this one can be built.
Only one of the three (Structure 2) is impossible, so the answer is one.
Exam trick: Whenever a structure must support
InsertandExtractMin(orDeleteMin) both in , it is impossible — the comparison-sort bound forbids it. PlainFindMin/FindMax(read-only, no removal) is fine in .