Explain about Implementation of Queue ? 


==> Implementation of Queue--

  • Queue can be implemented using an Array, Stack or Linked List.
  • The easiest way of implementing a queue is by using an Array.
  • Initially the head(FRONT) and the tail(REAR) of the queue points at the first index of the array (starting the index of array from 0).
  • As we add elements to the queue, the rear keeps on moving ahead, always pointing to the position where the next element will be inserted, while the front remains at the first index.
  • When we remove element from Queue, we can follow two possible approaches (mentioned [A] and [B] in above diagram).
  • In [A] approach, we remove the element at front position, and then one by one move all the other elements on position forward.
  • In approach [B] we remove the element from front position and then move front to the next position.
  • In approach [A] there is an overhead of shifting the elements one position forward every time we remove the first element.
  • In approach [B] there is no such overhead, but whenever we move head one position ahead, after removal of first element, the size on Queue is reduced by one space each time.


Share to whatsapp

More Questions from Data Structures and Algorithms Module 2

Explain simple queue ? Brief disadvantages of simple queue.


View

Define Priority Queue. Explain Application and implementation of Priority Queue ? 


View

Define Recursion. Explain types and requirement of recursion ?


View

Define Circular Queue. Describe implementation of Circular Queue ? 


View

 Explain Applications of Stack ? 


View

Explain Multiple stacks ?


View

Define Tower of Hanoi . Explain algorithm for Tower of Hanoi ? 


View