LOOK Elevator Algorithm in Java — Definition, Working and Program

Understand how the LOOK Elevator Algorithm optimizes elevator movement by serving only requested floors. Learn its working with examples and a Java program simulating a single elevator.

LOOK Elevator Algorithm in Java — Definition, Working and Program

The LOOK Elevator Algorithm is an optimized scheduling algorithm used in elevator systems and operating systems (disk scheduling). It improves upon the SCAN algorithm by eliminating unnecessary movement.

Instead of moving all the way to the top or bottom floor, the elevator looks ahead and reverses direction as soon as the last requested floor is served.

What Is the LOOK Elevator Algorithm?

The LOOK algorithm works as follows:

This makes LOOK more efficient than SCAN in real-life scenarios.

Why LOOK Is Better Than SCAN

Example Scenario

Current Floor: 5
Direction: UP
Requested Floors: 1, 3, 4, 7, 9

How LOOK Works

Service Order: 7 → 9 → 4 → 3 → 1

Java Program — LOOK Elevator Algorithm (Single Elevator)


import java.util.*;

public class LookElevator {

    public static void main(String[] args) {

        int currentFloor = 5;
        String direction = "UP";

        List requests = Arrays.asList(1, 3, 4, 7, 9);
        List up = new ArrayList<>();
        List down = new ArrayList<>();

        for (int floor : requests) {
            if (floor > currentFloor) {
                up.add(floor);
            } else if (floor < currentFloor) {
                down.add(floor);
            }
        }

        Collections.sort(up);
        Collections.sort(down, Collections.reverseOrder());

        System.out.println("LOOK Elevator Service Order:");

        if (direction.equals("UP")) {
            for (int floor : up) {
                System.out.println("Serving floor " + floor);
            }
            for (int floor : down) {
                System.out.println("Serving floor " + floor);
            }
        } else {
            for (int floor : down) {
                System.out.println("Serving floor " + floor);
            }
            for (int floor : up) {
                System.out.println("Serving floor " + floor);
            }
        }
    }
}

Sample Output


LOOK Elevator Service Order:
Serving floor 7
Serving floor 9
Serving floor 4
Serving floor 3
Serving floor 1

SCAN vs LOOK (Quick Comparison)

LOOK minimizes wasted movement and is closer to how real elevators behave.

Practice Challenges

  1. Modify the program to accept user input for floors and direction.
  2. Calculate total elevator movement (distance traveled).
  3. Extend the program to handle multiple elevators.

The LOOK Elevator Algorithm demonstrates how intelligent scheduling can significantly improve real-world systems like elevators and disk controllers.