Algorithm n Design
Algorithm n Design
3. Worst-Case Analysis
- Provides upper bounds on resource usage
- Helps in capacity planning and resource allocation
4. Standardization
- Common language for comparing algorithms
- Simplifies algorithm selection decisions
Queue:
- FIFO normal bracket (First In First Out) structure
- Elements are added at one end and removed from the other
- Like a line of people - first person in line is first to be served
(b) Operations
Stack Operations:
1. Push - Add element to top
2. Pop - Remove element from top
3. Peek/Top - View top element
4. isEmpty - Check if stack is empty
5. isFull - Check if stack is full
Queue Operations:
1. Enqueue - Add element to rear
2. Dequeue - Remove element from front
3. Front - View front element
4. Rear - View rear element
5. isEmpty/isFull - Check queue status
(c) Implementation
2. Logarithmic - O(log n)
- Execution time increases logarithmically with input size
- Example: Binary search
3. Linear - O(n)
- Execution time increases linearly with input size
- Example: Linear search
5. Quadratic - O(n²)
- Execution time increases with square of input size
- Example: Bubble sort, Selection sort
6. Cubic - O(n³)
- Execution time increases with cube of input size
- Example: Matrix multiplication (naive)
7. Exponential - O(2ⁿ)
- Execution time doubles with each additional input
- Example: Recursive Fibonacci
8. Factorial - O(n!)
- Execution time grows factorially with input size
- Example: Generating all permutations