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