Queue Visualizer

What is the isFull Operation?

The isFull operation checks whether a queue has reached its maximum capacity in fixed-size implementations. It returns true if no more elements can be added (queue is full) and false if space remains. This operation is crucial for preventing overflow in array-based queue implementations.

How Does It Work?

The isFull operation examines the queue's capacity and current state:

Example scenarios (for a queue with capacity 3):
  1. Full Queue: [10, 20, 30]
    • isFull() → returns true
  2. Non-full Queue: [10, 20]
    • isFull() → returns false

Note: Dynamic implementations (like linked lists) typically don't need this operation as they can grow indefinitely.

Implementation Details

Different approaches to check if a queue is full:
  1. Linear Array Implementation:
    • Check if rear == capacity - 1
    • Simple but wastes space when front ≠ 0
  2. Circular Array Implementation:
    • Check if (rear + 1) % capacity == front
    • More space-efficient
  3. Size Counter Approach:
    • Maintain a size variable
    • Check if size == capacity

Algorithm Steps

For circular array implementation:
  1. Calculate next rear position: (rear + 1) % capacity
  2. Compare with front position
  3. If equal, return true (queue is full)
  4. Else return false (space available)

Time Complexity

The isFull operation always runs in O(1) constant time because:
  1. It only requires simple pointer arithmetic and comparison
  2. No iteration through elements is needed
  3. Performance is independent of queue size

Practical Usage

isFull is essential in:
  1. Bounded buffer problems
  2. Producer-consumer scenarios
  3. Memory-constrained systems
  4. Before enqueue operations to prevent overflow

Special Cases

  • Dynamic Queues: Always return false (no capacity limit)
  • Empty Full Queue: Possible when capacity = 0
  • Edge Cases: When front = 0 and rear = capacity - 1

The isFull operation is critical for robust queue implementations in fixed-capacity scenarios, ensuring data integrity by preventing buffer overflow conditions in system programming and embedded applications.

Max size: 5 items
Queue is empty
FrontRear
Queue is empty!

Queue Implementation (isFull Function Only)

// Array Queue isFull in JavaScript
class ArrayQueue {
  constructor(capacity) {
    this.arr = new Array(capacity);
    this.front = -1;
    this.rear = -1;
    this.capacity = capacity;
  }

  isFull() {
    return (this.rear + 1) % this.capacity === this.front;
  }
}

Explore Other Operations