سوال ۱۰۳ کنکور ارشد مهندسی کامپیوتر ۱۴۰۱
۱۰۳- آسانسور ساختمانی ۲۰ طبقه (از همکف طبقه ۱۹) با ظرفیت حمل ۱ نفر مفروض است. فرض کنید در هر طبقه دکمهای خبردهنده وجود دارد. آسانسور با یک سیاست خودکار کار میکند: از موقعیت فعلی خود در همان جهتِ حرکت به حرکت ادامه میدهد و در هر طبقهای که برای آن درخواست (تقاضا) ثبت شده باشد توقف میکند، و تا زمانی که در همان جهت دستِکم یک درخواستِ جلوتر باقی مانده باشد جهت خود را عوض نمیکند؛ تنها هنگامی که درخواستی جلوتر در آن جهت نباشد، جهت حرکت را برعکس میکند و به همان روش به درخواستهای جهت مخالف رسیدگی میکند. این سیاستِ حرکتِ آسانسور دقیقاً معادل یکی از الگوریتمهای زمانبندیِ بازویِ دیسک است. تحتِ کدام شرطِ زیر، این سیاست دقیقاً مانندِ آن الگوریتم رفتار میکند (بهعبارتی شرطِ لازمِ آن میشود)؟
پاسخ صحیح: گزینهٔ A — وقتی آسانسور تنها پس از آنکه دیگر درخواستی در جهتِ جاری باقی نماند جهت را عوض کند، دقیقاً الگوریتم LOOK (آسانسوری) است و نبودِ گرسنگی (starvation) شرطِ لازم آن میشود.
The described policy is the textbook elevator algorithm, the disk-arm scheduling family that gave disk scheduling its name.
Mapping the analogy. The disk arm the elevator car; a track request a floor call; the seek direction the up/down travel direction.
Which variant exactly matches the description? The car keeps moving in one direction, services every pending call it passes, and reverses only when no further request remains ahead in that direction (it does not run all the way to the physical end of the shaft). That "turn around as soon as nothing is ahead" behaviour is precisely LOOK (the practical elevator algorithm), as opposed to SCAN, which always sweeps to the extreme cylinder before reversing:
| Variant | Reversal rule |
|---|---|
| SCAN | go to the extreme end of the disk, then reverse |
| LOOK | reverse as soon as no request lies ahead in the current direction |
| C-SCAN / C-LOOK | service in one direction only, then jump back to the start |
Why option 1. Because the arm sweeps back and forth and every request lies somewhere on the sweep path, any pending request is guaranteed to be served within at most one full back-and-forth pass. Hence the policy is starvation-free (no indefinite waiting) — and this bounded-waiting / no-starvation property is exactly the defining (necessary) characteristic that distinguishes the elevator (SCAN/LOOK) discipline from greedy SSTF, which can starve far-away requests. Option 1 states both facts correctly.
Why the others fail:
- Option 2 forces a trip to the top floor with no pending call — that is SCAN, not what the stem describes, and it is mislabeled SSTF.
- Option 3 describes always jumping to the globally nearest request irrespective of direction — that is SSTF, which the stem explicitly is not (the car keeps its direction), and it is mislabeled SCAN.
- Option 4 is plain FCFS (serve in request-arrival order), mislabeled C-SCAN.
Exam trick: "Reverse only when nothing is ahead" = LOOK; "always run to the physical end first" = SCAN. The elevator/SCAN-LOOK family is prized precisely because, unlike SSTF, it bounds waiting time and so avoids starvation.