Algorithms

23 — Algorithms

Previous: 22 Data Structures · Next: 24 LeetCode

▶️ pkg4algorithms/algorithms1SortingAlgorithms.javaalgorithms7DivideAndConquer.java


Package map

# Topic Algorithms File
1 Sorting Bubble, Selection, Insertion, Merge, Quick, Heap, Counting algorithms1SortingAlgorithms
2 Searching Linear, Binary, first/last occurrence algorithms2SearchingAlgorithms
3 Greedy Activity selection, interval scheduling algorithms3GreedyAlgorithms
4 Dynamic Programming Fibonacci, knapsack, LCS algorithms4DynamicProgramming
5 Backtracking Subsets, permutations, N-Queens algorithms5Backtracking
6 Graph Dijkstra, Topological sort, cycle detect algorithms6GraphAlgorithms
7 Divide & Conquer Merge sort, quickselect, binary search algorithms7DivideAndConquer

Big-O cheat sheet

Notation Name Example
O(1) Constant HashMap get
O(log n) Logarithmic Binary search
O(n) Linear Scan array
O(n log n) Linearithmic Merge sort
O(n²) Quadratic Nested loops
O(2ⁿ) Exponential Naive subsets

Always state time and space complexity in interviews.


Pattern recognition

Problem signal Try
Sorted array + find Binary search
All subsets/permutations Backtracking
Optimal substructure Dynamic programming
Shortest path (non-negative) Dijkstra
Dependencies / prerequisites Topological sort
Top K elements Heap
Subarray sum / window Sliding window

Next → 24 LeetCode Related → 17 Print Puzzles