In a SCAN algorithm implementation, the disk head is at 40 and requests are [10, 20, 30, 50, 60]. The code incorrectly services requests in ascending order regardless of head direction. What is the primary logical error?
AThe algorithm services requests only in descending order
BThe algorithm reverses direction too early before reaching the disk end
CThe algorithm ignores the current head direction and always sorts requests ascending
DThe algorithm does not include the current head position in servicing
Step-by-Step Solution
Solution:
Step 1: Understand SCAN behavior
SCAN services requests in the direction of head movement, then reverses at disk end.
Step 2: Identify error in code logic
Servicing requests always in ascending order ignores the head's current direction, violating SCAN's principle.
Step 3: Correct approach
Requests should be serviced in ascending order when moving up, descending when moving down.
Final Answer:
The algorithm ignores the current head direction and always sorts requests ascending -> Option C
Quick Check:
SCAN must consider head direction when ordering requests [OK]
Quick Trick:SCAN must respect head direction when ordering requests [OK]
Common Mistakes:
MISTAKES
Sorting requests only ascending without direction check
Not reversing direction at disk ends
Skipping requests on return path
Master "Design — Elevator System" in LLD
9 interactive learning modes - each teaches the same concept differently