Kodekraftt
/Blog
/Look Elevator Algorithm In Java Definition Working And Program
Join Early AccessContact UsPrivacy Policy
Java BasicsOOPsDSA with JavaQuizzesInterview Preparation

© 2026 KodeKraftt. All rights reserved.

Build smarter. Learn more. Innovate better.

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:

  • The elevator moves in one direction (UP or DOWN).
  • It serves all floor requests in that direction.
  • When there are no more requests ahead, it reverses direction.
  • It does not go to the building’s extreme floors unless requested.

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

Why LOOK Is Better Than SCAN

  • Reduces unnecessary elevator movement
  • Saves time and energy
  • More realistic for modern buildings
  • Improves average response time

Example Scenario

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

How LOOK Works

  • Move UP → serve 7
  • Move UP → serve 9 (last request in UP direction)
  • Reverse direction
  • Move DOWN → serve 4 → 3 → 1

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)

  • SCAN: Goes to extreme floors even if not requested
  • LOOK: Reverses at last requested floor

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.

You might also like

Check if Two Strings Are Rotations of Each Other in Java — Definition, Examples and Program

Learn how to check whether two strings are rotations of each other in Java using logical string comparison without using complex libraries.

Find the Shortest Word in a Sentence in Java — Definition, Examples and Program

Learn how to find the shortest word in a sentence in Java using a simple character-by-character approach without using split() or advanced string methods.

Abundant Number in Java — Definition, Examples and Program

Learn what an abundant number is in Java with definition, examples, and a clean program to check whether a number is abundant or not.

Concatenate Two Strings in Java Without Using + Operator — Examples and Program

Learn how to concatenate two strings in Java without using the + operator. This blog explains the logic with examples, a Java program, and practice challenges.

Check if a String is Empty or Null in Java — Definition, Examples and Program

Learn how to check whether a string is null or empty in Java. This blog explains the difference, common mistakes, examples, and a safe Java program with practice challenges.

Convert String to Uppercase in Java Without Using String Library

Learn how to convert a string to uppercase in Java without using built-in String methods. This blog explains the ASCII-based logic with examples, a Java program, and practice challenges.