A Way For Learning

Types of Queues

No comments

Different types of queues:
A queue is a type of abstract data type that can be implemented as a linear or circular list.
 A queue has a front and a rear.


Queue can be of four types:

1. Simple Queue

2. Circular Queue

3. Priority Queue

4. Dequeue (Double Ended queue)


1. Simple Queue: In Simple queue Insertion occurs at the rear of the list, and deletion occurs at the front of the list.





2. Circular Queue : A circular queue is a queue in which all nodes are treated as circular such that the first node follows the last node.






3. Priority Queue: A priority queue is a queue that contains items that have some preset priority. When an element has to be removed from a priority queue, the item with the highest priority is removed first





4. Dequeue (Double Ended queue): In dequeue(double ended queue) Insertion and Deletion occur at both the ends i.e. front and rear of the queue.




Linear queues require much less programming logic as (you're right) the limitation of queue-size is really about all you really need to know. However, circular queues provide much more flexibility than a linear queue. Here's a couple of examples of flexibility available with a circular queue that aren't easily implementable with a linear queue:

1. Memory allocations...(assuming no pointers)
A. (Linear Queue):
i. Allocate new, larger block of memory reflective of the entire (existing) queue and the queue-size additions.
ii. Copy the initial block of memory (i.e. the entire existing queue) to the newly allocated block of memory.
iii Reset the "high-water" variable indicating the new size of the queue.

B. (Circular Queue):
i. Allocate ONLY the new object or structure-type required.
ii. Insert the new allocation ANYWHERE you want in the queue.

Typically circular queues implement a linked-list design to manage the queue. This allows you to "insert" an artifact (e.g. object or data-structure) anywhere you like into a queue. This is very difficult within a linear queue (depending on the reference implementation). Additionally memory management becomes much easier to control and predominantly more efficient implementing a circular queue.

2. Queue Referencing...
A. (Linear Queue):
i. Reference the queue by indicies (e.g. myQueue[2], myQueue[nCurrentObject], myNumberQueue[12] = 10) but here's the double-edged blade (myFocalObject = myQueue[12]).

B. (Circular Queue):
i. Reference the queue by function (e.g. GetNext(..), GetPrev(..)) or by primary data artifact (e.g. GetByName(..), GetByID(..)) to retrieve specific artifact within the queue.

The principle advantages in using a circular queue here is no explicit reference to queue indices and the ability to search by queue element data in a way that obfuscates the queue itself. This would be very valuable if your software will be enhanced in the future or part of a larger software design.

IN CONCLUSION...

If ease-of-implementation and limited software life is more important, then use the linear queues. They'll be easier to write, read and if the software you're designing has a limited lifetime and/or is compartmentalized into a small enough function, you probably don't want to "over-engineer" your code.


  • In case of a ordinary queue, the insertion take place from the front end and the deletion take place  from the rear end. In the case of deletion from the front end, the datas are deleted but the space of the queue is not utilized for the further storage. So this problem is solved in case of a circular queue. Even if the rear is full but there is space at the front end, then the data can be stored in the front end until the queue overflows.



  • Circular queue is a bounded queue which implements arrays.It is beter than a normal queue because in this we can effectively utilise the memory space.If we have a normal queue and have deleted some elements from there then empty space is created there and even if the queue has empty cells then also we cannot insert any new element because the insertion has to be done from one side only(i.e rear or tail) and deletion has to be done from another side(i.e front or head).But in case of circular queue the front and rear are adjacent to each other.








  • No comments :

    Post a Comment