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

Define Evaluation of Postfix expression. Explain algorithm and example for it ? 


View

Define stacks . Explain implementation of stacks ? 


View

Define Tower of Hanoi. Explain Problem statement for Tower of Hanoi ? 


View

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


View

Define Queue. Explain Basic features of Queue ? 


View

Explain stacks using dynamic arrays ? 


View

Explain Factorial of a number ? 


View