Collection of flash cards about queues
Creator
HlC44W6cOAT4s90O5qHtwtzi6lm2
The number of elements currently stored in the Vector.
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.
To view the element at the front of the queue without removing it.
Using an array (circular array) or a linked list.
Adding an element to the end of the Vector.
The rear (or back) end.
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.
A heap (min-heap or max-heap).
The total number of elements the Vector can hold before it needs to reallocate memory.
Removing an element from the front of the queue.
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'.
O(1) (amortized constant time), as reallocations happen infrequently.
The front end.
O(n) (linear time), because subsequent elements need to be shifted.
Adding an element to the rear of the queue.
A queue-like data structure that allows elements to be added or removed from both the front and the rear.
Dynamic size, allowing it to grow or shrink as needed without explicit resizing.
The number of elements currently in the queue.
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 special type of queue where each element has a priority, and elements with higher priority are dequeued before elements with lower priority.
Enqueue: O(1). Dequeue: O(1).
Arrays and linked lists.
Determines the number of elements in the queue.
The process of removing an element from the front of the queue.
A deque where deletion is allowed at only one end.
Print queues, call centers, and task scheduling.
Enqueue: O(1). Dequeue: O(1).
A double-ended queue, where elements can be added or removed from both ends.
A deque where insertion is allowed at only one end.
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.
A linear data structure that follows the First-In-First-Out (FIFO) principle.
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.
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.
Check if the rear pointer has reached the last index of the array.
Elements are stored in contiguous memory locations.
Enqueue: Adds an element to the rear of the queue. Dequeue: Removes an element from the front of the queue.
Memory allocation is static and fixed in size.
Verifies whether the queue is empty.
Input-restricted deque and Output-restricted deque.
enqueue(), dequeue(), peek()
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.
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.
A queue that connects the front and rear ends, forming a circle. This helps in better memory utilization.
Memory is allocated dynamically.
A queue where elements are assigned priorities and processed based on that priority.
myQueue.push(10);
myQueue.back();
Elements with higher priority are processed before elements with lower priority.
O(1)
rear()
When you need to process elements in the order they arrive.
Heaps
myQueue.empty();
Breadth-First Search (BFS)
Handling print jobs, managing network traffic, and CPU task scheduling.
First-In-First-Out (FIFO)
enqueue()
Simple implementation and efficient access.
Elements can only be inserted or deleted at the ends (front and rear).
dequeue()
O(1)
myQueue.pop();
#include <queue>
Linked List and Array
Used in task scheduling and event simulation systems.
Useful when order of processing is important.
std::priority_queue<int> myPQueue;
O(1)
front()
A data structure that follows the First-In-First-Out (FIFO) principle.
myQueue.front();
myQueue.size();
std::queue<int> myQueue;
Dynamic size and easier insertion/deletion.