• Home
  • About
    • Ugur photo

      Ugur

      Blog

    • Learn More
    • Twitter
    • LinkedIn
    • Instagram
    • Github
  • Posts
    • All Posts
    • All Tags

Queue

06 Feb 2021

Reading time ~1 minute

QUEUE

Like Stack, Queue is a linear structure which follows a particular order in which th eoperations are performed. The order is First In First Out (FIFO). A good example of queue is any queue consumers for a resource where the consumer that came first is served first. The difference between stacks and queues in removing. In a stack we remove the item the most recently added; in a queue, we remove the item the least recently added.

Mainly the following four basic operations are performed in the queue:

  • ENQUEUE

    Adds an item in the queue. If the queue is full, then it is said to be an Overflow condition.

  • DEQUEUE

    Removes an item from the queue. The items are popped in the same order in which they are pushed. If the queue is empty, then it is said to be an underflow condition.

  • FRONT

    Get the front item from queue.

  • REAR

    Get the last item from queue.

Applications of Queue

Queue is used when things do not have to be processed immediately, but have to be processed in First In First Out order like Breadth First Search. This property of Queue makes it also useful in following kind of scenarios.

Time complexities of operations on Queue:

Enque(Insertion),Deque(Deletion),Front(GetFront) and Rear(GetRear) all take O(1) time.

PROS

Easy to implement.

CONS

  • Static Data Structure, fixed size.
  • If the queue has a large number of enqueue and dequeue operations, at some point may not we able to insert elements in the queue even if the queue is empty.

REFERENCES

https://www.geeksforgeeks.org/queue-set-1introduction-and-array-implementation/



data structurequeuealgorithms Share Tweet +1