Bird
Raised Fist0
Operating Systemsknowledge~6 mins

SCAN (elevator algorithm) in Operating Systems - Full Explanation

Choose your learning style10 modes available
Introduction
Imagine a busy elevator in a tall building that needs to pick up and drop off passengers efficiently. The problem is how to serve requests in a way that reduces waiting time and avoids unnecessary back-and-forth movement. The SCAN algorithm solves this problem for disk scheduling by moving the disk arm in one direction, servicing requests along the way, then reversing direction at the end.
Explanation
Movement Direction
The SCAN algorithm moves the disk arm in one fixed direction, either towards the highest or lowest track number. It services all requests in that direction until it reaches the end of the disk. Then, it reverses direction and services requests on the way back.
SCAN moves the disk arm like an elevator, sweeping in one direction before reversing.
Request Servicing
As the disk arm moves, it picks up all pending requests on its path in order. This reduces the total movement compared to jumping back and forth randomly. Requests are handled in sequence based on their position along the disk tracks.
Requests are serviced in order along the arm's path, minimizing unnecessary movement.
End of Disk Behavior
When the disk arm reaches the last track in its current direction, it reverses and starts servicing requests in the opposite direction. This ensures no requests are missed and the arm continuously moves back and forth like an elevator.
The arm reverses direction only at the disk's ends, ensuring continuous sweeping.
Advantages Over Other Algorithms
SCAN reduces the average waiting time compared to simpler methods like First-Come-First-Serve by avoiding long delays for requests far from the current arm position. It also prevents starvation, where some requests might never get serviced.
SCAN balances efficiency and fairness by servicing requests in a sweeping pattern.
Real World Analogy

Imagine an elevator in a tall building that moves up, stopping at every floor where someone wants to get on or off. When it reaches the top floor, it reverses and moves down, again stopping at requested floors. This way, the elevator doesn't waste time going up and down randomly but follows a clear path.

Movement Direction → Elevator moving steadily up or down without skipping floors
Request Servicing → Elevator stopping at each floor where passengers want to get on or off
End of Disk Behavior → Elevator reversing direction when it reaches the top or bottom floor
Advantages Over Other Algorithms → Elevator avoiding unnecessary trips and long waits by following a predictable route
Diagram
Diagram
┌─────────────────────────────┐
│ Disk Tracks (0 to Max Track)│
├─────────────────────────────┤
│ ↑                           │
│ │  ●   ●     ●   ●          │
│ │  ↑→→→→→→→→→→→→→→→→→→→→→→ │
│ │                           │
│ │                           │
│ │                           │
│ │                           │
│ │                           │
│ ↓                           │
│ ←←←←←←←←←←←←←←←←←←←←←←←←←←← │
└─────────────────────────────┘
The diagram shows the disk arm moving up servicing requests, then reversing direction at the end and moving down, similar to an elevator's path.
Key Facts
SCAN Algorithm → A disk scheduling method where the arm moves in one direction servicing requests, then reverses at the disk's end.
Disk Arm Movement → The physical movement of the read/write head across disk tracks to access data.
Request Queue → The list of pending disk access requests waiting to be serviced.
Starvation → A situation where some requests never get serviced due to scheduling unfairness.
Elevator Algorithm → Another name for the SCAN algorithm, inspired by elevator movement.
Common Confusions
Believing SCAN always moves the arm to the closest request next.
Believing SCAN always moves the arm to the closest request next. SCAN moves the arm in one fixed direction servicing all requests along the way, not necessarily the closest next request.
Thinking SCAN skips requests if they are behind the current arm direction.
Thinking SCAN skips requests if they are behind the current arm direction. SCAN will service all requests but only when the arm reverses direction and passes their track.
Summary
SCAN moves the disk arm in one direction, servicing requests along the way, then reverses at the disk's end.
This method reduces waiting time and avoids unnecessary arm movement compared to simpler scheduling.
It works like an elevator, continuously sweeping back and forth to serve all requests fairly.

Practice

(1/5)
1. What is the main idea behind the SCAN (elevator) disk scheduling algorithm?
easy
A. Requests are served in the exact order they arrive without reordering.
B. The disk arm moves in one direction, servicing requests until it reaches the end, then reverses direction.
C. The disk arm jumps directly to the closest request regardless of direction.
D. The disk arm moves randomly to service requests.

Solution

  1. Step 1: Understand SCAN movement

    SCAN moves the disk arm in one direction, serving all requests along the way until it reaches the last track in that direction.
  2. Step 2: Direction reversal

    After reaching the end, the arm reverses direction and serves requests on the way back, similar to an elevator moving up and down.
  3. Final Answer:

    The disk arm moves in one direction, servicing requests until it reaches the end, then reverses direction. -> Option B
  4. Quick Check:

    SCAN = moves one way then reverses [OK]
Hint: Think of SCAN like an elevator moving up and down [OK]
Common Mistakes:
  • Confusing SCAN with FCFS (first-come, first-served)
  • Thinking SCAN jumps directly to closest request
  • Assuming SCAN moves randomly
2. Which of the following correctly describes the order in which SCAN services disk requests?
easy
A. It services the closest request next, regardless of direction.
B. It services requests in the order they arrive without reordering.
C. It services requests by moving the arm in one direction, then reverses at the end.
D. It randomly selects requests to service next.

Solution

  1. Step 1: Identify SCAN's servicing order

    SCAN moves the disk arm in one direction, servicing all requests in that path.
  2. Step 2: Direction reversal at end

    When the arm reaches the last request or the disk end, it reverses direction and services requests on the return path.
  3. Final Answer:

    It services requests by moving the arm in one direction, then reverses at the end. -> Option C
  4. Quick Check:

    SCAN = one direction then reverse [OK]
Hint: Remember SCAN moves like an elevator, up then down [OK]
Common Mistakes:
  • Confusing SCAN with SSTF (closest request first)
  • Assuming SCAN ignores direction
  • Thinking SCAN services requests randomly
3. Given the disk requests at tracks [10, 22, 20, 2, 40, 6] and the disk arm currently at track 15 moving towards higher tracks, which request will SCAN service first?
medium
A. Track 20
B. Track 10
C. Track 6
D. Track 2

Solution

  1. Step 1: Identify current arm position and direction

    The arm is at track 15 and moving towards higher tracks (upwards).
  2. Step 2: Find the closest request in the moving direction

    Requests above 15 are 20, 22, and 40. The closest is track 20.
  3. Final Answer:

    Track 20 -> Option A
  4. Quick Check:

    SCAN services requests ahead in current direction first [OK]
Hint: Pick closest request ahead in current direction [OK]
Common Mistakes:
  • Choosing requests behind current arm position
  • Ignoring arm's moving direction
  • Picking the closest request overall instead of in direction
4. A disk arm is at track 50 moving towards track 0. The requests are at tracks [10, 20, 30, 40, 60]. Which request will SCAN service next? Identify the error in this reasoning: "Since the arm is moving towards 0, it will service track 60 next because it is the closest."
medium
A. The arm will service track 60 next; no error in reasoning.
B. The arm will service track 20 next; the error is ignoring request order.
C. The arm will service track 10 next; the error is assuming direction matters.
D. The arm will service track 40 next; the error is ignoring the arm's direction.

Solution

  1. Step 1: Understand arm direction and position

    The arm is at track 50 moving towards 0 (downwards).
  2. Step 2: Identify requests in arm's direction

    Requests below 50 are 10, 20, 30, 40; above 50 is 60.
  3. Step 3: Find next request in direction

    The closest request in the moving direction is track 40, not 60.
  4. Final Answer:

    The arm will service track 40 next; the error is ignoring the arm's direction. -> Option D
  5. Quick Check:

    SCAN respects arm direction when choosing requests [OK]
Hint: Always consider arm direction before picking requests [OK]
Common Mistakes:
  • Ignoring arm direction and picking closest request overall
  • Assuming SCAN jumps to farthest request
  • Confusing SCAN with SSTF
5. A disk arm is at track 50 on a disk with tracks numbered 0 to 199. Requests are at tracks [95, 180, 34, 119, 11, 123, 62, 64]. The arm is moving towards higher tracks. Using the SCAN algorithm, what is the order in which the requests will be serviced?
hard
A. [62, 64, 95, 119, 123, 180, 199, 34, 11]
B. [62, 64, 95, 119, 123, 180, 34, 11]
C. [95, 119, 123, 180, 199, 64, 62, 34, 11]
D. [95, 119, 123, 180, 64, 62, 34, 11]

Solution

  1. Step 1: Identify requests above current arm position

    Arm at 50 moving up; requests above 50 are 62, 64, 95, 119, 123, 180.
  2. Step 2: Service requests upwards in order

    Requests are serviced in ascending order: 62, 64, 95, 119, 123, 180.
  3. Step 3: Reach end of disk and reverse

    SCAN continues to the last track (199) before reversing direction.
  4. Step 4: Service remaining requests on return

    On return, service requests below 50 in descending order: 34, then 11.
  5. Final Answer:

    [62, 64, 95, 119, 123, 180, 199, 34, 11] -> Option A
  6. Quick Check:

    SCAN = up servicing, end, then down servicing [OK]
Hint: Service all requests up, go to end, then service down [OK]
Common Mistakes:
  • Skipping the last track before reversing
  • Not servicing requests in sorted order
  • Ignoring requests on return path
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard