Top Ad unit 728 × 90

what is queue ? |easy explain

What is Queue?: 

  1. It is a non primitive linear data structure it is a homogeneous and ordered collection of element in which new element are inserted at  'Rear End ' and the the existing element are deleted from 'Front End'. 
  2. Queue basically works on FiFo (first in first out).
  3. Queue uses two operation enqueue (for inserted ) and Dequeue (for deletion) of the new and existing elements.

Operations of Queue:

1). Insertion :  The insertion of element enqueue are done by Rear End. Before the insertion of the element it is checked as whether the queue is full or not.

2). Deletion :-   The Deletion of element enqueue are done by 'front end' before performing this operation it will checked the queue is empty or not.


Type of Queue:

There are basically three type of queue.

1). Circular Queue
2). Priority Queue
3). Double Ended Queue

1).Circular Queue:

A circular queue is one in which a new element inserted at very first location on the queue if the last location of the queue is full.    

In other words if we have a queue of small 'n' element then after inserting an element at the last location i.e 'n-1' place of the queue then the next element will be inserted at the very first location of the queue. We can say that circular queue is one in which the first element comes just after the last element, and it can be viewed as a mesh or look of wires in which two end of the wires of connection to gather. 

2). Priority Queue :

To represent a priority queue a 2D array is required first array will keep recall of data and information and second array keep the contain the priority of precedence  or in which each element is associated with priority value.
  1. In priority queue the data / information are processed asper there priority.
  2. The lower priority information will be processed first then the higher priority. 

3). Double Ended Queue:  

Double Ended Queue is the type of queue or homogeneous list of element in which insertion or deletion are perform from both the ends i.e front end and rear end. In double ended queue we can insert element from rear as well as from front end similar we can delete the element from rear as well as front end also.

Structure of Double ended queue:



Represent of Queue:

1). Static  Implementation of queue :-  

In an array representation front will be an index variable which hold the index of the element which will be deleted from the Queue.

[initial value of front =-1]
when queue is empty rear is also an index variable which will hold the index of last element in Queue.
[ initial value of rear = -1 ]

For Array Representation:-  [ total number of element present in the queue = front - rear+1 ] 


2). Dynamic Implementation of Queue :

The Queue using link list is very much similar to link list.  The only difference between in queue left most  node is called front node and right most is called rear node.  We can not remove any orbitary node from queue.

Advantage:

The  main advantage of link list representation is that we need not have two warried about size of the queue the initial value of front and rear will be ' NULL'. 

Operation of Dynamic Implementation of Queue:

Insertion of a node:   Insertion of new element will be perform rear and its follow following step.
  1. checking the queue overflow
  2. If queue is empty then set as [front = -1, Rear = -1 ].
  3. increment the rear end and insert the node / item in the rear end.
Then [ Rear = Rear +1 ] & [front = Front+1 ],
what is queue ? |easy explain Reviewed by For Learnig on May 26, 2023 Rating: 5

No comments:

If you have any doubts, please tell me know

Contact Form

Name

Email *

Message *

Powered by Blogger.