

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Operation Description Time Complexity
enqueue(item) Adds a new element to the^ Rear^ of the queue.^ O(1)
dequeue() Removes and returns the element from the Front. O(1)
peek() / front() Returns the front element without removing it. O(1)
isEmpty() Checks if the queue contains any elements. O(1)
Circular Queue: Overcomes the limitation of un-reusable empty spaces in array-based queues by linking the last position back to the first position, forming a continuous circle. Priority Queue: Elements are enqueued with a "priority" value. Dequeuing removes the element with the highest priority first, rather than strictly following FIFO. Often implemented using Heaps. Deque (Double-Ended Queue): Allows insertion and deletion from both the front and the rear, providing flexibility between a stack and a queue.
4. Implementation Strategies
Array Implementation
Pros: Easy to implement, fast, and cache- friendly. Cons: Fixed size limit. Standard arrays suffer from a "false full" condition where space freed by dequeue cannot be reused (solved by Circular Queues).
Linked List Implementation
Pros: Dynamic size, no wasted memory, can grow infinitely (until RAM runs out). Cons: Requires extra memory for storing node pointers, scattered memory allocations.
5. Key Applications in Computer Science
CPU & Disk Scheduling: Operating systems use queues to manage processes waiting for CPU time or I/O operations (e.g., Round Robin scheduling). Graph Algorithms: Breadth-First Search (BFS) relies entirely on a queue to explore nodes level-by- level in graphs and trees. Asynchronous Data Transfer: Buffers (like IO Buffers, pipes, file IO) use queues to manage data transferred asynchronously between two processes. Print Spooling: Documents sent to a shared network printer are queued and printed in the exact order they were received.