Stack Fundamentals
Definition: A stack follows the Last In, First Out (LIFO) principle. Analogy: Like a stack of plates; the last plate added is the first removed. Stack Operations
Push: Add an element to the top. Pop: Remove the top element. Peek: View the top element without removing it. isEmpty(): Check if the stack is empty. Size: Number of elements in the stack. Clear: Remove all elements. Stack Properties
Operations are only at the top. Sequential access required for specific elements. Sorting within a stack is not possible. Time Complexity
Queue Fundamentals
Definition: A queue follows the First In, First Out (FIFO) principle. Analogy: Like a line at a grocery store; the first person in line is the first served. Queue Operations
Enqueue: Add an element to the rear. Dequeue: Remove an element from the front. Peek: View the front element without removing it. isEmpty(): Check if the queue is empty. Size: Number of elements in the queue. Clear: Remove all elements. Time Complexity
Enqueue, Dequeue, Peek: O(1) For more detailed information on Stack & Queue, refer to the Notion link: Stack & Queue