0% found this document useful (0 votes)
16 views12 pages

QUEUES

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views12 pages

QUEUES

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

QUEUES

• Queues are an essential data structure that are found in vast


amounts of software from user mode to kernel mode applications
that are core to the system. Fundamentally they honour a first in
first out (FIFO) strategy, that is the item first put into the queue will
be the first served, the second item added to the queue will be the
second to be served and so on.
• A traditional queue only allows you to access the item at the front
of thequeue; when you add an item to the queue that item is placed
at the back ofthe queue.
 Historically queues always have the following three core methods:

 Enqueue: places an item at the back of the queue;


 Dequeue: retrieves the item at the front of the queue, and removes
it from the queue;
 Peek: 1 retrieves the item at the front of the queue without
removing it from the queue
A
standard
queue
 In this section we will discuss how you can, if required, implement an efficient
queue data structure.The main property of a queue is that we have access to
the item at the front of the queue. The queue data structure can be efficiently
implemented using a singly linked lis. A singly linked list provides O(1)
insertion and deletion run time complexities. The reason we have an O(1) run
time complexity for deletion is because we only ever remove items from the
front of queues (with the Dequeue operation).
 Since we always have a pointer to the item at the head of a singly linked list,
removal is simply a case of returning the value of the old head node, and then
modifying the head pointer to be the next node of the old head node. The run
time complexity for searching a queue remains the same as that of a singly
linked list: O(n).
Priority
Queue
 Unlike a standard queue where items are ordered in terms of who arrived
first, a priority queue determines the order of its items by using a form of
custom comparer to see which item has the highest priority. Other than the
items in a priority queue being ordered by priority it remains the same as a
normal queue: you can only access the item at the front of the queue. A
sensible implementation of a priority queue is to use a heap data structure.
 Using a heap we can look at the first item in the queue by simply returning
the item at index 0 within the heap array. A heap provides us with the
ability to construct a priority queue where the items with the highest
priority are either those with the smallest value, or those with the largest.
Double
Ended
Queue
 Unlike the queues we have talked about previously in this chapter a double
ended queue allows you to access the items at both the front, and back of
the queue. A double ended queue is commonly known as a deque which is
the name we will here on in refer to it as. A deque applies no prioritization
strategy to its items like a priority queue does, items are added in order to
either the front of back of the deque. The former properties of the deque
are denoted by the programmer utilising the data structures exposed
interface
 Deque’s provide front and back specific versions of common queue
operations, e.g. you may want to enqueue an item to the front of the queue
rather than the back in which case you would use a method with a name
along the lines of EnqueueFront. The following list identifies operations that
are commonly supported by deque’s:
• EnqueueFront • DequeueBack
• PeekFront • EnqueueBack
• DequeueFront • PeekBack

You might also like