Skip to content

Commit 7d2e8bc

Browse files
committed
added stacks and queues in data structures
1 parent b0dfcd3 commit 7d2e8bc

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## 2. Queues
2+
A **Queue** is a linear data structure that follows the First-In-First-Out (FIFO) principle. The first element added is the first to be removed.
3+
4+
### Key Characteristics
5+
- Operates in a **FIFO** order.
6+
- Can be implemented using arrays, linked lists, or circular buffers.
7+
8+
### Types of Queues
9+
- **Simple Queue**: Basic FIFO queue.
10+
- **Circular Queue**: The last position is connected back to the first.
11+
- **Priority Queue**: Elements are dequeued based on priority.
12+
- **Deque**: Double-ended queue, allowing insertion and deletion at both ends.
13+
14+
### Common Operations
15+
- **Enqueue(x)**: Adds element `x` at the end of the queue.
16+
- Complexity: \(O(1)\)
17+
- **Dequeue()**: Removes and returns the front element.
18+
- Complexity: \(O(1)\)
19+
- **Front()**: Returns the front element without removing it.
20+
- Complexity: \(O(1)\)
21+
- **isEmpty()**: Checks if the queue is empty.
22+
- Complexity: \(O(1)\)
23+
24+
### Applications
25+
- **CPU Scheduling**: Round-robin scheduling.
26+
- **Breadth-First Search (BFS)**: Used in graph traversal.
27+
- **IO Buffers**: Handling asynchronous data.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## 1. Stacks
2+
A **Stack** is a linear data structure that follows the Last-In-First-Out (LIFO) principle. This means the last element added is the first one to be removed.
3+
4+
### Key Characteristics
5+
- Operates in a **LIFO** order.
6+
- Can be implemented using arrays or linked lists.
7+
8+
### Common Operations
9+
- **Push(x)**: Adds element `x` to the top of the stack.
10+
- Complexity: \(O(1)\)
11+
- **Pop()**: Removes and returns the top element.
12+
- Complexity: \(O(1)\)
13+
- **Peek/Top()**: Returns the top element without removing it.
14+
- Complexity: \(O(1)\)
15+
- **isEmpty()**: Checks if the stack is empty.
16+
- Complexity: \(O(1)\)
17+
18+
### Applications
19+
- **Expression Parsing**: Evaluating postfix and infix expressions.
20+
- **Function Calls**: Recursive calls use a call stack.
21+
- **Backtracking**: Helps in scenarios where previous states are revisited, like maze solving or browser history.

0 commit comments

Comments
 (0)