Collection of flash cards about queues
Creator
username could not be found
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.
The front end.
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.
A queue-like data structure that allows elements to be added or removed from both the front and the rear.
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 linear data structure that follows the First-In, First-Out (FIFO) principle.
Removing an element from the front of the queue.
Adding an element to the end of the Vector.
A dynamic array, which is a contiguous block of memory that can automatically grow or shrink in size.
A special type of queue where each element has a priority, and elements with higher priority are dequeued before elements with lower priority.
Using an array (circular array) or a linked list.
A heap (min-heap or max-heap).
Adding an element to the rear of the queue.
First-In, First-Out.
To view the element at the front of the queue without removing it.
The rear (or back) end.
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.
O(1) (constant time), because elements are stored contiguously.
The total number of elements the Vector can hold before it needs to reallocate memory.
Using an operation like 'pop_back'.
If the queue contains no elements.
Enqueue: O(1). Dequeue: O(1).
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.
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.
The process of adding an element to the rear of the queue.
Memory allocation is static and fixed in size.
Useful when you need to maintain the order of elements and process them in the order they arrived.
Check if the front and rear pointers are pointing to the same location or if front is NULL.
enqueue(), dequeue(), peek()
Verifies whether the queue is empty.
front: Points to the front element in the queue. rear: Points to the rear element in the queue.
First-In-First-Out. The element that is added first is the element that is removed first.
Simple to implement, but can be inefficient if the queue becomes full.
A queue where the elements have priorities assigned to them. Elements with higher priority are processed before elements with lower priority.
Returns the element at the front of the queue without removing it.
Determines the number of elements in the queue.
Arrays and linked lists.
Input-restricted deque and Output-restricted deque.
A deque where deletion is allowed at only one end.
Print queues, call centers, and task scheduling.
Elements are stored in contiguous memory locations.
Enqueue: O(1). Dequeue: O(1).
A double-ended queue, where elements can be added or removed from both ends.
More complex to implement, but more efficient in terms of memory usage.
A situation when the queue is completely empty and no more elements can be removed.
A deque where insertion is allowed at only one end.
The process of removing an element from the front of the queue.
enqueue()
Breadth-First Search (BFS)
A queue where elements are assigned priorities and processed based on that priority.
myQueue.back();
When you need to process elements in the order they arrive.
myQueue.push(10);
myQueue.size();
myQueue.front();
Elements with higher priority are processed before elements with lower priority.
O(1)
rear()
std::queue<int> myQueue;
Dynamic size and easier insertion/deletion.
myQueue.pop();
std::priority_queue<int> myPQueue;
O(1)
front()
#include <queue>
Linked List and Array
Used in task scheduling and event simulation systems.
Elements can only be inserted or deleted at the ends (front and rear).
Useful when order of processing is important.
O(1)
A data structure that follows the First-In-First-Out (FIFO) principle.
dequeue()
Simple implementation and efficient access.
Handling print jobs, managing network traffic, and CPU task scheduling.
Heaps
myQueue.empty();
First-In-First-Out (FIFO)