1.
Inorder Traversal of Binary Tree
Performs left-root-right traversal using recursion.
Code:
void inorder(Node node) {
if (node == null) return;
inorder([Link]);
[Link]([Link] + " ");
inorder([Link]);
}
2. Basic Binary Tree (Insert, Delete, Traverse)
Implements insert, delete and traversal operations with recursion and iterative logic.
3. Array Operations
Max/Min: loop through array keeping track of min and max.
Reverse: swap first and last elements iteratively.
Sort 0s,1s,2s: Dutch National Flag algorithm using three pointers (low, mid, high).
4. Stack using Two Queues
Implements LIFO using FIFO queues. Push in one queue, and transfer elements for pop operation.
5. Evaluate Postfix Expression
Uses a stack to evaluate postfix: scan token by token, push operands, pop two for operator.
6. Balanced Parentheses
Stack-based algorithm: push '(' and pop when ')' appears. If stack empty at end → balanced.
7. Kth Smallest/Largest Element
Use sorting or a min/max heap for efficiency. Time O(n log k).
8. Linked List Operations
Reverse: iterate, adjust pointers.
Remove Nth: count nodes or use two-pointer approach.
Merge Sorted: compare heads and merge into new list.
9. Detect Cycle (Floyd’s Algorithm)
Use slow and fast pointers. If they meet → cycle exists.
10. Find Middle of Linked List
Use two pointers: move slow by 1 and fast by 2. When fast hits end → slow is middle.
11. Doubly Linked List
Supports insertion, deletion, traversal both forward and backward using prev/next pointers.
12. Stack using Linked List
Implements stack with linked list nodes (push, pop, peek, isEmpty).
13. Hashing
Improves search efficiency to O(1) using hash functions to map keys to indices.
14. Stack vs Queue Usage
Stack: backtracking, expression evaluation.
Queue: scheduling, BFS traversal.
Use whichever fits LIFO/FIFO logic.
15. Priority Queue using Heap
Implements insert, delete, update with O(log n) using binary heap (min-heap or max-heap).
16. Heap vs Sorted Array Comparison
Heap: faster insertion (O(log n)), slower traversal.
Sorted Array: faster lookup (O(1) for smallest/largest).
17. Heap Performance Analysis
Under heavy loads, heap operations remain logarithmic — stable performance even for large
datasets.
18. Priority Queues in Real-time Systems
Used in OS scheduling, network packet processing — ensures high-priority tasks handled first.
19. Level Order Traversal (Binary Tree)
Use queue for BFS — print each level by dequeuing nodes level by level.
20. Queue using Stacks
Two stacks used — one for enqueue (stack1), one for dequeue (stack2). Transfer elements when
needed.
Amortized O(1) performance.