Data Structures & Algorithms – Layman Handwritten Notes
(Interview Prep)
How to use these notes: Read like handwritten revision notes. Focus on intuition first, then patterns, then
complexity. Practice 2–3 problems per topic.
1. Big-O Notation (Time & Space Complexity)
● Big-O means: how fast time or memory grows when input size increases.
● O(1): constant (best) – example: accessing array element.
● O(log n): halves every time – example: binary search.
● O(n): grows linearly – example: loop over array.
● O(n log n): divide + work – example: merge sort.
● O(n²): nested loops – example: bubble sort.
● Interview tip: Always mention time + space complexity.
2. Arrays
● Array = boxes in continuous memory, index-based access.
● Fast access O(1), slow insert/delete in middle O(n).
● Typical problems: max/min, prefix sum, two pointers.
● Trick: If sorted → think binary search or two pointers.
3. Strings
● String = array of characters.
● Common patterns: frequency count, sliding window.
● Use hash map for anagrams, duplicates.
● Watch out for immutability in some languages.
4. Linked List
● Nodes connected by pointers (not continuous).
● Types: Singly, Doubly, Circular.
● Fast insert/delete O(1), slow access O(n).
● Classic questions: reverse list, detect loop (Floyd’s cycle).
5. Stack
● Stack = plate stack (LIFO).
● Operations: push, pop, peek – all O(1).
● Used in: recursion, undo, expression evaluation.
● Classic: valid parentheses, next greater element.
6. Queue
● Queue = line at counter (FIFO).
● Types: simple queue, circular queue, deque.
● Used in: BFS, scheduling.
● Trick: Use deque for sliding window problems.
7. Hashing (Hash Map / Hash Set)
● Key → hash function → index.
● Average O(1) insert/search/delete.
● Used for fast lookup, counting frequency.
● Collision handled by chaining or open addressing.
8. Recursion
● Function calling itself.
● Needs: base case + recursive relation.
● Uses stack memory.
● Interview rule: If loop looks hard → try recursion.
9. Sorting Algorithms
● Bubble/Selection/Insertion: O(n²) – basics.
● Merge Sort: O(n log n), stable, extra space.
● Quick Sort: Avg O(n log n), worst O(n²), in-place.
● Interview favorite: Why quick sort is fast on average.
10. Searching
● Linear Search: O(n).
● Binary Search: O(log n) – needs sorted array.
● Binary search on answer space is a common trick.
11. Trees
● Tree = hierarchical structure.
● Binary Tree, BST.
● BST rule: left < root < right.
● Traversals: inorder, preorder, postorder.
● Interview favorite: height, diameter, LCA.
12. Graphs
● Graph = nodes + edges.
● Representations: adjacency list/matrix.
● BFS → shortest path in unweighted graph.
● DFS → cycles, connected components.
13. Dynamic Programming (DP)
● DP = recursion + memory.
● Use when problems have overlapping subproblems.
● Steps: define state → transition → base case.
● Examples: Fibonacci, knapsack, LIS.
14. Greedy Algorithms
● Take best choice now, hope for best overall.
● Works when problem has greedy property.
● Examples: activity selection, coin change (some cases).
15. Interview Strategy
● First explain brute force.
● Then optimize step by step.
● Talk while solving.
● Write clean code with edge cases.
End Note: These notes are for quick handwritten-style revision. Practice coding is mandatory to crack
interviews.