πŸ—ΊοΈ All Roadmaps β€Ί DSA Mastery

🧠 DSA Mastery Roadmap

Data Structures & Algorithms for Coding Interviews β€” Complete C++ Reference with LeetCode Problems & Chapter Deep-Dives

13Chapters
150+Problems
C++Templates
13Patterns
πŸ“Š Your Progress
0% Loading…
Ch0
Big O Notation & Recursion
Beginner No Prerequisites πŸ“„ Chapter Notes
β–Ό
0/4 solved 0%
  • Big O: drop constants (O(5n)=O(n)), drop lower-order terms (O(nΒ²+n)=O(nΒ²))
  • Complexity Hierarchy: O(1) β†’ O(log n) β†’ O(n) β†’ O(n log n) β†’ O(nΒ²) β†’ O(2ⁿ) β†’ O(n!)
  • Recursion: every recursive function needs a base case + recursive case
  • Call stack space = O(depth) β€” watch for stack overflow on deep recursion
  • Memoization = cache results to avoid recomputing subproblems
Recursion spaceO(depth) MemoizedO(n) states
// Generic recursion template
ReturnType solve(params, state) {
    if (baseCondition) return baseValue;   // 1. Base case
    return solve(smallerParams, newState); // 2. Recursive case
}
// Top-down memoization
unordered_map<int, int> memo;
int dp(int n) {
    if (n <= 1) return n;
    if (memo.count(n)) return memo[n];
    return memo[n] = dp(n-1) + dp(n-2);
}
βœ“#ProblemDifficulty
1509. Fibonacci NumberEasy
270. Climbing StairsEasy
3231. Power of TwoEasy
4206. Reverse Linked ListEasy
Ch1
Arrays & Strings
Intermediate Prereq: Ch0 πŸ“„ Chapter Notes
β–Ό
0/26 solved 0%
  • OPPOSITE ENDS: left=0, right=n-1, move inward β€” palindrome, two-sum on sorted
  • SAME DIRECTION: fast/slow pointers β€” remove duplicates, subsequence check
  • TWO ARRAYS: one pointer per array β€” merge sorted arrays, compare sequences
TimeO(n) SpaceO(1)
// Opposite ends
int left = 0, right = arr.size() - 1;
while (left < right) {
    if (condition) { left++; right--; }
    else if (tooSmall) left++;
    else right--;
}
// Fast/Slow (same direction)
int slow = 0;
for (int fast = 0; fast < arr.size(); fast++)
    if (condition(arr[fast])) arr[slow++] = arr[fast];
βœ“#ProblemDifficulty
1125. Valid PalindromeEasy
2167. Two Sum IIMedium
3344. Reverse StringEasy
4977. Squares of a Sorted ArrayEasy
5283. Move ZeroesEasy
626. Remove Duplicates from Sorted ArrayEasy
7392. Is SubsequenceEasy
815. 3SumMedium
911. Container With Most WaterMedium
1042. Trapping Rain WaterHard
  • DYNAMIC WINDOW: expand right always, shrink left while constraint violated
  • FIXED WINDOW (size k): slide β€” add arr[right], remove arr[right-k]
  • Count of valid subarrays ending at right = right - left + 1
TimeO(n) amortized SpaceO(1) or O(k)
// Dynamic window
int left = 0, curr = 0, ans = 0;
for (int right = 0; right < nums.size(); right++) {
    curr += nums[right];
    while (curr > k) curr -= nums[left++];
    ans = max(ans, right - left + 1);
}
// Fixed window (size k)
int curr = 0;
for (int i = 0; i < k; i++) curr += nums[i];
int ans = curr;
for (int i = k; i < nums.size(); i++) {
    curr += nums[i] - nums[i-k];
    ans = max(ans, curr);
}
βœ“#ProblemDifficulty
11643. Maximum Average Subarray IEasy
121004. Max Consecutive Ones IIIMedium
133. Longest Substring Without Repeating CharactersMedium
14713. Subarray Product Less Than KMedium
15209. Minimum Size Subarray SumMedium
16904. Fruit Into BasketsMedium
17239. Sliding Window MaximumHard
1876. Minimum Window SubstringHard
  • prefix[i] = prefix[i-1] + nums[i-1]. Range sum [l,r] = prefix[r+1] - prefix[l]
  • Combine with hashmap: store prefix sum frequencies for subarray count problems
  • 2D prefix sums for matrix range queries
TimeO(n) build, O(1) query SpaceO(n)
vector<int> prefix(nums.size() + 1, 0);
for (int i = 0; i < nums.size(); i++) prefix[i+1] = prefix[i] + nums[i];
// Sum nums[l..r] = prefix[r+1] - prefix[l]

// Subarray sum equals k β€” O(n)
unordered_map<int,int> freq; freq[0] = 1; // init: prefix sum 0 seen once
int curr = 0, ans = 0;
for (int x : nums) { curr += x; ans += freq[curr - k]; freq[curr]++; }
βœ“#ProblemDifficulty
191480. Running Sum of 1d ArrayEasy
201413. Minimum Value to Get Positive Step by Step SumEasy
212090. K Radius Subarray AveragesMedium
22303. Range Sum Query - ImmutableEasy
23560. Subarray Sum Equals KMedium
24525. Contiguous ArrayMedium
25238. Product of Array Except SelfMedium
26724. Find Pivot IndexEasy
Ch2
Hashing β€” HashMaps & Sets
Intermediate Prereq: Ch1 πŸ“„ Chapter Notes
β–Ό
0/13 solved 0%
  • EXISTENCE CHECK: Use unordered_set for O(1) lookup (duplicates, anagram, pangram)
  • FREQUENCY COUNT: Use unordered_map<T,int> (count chars, elements, words)
  • TWO-SUM PATTERN: Store seen values; for each x, check if (target-x) exists
  • GROUPING: Map key β†’ list of values (group anagrams by sorted string)
  • SLIDING WINDOW + HASHMAP: Track character frequencies in a window
  • PREFIX SUM + HASHMAP: Count subarrays with target sum/property
TimeO(n) average SpaceO(n)
// Frequency count
unordered_map<int,int> freq;
for (int x : arr) freq[x]++;
// Two-sum lookup
unordered_map<int,int> seen;
for (int i = 0; i < nums.size(); i++) {
    if (seen.count(target - nums[i])) return {seen[target-nums[i]], i};
    seen[nums[i]] = i;
}
// Group anagrams
unordered_map<string, vector<string>> groups;
for (string& s : strs) {
    string key = s; sort(key.begin(), key.end());
    groups[key].push_back(s);
}
βœ“#ProblemDifficulty
11832. Check if the Sentence Is PangramEasy
2268. Missing NumberEasy
31426. Counting ElementsEasy
41. Two SumEasy
5383. Ransom NoteEasy
6771. Jewels and StonesEasy
72225. Find Players With Zero or One LossesMedium
81133. Largest Unique NumberEasy
91189. Maximum Number of BalloonsEasy
1049. Group AnagramsMedium
11347. Top K Frequent ElementsMedium
12560. Subarray Sum Equals KMedium
13146. LRU CacheMedium
Ch3
Linked Lists
Intermediate Prereq: Ch2 πŸ“„ Chapter Notes
β–Ό
0/11 solved 0%
  • FAST/SLOW POINTERS (Floyd's): fast moves 2x, slow 1x β€” middle, cycle, kth from end
  • REVERSAL: Iterative with prev/curr/next. O(n) time, O(1) space
  • DUMMY NODE: Add dummy head to simplify edge cases (empty list, removing head)
  • TWO-POINTER MERGE: Merge two sorted lists by comparing heads
TimeO(n) traversal SpaceO(1) most patterns
// Fast/slow β€” find middle
ListNode *slow = head, *fast = head;
while (fast && fast->next) { slow = slow->next; fast = fast->next->next; }
// slow = middle

// Reverse iteratively
ListNode *prev = nullptr, *curr = head;
while (curr) { ListNode* nxt = curr->next; curr->next = prev; prev = curr; curr = nxt; }
// prev = new head

// Merge sorted (dummy head)
ListNode dummy(0); ListNode* tail = &dummy;
while (l1 && l2) {
    if (l1->val <= l2->val) { tail->next = l1; l1 = l1->next; }
    else { tail->next = l2; l2 = l2->next; }
    tail = tail->next;
}
tail->next = l1 ? l1 : l2;
βœ“#ProblemDifficulty
1876. Middle of the Linked ListEasy
283. Remove Duplicates from Sorted ListEasy
3206. Reverse Linked ListEasy
492. Reverse Linked List IIMedium
5141. Linked List CycleEasy
621. Merge Two Sorted ListsEasy
719. Remove Nth Node From End of ListMedium
82. Add Two NumbersMedium
9143. Reorder ListMedium
10146. LRU CacheMedium
1123. Merge K Sorted ListsHard
Ch4
Stacks & Queues
Intermediate Prereq: Ch3 πŸ“„ Chapter Notes
β–Ό
0/11 solved 0%
  • MATCHING/VALIDATION: Push open brackets, pop on close, check match
  • MONOTONIC STACK (increasing): pop smaller than current β†’ next greater element
  • MONOTONIC STACK (decreasing): pop greater than current β†’ next smaller element
  • STRING SIMULATION: Build result char-by-char on a stack
TimeO(n) SpaceO(n)
// Monotonic stack β€” Next Greater Element
vector<int> ans(nums.size(), -1);
stack<int> stk;
for (int i = 0; i < nums.size(); i++) {
    while (!stk.empty() && nums[i] > nums[stk.top()])
        { ans[stk.top()] = nums[i]; stk.pop(); }
    stk.push(i);
}
// Bracket matching
stack<char> stk;
for (char c : s) {
    if (c == '(') stk.push(c);
    else if (!stk.empty() && stk.top() == '(') stk.pop();
    else return false;
}
return stk.empty();
// Deque β€” sliding window max
deque<int> dq;
for (int i = 0; i < nums.size(); i++) {
    while (!dq.empty() && dq.front() < i-k+1) dq.pop_front();
    while (!dq.empty() && nums[dq.back()] < nums[i]) dq.pop_back();
    dq.push_back(i);
    if (i >= k-1) ans.push_back(nums[dq.front()]);
}
βœ“#ProblemDifficulty
120. Valid ParenthesesEasy
271. Simplify PathMedium
31544. Make The String GreatEasy
4496. Next Greater Element IEasy
5901. Online Stock SpanMedium
6739. Daily TemperaturesMedium
7735. Asteroid CollisionMedium
884. Largest Rectangle in HistogramHard
9346. Moving Average from Data StreamEasy
10239. Sliding Window MaximumHard
11622. Design Circular QueueMedium
Ch5
Trees & Graphs
Advanced Prereq: Ch4 πŸ“„ Chapter Notes
β–Ό
0/22 solved 0%
  • PREORDER (rootβ†’leftβ†’right): copying, serializing trees
  • INORDER (leftβ†’rootβ†’right): sorted order for BST
  • POSTORDER (leftβ†’rightβ†’root): deletion, computing subtree properties
  • GLOBAL vs LOCAL: use a global variable for answers spanning multiple nodes
TimeO(n) SpaceO(h) stack
// Recursive DFS
int dfs(TreeNode* node) {
    if (!node) return 0;
    int left = dfs(node->left), right = dfs(node->right);
    return 1 + max(left, right); // example: height
}
// BFS level-order
queue<TreeNode*> q; q.push(root);
while (!q.empty()) {
    int sz = q.size();
    for (int i = 0; i < sz; i++) {
        TreeNode* node = q.front(); q.pop();
        if (node->left)  q.push(node->left);
        if (node->right) q.push(node->right);
    }
}
// Graph BFS β€” shortest path
vector<int> dist(n, -1);
queue<int> q; q.push(start); dist[start] = 0;
while (!q.empty()) {
    int node = q.front(); q.pop();
    for (int nei : adj[node])
        if (dist[nei]==-1) { dist[nei]=dist[node]+1; q.push(nei); }
}
βœ“#ProblemDifficulty
1111. Minimum Depth of Binary TreeEasy
2104. Maximum Depth of Binary TreeEasy
3543. Diameter of Binary TreeEasy
41026. Maximum Difference Between Node and AncestorMedium
5113. Path Sum IIMedium
6236. Lowest Common Ancestor of a Binary TreeMedium
7124. Binary Tree Maximum Path SumHard
8102. Binary Tree Level Order TraversalMedium
91302. Deepest Leaves SumMedium
10103. Binary Tree Zigzag Level Order TraversalMedium
11637. Average of Levels in Binary TreeEasy
12701. Insert into a Binary Search TreeMedium
13270. Closest Binary Search Tree ValueEasy
1498. Validate Binary Search TreeMedium
15230. Kth Smallest Element in a BSTMedium
161971. Find if Path Exists in GraphEasy
17695. Max Area of IslandMedium
181926. Nearest Exit from Entrance in MazeMedium
19200. Number of IslandsMedium
20207. Course ScheduleMedium
21133. Clone GraphMedium
22127. Word LadderHard
Ch6
Heaps & Priority Queues
Intermediate Prereq: Ch5 πŸ“„ Chapter Notes
β–Ό
0/8 solved 0%
  • TOP K: Min-heap of size k β€” push each element; if size > k, pop. Heap = top k largest
  • K-WAY MERGE: Push (value, listIndex, elemIndex) into heap; always pop smallest
  • RUNNING MEDIAN: Max-heap for lower half + min-heap for upper half
  • Trigger: 'Smallest/Largest K elements' β†’ heap. C++ default is max-heap; use greater<int> for min
Push/PopO(log n) PeekO(1)
// Min-heap
priority_queue<int, vector<int>, greater<int>> minH;
// Top-K largest using min-heap of size K
priority_queue<int, vector<int>, greater<int>> pq;
for (int x : nums) { pq.push(x); if (pq.size() > k) pq.pop(); }
// pq.top() = kth largest
// Custom comparator
auto cmp = [](pair<int,int>& a, pair<int,int>& b){ return a.first > b.first; };
priority_queue<pair<int,int>, vector<pair<int,int>>, decltype(cmp)> pq(cmp);
βœ“#ProblemDifficulty
11962. Remove Stones to Minimize the TotalMedium
21167. Minimum Cost to Connect SticksMedium
3215. Kth Largest Element in an ArrayMedium
4973. K Closest Points to OriginMedium
5703. Kth Largest Element in a StreamEasy
6295. Find Median from Data StreamHard
7621. Task SchedulerMedium
823. Merge K Sorted ListsHard
Ch7
Greedy Algorithms
Intermediate Prereq: Ch3 πŸ“„ Chapter Notes
β–Ό
0/8 solved 0%
  • SORT FIRST: Most greedy problems require sorting by some key (weight, ratio, end time)
  • INTERVAL SCHEDULING: Sort by end time β€” greedily take non-overlapping intervals
  • EXCHANGE ARGUMENT: Prove swapping adjacent elements doesn't improve solution
  • Ask: 'Does taking the best local choice block a better global solution?' If no β†’ greedy works
TimeO(n log n) with sort SpaceO(1)
// Interval scheduling β€” max non-overlapping intervals
sort(intervals.begin(), intervals.end(),
    [](auto& a, auto& b){ return a[1] < b[1]; }); // sort by end
int count = 0, prevEnd = INT_MIN;
for (auto& iv : intervals)
    if (iv[0] >= prevEnd) { count++; prevEnd = iv[1]; }
βœ“#ProblemDifficulty
11323. Maximum 69 NumberEasy
21710. Maximum Units on a TruckEasy
31338. Reduce Array Size to The HalfMedium
4435. Non-overlapping IntervalsMedium
555. Jump GameMedium
645. Jump Game IIMedium
7134. Gas StationMedium
8135. CandyHard
Ch8
Binary Search
Intermediate Prereq: Ch1 πŸ“„ Chapter Notes
β–Ό
0/9 solved 0%
  • ON SORTED ARRAY: Classic search / find leftmost or rightmost position
  • ON ANSWER SPACE: Binary search on the answer when feasibility is monotonic
  • FIND LEFTMOST: Use 'left = mid + 1' when condition met β€” pushes left boundary right
  • Trigger: 'minimize the maximum' or 'maximize the minimum' β†’ binary search on answer
TimeO(log n) SpaceO(1)
// Standard binary search
int lo = 0, hi = nums.size()-1;
while (lo <= hi) {
    int mid = lo + (hi-lo)/2;  // avoid overflow
    if (nums[mid] == target) return mid;
    else if (nums[mid] < target) lo = mid+1;
    else hi = mid-1;
}
// Binary search on answer (minimise)
int lo = minVal, hi = maxVal, ans = hi;
while (lo <= hi) {
    int mid = lo + (hi-lo)/2;
    if (feasible(mid)) { ans = mid; hi = mid-1; }
    else lo = mid+1;
}
βœ“#ProblemDifficulty
1704. Binary SearchEasy
235. Search Insert PositionEasy
32389. Longest Subsequence With Limited SumEasy
41283. Find the Smallest Divisor Given a ThresholdMedium
5410. Split Array Largest SumHard
6875. Koko Eating BananasMedium
7162. Find Peak ElementMedium
833. Search in Rotated Sorted ArrayMedium
94. Median of Two Sorted ArraysHard
Ch9
Backtracking
Advanced Prereq: Ch0 Recursion πŸ“„ Chapter Notes
β–Ό
0/11 solved 0%
  • GENERATION: Build all permutations/subsets/combinations β€” just enumerate
  • CONSTRAINED: Prune early when constraint violated (sum exceeds target)
  • Template: choose β†’ recurse β†’ unchoose (restore state)
  • Use 'start' index to avoid re-using earlier elements in combination problems
  • Use 'used[]' boolean array for permutations to avoid duplicate positions
  • Time: O(n! Γ— n) permutations, O(2ⁿ Γ— n) subsets β€” always exponential
SubsetsO(2ⁿ Γ— n) PermsO(n! Γ— n)
vector<vector<int>> result;
vector<int> current;
void backtrack(int start) {
    if (isComplete()) { result.push_back(current); return; }
    for (int i = start; i < candidates.size(); i++) {
        if (shouldPrune(i)) continue;
        current.push_back(candidates[i]);  // choose
        backtrack(i + 1);                  // recurse
        current.pop_back();                // unchoose
    }
}
βœ“#ProblemDifficulty
1797. All Paths From Source to TargetMedium
217. Letter Combinations of a Phone NumberMedium
322. Generate ParenthesesMedium
4967. Numbers With Same Consecutive DifferencesMedium
5216. Combination Sum IIIMedium
678. SubsetsMedium
746. PermutationsMedium
839. Combination SumMedium
979. Word SearchMedium
1051. N-QueensHard
1137. Sudoku SolverHard
Ch10
Dynamic Programming
Advanced Prereq: Ch0, Ch9 πŸ“„ Chapter Notes
β–Ό
0/11 solved 0%
  • Step 1: Define what dp[i] (or dp[i][j]) represents
  • Step 2: Find the recurrence relation (transition)
  • Step 3: Identify base cases
  • Step 4: Determine iteration order (ensure subproblems solved before needed)
  • DP vs Greedy: DP explores all choices; Greedy makes one. Use DP when Greedy fails
1D DPO(n) 2D DPO(mΓ—n)
// 1D DP β€” Climbing Stairs
vector<int> dp(n+1, 0); dp[0]=1; dp[1]=1;
for (int i = 2; i <= n; i++) dp[i] = dp[i-1] + dp[i-2];
// Coin Change (unbounded knapsack)
vector<int> dp(amount+1, INT_MAX); dp[0]=0;
for (int i = 1; i <= amount; i++)
    for (int coin : coins)
        if (coin<=i && dp[i-coin]!=INT_MAX) dp[i]=min(dp[i],dp[i-coin]+1);
// State machine DP (Stock with cooldown)
int hold = -prices[0], sold = 0, rest = 0;
for (int i = 1; i < prices.size(); i++) {
    int ph=hold,ps=sold,pr=rest;
    hold=max(ph,pr-prices[i]); sold=ph+prices[i]; rest=max(pr,ps);
}
βœ“#ProblemDifficulty
170. Climbing StairsEasy
2746. Min Cost Climbing StairsEasy
3322. Coin ChangeMedium
4714. Best Time to Buy and Sell Stock with Transaction FeeMedium
5309. Best Time to Buy and Sell Stock with CooldownMedium
663. Unique Paths IIMedium
7931. Minimum Falling Path SumMedium
8198. House RobberMedium
91143. Longest Common SubsequenceMedium
1072. Edit DistanceMedium
11139. Word BreakMedium
Ch11
Bonus Topics β€” Tries, Bit Manipulation, Intervals
β–Ό
0/6 solved 0%
  • Store strings character by character. Each node = one character; isEnd flag marks valid word
  • O(m) insert and search where m = string length. Use for: autocomplete, prefix search
struct TrieNode {
    unordered_map<char, TrieNode*> children;
    bool isEnd = false;
};
class Trie {
    TrieNode* root = new TrieNode();
public:
    void insert(string word) {
        TrieNode* curr = root;
        for (char c : word) {
            if (!curr->children.count(c)) curr->children[c] = new TrieNode();
            curr = curr->children[c];
        }
        curr->isEnd = true;
    }
    bool search(string word) {
        TrieNode* curr = root;
        for (char c : word) {
            if (!curr->children.count(c)) return false;
            curr = curr->children[c];
        }
        return curr->isEnd;
    }
};
  • POWER OF TWO: n > 0 && (n & (n-1)) == 0 β€” exactly one bit set
  • CLEAR LOWEST SET BIT: n & (n-1) β€” use in Kernighan popcount loop O(set bits)
  • ISOLATE LOWEST SET BIT: n & (-n) β€” rightmost 1 preserved, rest zero
  • XOR TRICK: a^a=0, a^0=a β€” cancel pairs; find unique element in O(n)/O(1)
  • SET / CLEAR / TOGGLE / CHECK: x|=(1<<n) / x&=~(1<<n) / x^=(1<<n) / (x>>n)&1
  • EXTRACT BITFIELD: (x >> start) & ((1 << width) - 1) β€” packet headers, hardware registers
  • BITMASK DP: state = subset bitmask of N elements; viable when N ≀ 20
Bit opsO(1) Popcount loopO(set bits) Bitmask DPO(2ⁿ · n)
// Core mask operations
x |= (1 << n);             // SET bit n
x &= ~(1 << n);            // CLEAR bit n
x ^= (1 << n);             // TOGGLE bit n
int b = (x >> n) & 1;      // CHECK bit n (returns 0 or 1)

// Power of two?
bool isPow2 = x > 0 && (x & (x-1)) == 0;

// Count set bits β€” Brian Kernighan O(set bits)
int cnt = 0;
while (x) { x &= x-1; cnt++; }  // clears lowest set bit each iteration

// XOR β€” find single non-duplicate in O(n) / O(1) (LC 136)
int res = 0;
for (int n : nums) res ^= n;    // paired elements cancel: x^x=0

// Count bits for 0..n β€” DP O(n) (LC 338)
vector<int> dp(n+1);
for (int i = 1; i <= n; i++) dp[i] = dp[i >> 1] + (i & 1);

// Extract bitfield [start, start+width)
uint32_t field = (x >> start) & ((1 << width) - 1);
// Insert pattern: x = (x & ~mask) | (pattern << start)
//   where mask = ((1 << width) - 1) << start
βš™οΈ Full Deep-Dive (10 tabs) πŸ”§ Systems Problems πŸ› Debugging Guide 🎯 Practice Problems β†’
βœ“#ProblemDifficulty
1208. Implement Trie (Prefix Tree)Medium
21268. Search Suggestions SystemMedium
3136. Single Number (XOR)Easy
4191. Number of 1 BitsEasy
557. Insert IntervalMedium
656. Merge IntervalsMedium
Ch12
Study Plan & Complexity Cheatsheet
β–Ό
  • Week 1: Ch0 Big O + Ch1 Two Pointers. Solve all Easy problems.
  • Week 2: Ch1 Sliding Window + Prefix Sum. Solve all Easy + 2 Medium.
  • Week 3: Ch2 Hashing. Core patterns β€” Two Sum, freq count, grouping.
  • Week 4: Ch3 Linked Lists. All patterns β€” fast/slow, reversal, merge.
  • Week 5: Ch4 Stacks (monotonic, bracket matching).
  • Week 6–7: Ch5 Trees β€” DFS first (preorder, postorder, LCA), then BFS + BST.
  • Week 8: Ch5 Graphs β€” DFS + BFS + Union-Find.
  • Week 9: Ch6 Heaps + Ch7 Greedy.
  • Week 10: Ch8 Binary Search β€” standard + answer space search.
  • Week 11: Ch9 Backtracking β€” all generation/constrained problems.
  • Week 12–13: Ch10 DP β€” 1D, 2D, state machine, knapsack.

Array / String

AccessO(1)
SearchO(n)
Insert/DeleteO(n)
AppendO(1) amort.

HashMap / HashSet

InsertO(1) avg
LookupO(1) avg
DeleteO(1) avg
Worst caseO(n)

Binary Tree

DFS / BFSO(n)
BST searchO(h)
BST balancedO(log n)
SpaceO(h) stack

Heap

PushO(log n)
PopO(log n)
PeekO(1)
BuildO(n)

Sorting

std::sortO(n log n)
Counting sortO(n+k)
Radix sortO(nk)
Merge sortO(n log n)

Graph

BFS / DFSO(V+E)
DijkstraO((V+E)log V)
Union-FindO(Ξ±(n))β‰ˆO(1)
Topo sortO(V+E)
← Back to All Roadmaps