Collection of flash cards about queues
Creator
username could not be found
The number of elements currently in the queue.
O(1) (amortized constant time), as reallocations happen infrequently.
Dynamic size, allowing it to grow or shrink as needed without explicit resizing.
A queue-like data structure that allows elements to be added or removed from both the front and the rear.
Adding an element to the rear of the queue.
Using an array (circular array) or a linked list.
A special type of queue where each element has a priority, and elements with higher priority are dequeued before elements with lower priority.
A linear data structure that follows the First-In, First-Out (FIFO) principle.
A dynamic array, which is a contiguous block of memory that can automatically grow or shrink in size.
A heap (min-heap or max-heap).
Adding an element to the end of the Vector.
Removing an element from the front of the queue.
The total number of elements the Vector can hold before it needs to reallocate memory.
The rear (or back) end.
To view the element at the front of the queue without removing it.
First-In, First-Out.
O(1) (constant time), because elements are stored contiguously.
A static array has a fixed size defined at compile time, while a Vector can change its size during runtime.
The number of elements currently stored in the Vector.
The front end.
O(n) (linear time), because subsequent elements need to be shifted.
Fixed size or the need for re-sizing (if not circular), and potential for wasted space or 'wraparound' complexity.
If the queue contains no elements.
Using an operation like 'pop_back'.
It typically allocates a larger block of memory (e.g., doubles its current capacity), copies all existing elements to the new block, and then deallocates the old block.
Enqueue: O(1). Dequeue: O(1).
The process of adding an element to the rear of the queue.
A situation when the queue is completely full and no more elements can be added.
A linear data structure that follows the First-In-First-Out (FIFO) principle.
Useful when you need to maintain the order of elements and process them in the order they arrived.
Memory allocation is static and fixed in size.
Check if the front and rear pointers are pointing to the same location or if front is NULL.
Enqueue: Adds an element to the rear of the queue. Dequeue: Removes an element from the front of the queue.
Check if the rear pointer has reached the last index of the array.
Memory is allocated dynamically.
A queue that connects the front and rear ends, forming a circle. This helps in better memory utilization.
Returns the element at the front of the queue without removing it.
Verifies whether the queue is empty.
front: Points to the front element in the queue. rear: Points to the rear element in the queue.
enqueue(), dequeue(), peek()
First-In-First-Out. The element that is added first is the element that is removed first.
A queue where the elements have priorities assigned to them. Elements with higher priority are processed before elements with lower priority.
Simple to implement, but can be inefficient if the queue becomes full.
Print queues, call centers, and task scheduling.
Arrays and linked lists.
Determines the number of elements in the queue.
Input-restricted deque and Output-restricted deque.
A deque where deletion is allowed at only one end.
A situation when the queue is completely empty and no more elements can be removed.
More complex to implement, but more efficient in terms of memory usage.
A double-ended queue, where elements can be added or removed from both ends.
Enqueue: O(1). Dequeue: O(1).
A deque where insertion is allowed at only one end.
The process of removing an element from the front of the queue.
Elements are stored in contiguous memory locations.
dequeue()
Breadth-First Search (BFS)
myQueue.back();
A queue where elements are assigned priorities and processed based on that priority.
When you need to process elements in the order they arrive.
enqueue()
Elements with higher priority are processed before elements with lower priority.
rear()
O(1)
myQueue.front();
myQueue.push(10);
myQueue.size();
front()
O(1)
#include <queue>
Dynamic size and easier insertion/deletion.
std::queue<int> myQueue;
std::priority_queue<int> myPQueue;
myQueue.pop();
Heaps
Simple implementation and efficient access.
Handling print jobs, managing network traffic, and CPU task scheduling.
myQueue.empty();
First-In-First-Out (FIFO)
Used in task scheduling and event simulation systems.
Linked List and Array
Elements can only be inserted or deleted at the ends (front and rear).
Useful when order of processing is important.
A data structure that follows the First-In-First-Out (FIFO) principle.
O(1)