Queue
A Queue is a linear data structure that follows the First-In-First-Out (FIFO) principle. Elements are added at the rear and removed from the front. Common operations include enqueue and dequeue.
Queue Visualization
Queue is empty
Queue (FIFO): Empty
Complexity
Time Complexity:
O(1) for enqueue/dequeueSpace Complexity:
O(n)Pseudocode
class Queue:
function enqueue(item):
queue.append(item)
function dequeue():
if queue is empty:
return error
return queue.remove_first()
function front():
return queue[0]Related Algorithms
Stack
A Stack is a linear data structure that follows the Last-In-First-Out (LIFO) principle. Elements are added and removed from the same end (top). Common operations include push, pop, and peek.
Time: O(1) for push/pop/peek | Space: O(n)
Linked List
A Linked List is a linear data structure where elements are stored in nodes, and each node points to the next node. It allows dynamic memory allocation and efficient insertion/deletion operations.
Time: O(1) for insert/delete, O(n) for search | Space: O(n)