180 likes | 340 Views
Abstract Data Types (ADT) Queues. Authors: Robin Gajadhar Anthony George Christian Loregnard. Objectives. Queue/ Linear queue Enqueue Dequeue Empty Circular queue Linear queue Priority queue Double ended queue.
E N D
Abstract Data Types (ADT) Queues Authors: Robin Gajadhar Anthony George Christian Loregnard
Objectives • Queue/ Linear queue • Enqueue • Dequeue • Empty • Circular queue • Linear queue • Priority queue • Double ended queue
What are queues ( pronounced “Q”)? • A linear list where data can be entered from the end (rear) and deleted at the beginning (front) • Eg. A line of celebrities try to get into a club, they reach the beginning (front) of the line and enter and more celebrities join the line from the back (rear).
Applications related to Computer Science • Threads • Job scheduling (e.g. Round-Robin algorithm for CPU allocation)
Applications of Queues • Direct applications • Waiting lists • Access to shared resources (e.g., printer) • Multiprogramming • Indirect applications • Auxiliary data structure for algorithms • Component of other data structures
Circular Queue • Circular Queue is like a linear queue but in addition, it's last element have a pointer to it's first element. Also called ring buffer.
Priority Queue • Think of a priority queue as a kind of bag that holds priorities. You can put one in, and you can take out the current highest priority.
Priority Queue • A priority queue is different from a "normal" queue, because instead of being a "first-in-first-out" data structure, values come out in order by priority. Each time the printer is free, the job with the highest priority would be removed from the print queue, and printed.
Example • Think of celebrities trying to enter a club, popular celebrities go first, less popular celebrities enter second, bad celebrities enter third and regular people will enter last, they are of lower priority. The popular celebrities would leave the queue first.
Double ended queue • A queue that allows items to be added or removed from either the front or the back of the queue. Often written as Deque and pronounced like "deck" to avoid confusing with DequeueOperation??. A DoubleEndedQueue is usually implemented using DoubleLinkedList.
Example • A line of domino blocks. You can either add or remove a block from the front or back.
Queue operation • Creates an empty queue • Eg. Setting crowd barriers at a bank before the crowd arrives
Enqueue operation • Inserts an item at the rear of the queue (eg.More female celebrities join at the back of the line) • Justin Beiber • Beyonce • NickiMinaj • Kim Kardashian • Eve • Alicia Keys
Dequeue operation • Remove a job at the start(front) of the queue. Justin Beiber is removed from the queue. Justin Beiber Beyonce NickiMinaj Kim Kardashian Eve Alicia Keys
Empty operation • Check to see whether or not the queue is empty. Returns true if it is and false if not.
End of Presentation • An easy way to remember the operations is • Queens Eat Dry Eggs • Queue EnqueueDeque Empty