Algorithms Illuminated (Parts 1-4)

by Tim Roughgarden · 2020

A comprehensive four-part series on algorithms: asymptotic notation and divide-and-conquer (Part 1), graph algorithms and data structures (Part 2), greedy algorithms and dynamic programming (Part 3), and NP-hard problems (Part 4).

193Extracted Problems
24Chapters
0Linked to DB
193Book Total
AlgorithmsDivide & ConquerGraphsDynamic ProgrammingNP-CompletenessTextbook
193 shown
  • 1-1Derive recurrence for Karatsuba splitting into three parts
    Divide&Conquer
    Medium
    1-2Implement MergeSort and count inversions in a permutation
    Divide&ConquerSorting
    Easy
    1-3Prove by induction MergeSort sorts any array correctly
    SortingProof
    Medium
    1-4Analyze number of recursive calls in Karatsuba for n-digit input
    Divide&Conquer
    Medium
    1-5Give O(n log n) algorithm for pairs (i<j) with a_i > 2*a_j
    Divide&ConquerCounting
    Hard
    1-6Design O(n) algorithm to check valid merge of two sorted sequences
    MergeArrays
    Medium
    1-7Prove Karatsuba works for n not a power of 2
    Divide&ConquerProof
    Easy
    1-8Problem 1.8
    Medium
  • 2-1Prove f(n)=O(g(n)) implies g(n)=Omega(f(n))
    AsymptoticProof
    Easy
    2-2Determine if n^1.001+n log n = Theta(n^1.001) or Theta(n log n)
    Asymptotic
    Medium
    2-3Arrange by growth: n log n, n^2, 2^n, log n!, n^0.5, log^2 n
    Asymptotic
    Easy
    2-4Give f,g where f!=O(g) and g!=O(f) (incomparable)
    Asymptotic
    Medium
    2-5Prove/disprove: if f=O(g) and h=O(g) then f=O(h)
    AsymptoticProof
    Medium
    2-6Prove n! = O(n^n) and n! = omega(2^n)
    AsymptoticMath
    Medium
    2-7Show log(n!) = Theta(n log n) via Stirling
    AsymptoticMath
    Hard
    2-8Prove master theorem case: T(n)=aT(n/b)+cn^k, a>b^k => T(n)=Theta(n^{log_b a})
    AsymptoticMasterMethod
    Hard
  • 3-1Implement D&C closest-pair and analyze running time
    Divide&ConquerGeometry
    Hard
    3-2Count post-sort inversions: pairs (i<j) with a_i < a_j
    Divide&ConquerSorting
    Easy
    3-3Generalize Strassen for 7x7 matrices - how many multiplications?
    Divide&ConquerMatrix
    Hard
    3-4Design D&C max subarray sum in O(n log n)
    Divide&ConquerArrays
    Medium
    3-5Count significant inversions (a_i > 2*a_j) using modified merge sort
    Divide&ConquerCounting
    Medium
    3-6Show closest-pair works for Manhattan distance
    Divide&ConquerGeometry
    Medium
    3-7Prove D&C closest-pair runs in O(n log n)
    Divide&ConquerGeometry
    Medium
    3-8Problem 3.8
    Medium
  • 4-1Solve T(n)=9T(n/3)+n via master method
    MasterMethod
    Easy
    4-2Solve T(n)=2T(n/2)+n log n via master method
    MasterMethod
    Easy
    4-3Solve T(n)=T(2n/3)+1 - which algorithm?
    MasterMethodBinarySearch
    Easy
    4-4Solve T(n)=3T(n/4)+n log n - which case?
    MasterMethod
    Medium
    4-5Describe algorithm for each master theorem case
    MasterMethod
    Medium
    4-6Prove master theorem case 1: T(n)=aT(n/b)+cn^k, a>b^k => T(n)=Theta(n^{log_b a})
    MasterMethodProof
    Hard
    4-7Solve T(n)=2T(n/2)+n/log n - can master theorem apply?
    MasterMethod
    Hard
    4-8Problem 4.8
    Medium
  • 5-1Trace QuickSort on [4,1,3,5,2] with last-element pivot
    QuickSortSorting
    Easy
    5-2Expected comparisons for randomized QuickSort on length n
    QuickSortRandomized
    Medium
    5-3Implement median-of-three pivot, analyze improvement
    QuickSort
    Medium
    5-4Design QuickSort variant with O(n log n) worst-case
    QuickSortDivide&Conquer
    Hard
    5-5Prove expected QuickSort comparisons is O(n log n)
    QuickSortRandomized
    Hard
    5-6Show QuickSort recursion depth O(log n) with high probability
    QuickSortRandomized
    Medium
    5-7Implement 3-way partition QuickSort for duplicates
    QuickSortSorting
    Medium
    5-8Problem 5.8
    Medium
  • 6-1Trace RSelect finding 3rd smallest in [7,2,9,4,3,8,5]
    SelectionRandomized
    Easy
    6-2Show DSelect recurrence solves to O(n)
    SelectionDivide&Conquer
    Medium
    6-3Prove median of medians is >=30% and <=70% of all elements
    SelectionProof
    Medium
    6-4Implement DSelect with groups of 7, analyze recurrence
    Selection
    Hard
    6-5Design algorithm for kth smallest in sorted matrix
    SelectionBinarySearch
    Medium
    6-6Given two sorted arrays, find median of union in O(log(min(m,n)))
    SelectionBinarySearch
    Medium
    6-7Prove RSelect runs in expected O(n) even with adversarial input
    SelectionRandomized
    Hard
    6-8Problem 6.8
    Medium
  • 7-1Represent directed graph with lists vs matrices - compare sparse/dense space
    GraphRepresentation
    Easy
    7-2Prove reachable vertices from source computed in O(V+E)
    Graph
    Easy
    7-3Design algorithm to check connectivity via BFS/DFS
    GraphConnectivity
    Easy
    7-4Compute transitive closure via Floyd-Warshall
    GraphClosure
    Medium
    7-5Problem 7.5
    Hard
    7-6Problem 7.6
    Easy
    7-7Problem 7.7
    Easy
    7-8Problem 7.8
    Medium
  • 8-1Trace BFS on 7-vertex graph, find shortest paths from s
    BFSGraph
    Easy
    8-2Implement topological sort using DFS, detect cycles
    DFSTopSort
    Medium
    8-3Run Kosaraju two-pass SCC on 8-vertex directed graph
    DFSSCC
    Hard
    8-4Show reversing all DAG edges reverses topological order
    DAGTopSort
    Medium
    8-5Design algorithm to count simple paths between two DAG vertices
    DAGDP
    Medium
    8-6Prove undirected graph has <=2 components after removing one vertex
    GraphConnectivity
    Easy
    8-7Prove every DAG has at least one source and one sink
    DAGProof
    Easy
    8-8Problem 8.8
    Medium
  • 9-1Trace Dijkstra on weighted 6-vertex graph from A
    DijkstraSSSP
    Easy
    9-2Prove Dijkstra correct for non-negative weights
    DijkstraProof
    Hard
    9-3Implement Dijkstra with heap, analyze O((E+V) log V)
    DijkstraHeap
    Medium
    9-4Construct counterexample where Dijkstra fails with negative weights
    DijkstraCounterexample
    Easy
    9-5Design Dijkstra variant for top-k shortest paths
    DijkstraKShortestPaths
    Hard
    9-6Prove Dijkstra processes vertices in non-decreasing distance
    DijkstraProof
    Medium
    9-7Implement bidirectional Dijkstra from source and destination
    DijkstraOptimization
    Medium
    9-8Problem 9.8
    Medium
  • 10-1Illustrate binary heap from array, perform extract-min
    Heap
    Easy
    10-2Prove BUILD-MAX-HEAP runs in O(n), not O(n log n)
    HeapProof
    Medium
    10-3Implement min-heap with decrease-key in O(log n)
    Heap
    Medium
    10-4Design d-ary heap, analyze insert/extract-min times
    Heap
    Medium
    10-5Prove heap sort always O(n log n) regardless of input
    HeapSorting
    Easy
    10-6Implement heap priority queue for Dijkstra, analyze speedup
    HeapDijkstra
    Medium
    10-7Find median of stream using two heaps
    HeapStreaming
    Medium
    10-8Problem 10.8
    Medium
  • 11-1Insert into AVL tree, perform rotations to restore balance
    TreeBST
    Easy
    11-2Prove randomly built BST has O(log n) expected height
    BSTRandomized
    Hard
    11-3Implement sorted set using balanced BST (AVL/RB)
    BSTTree
    Medium
    11-4Show inorder traversal sequence of a BST
    BSTTree
    Easy
    11-5Design BST supporting split/join in O(log n)
    TreeBST
    Medium
    11-6Prove AVL height <= 1.44*log2(n+2)-1.328
    TreeAVL
    Hard
    11-7Find successor of element in BST in O(h)
    BSTTree
    Easy
    11-8Problem 11.8
    Medium
  • 12-1Show chaining for keys [10,22,31,4,15,28] in table size 7
    HashChaining
    Easy
    12-2Implement linear vs quadratic probing, compare clustering
    HashOpenAddressing
    Medium
    12-3Design Bloom filter, compute false positive rate for k hashes, m bits
    HashBloomFilter
    Hard
    12-4Prove uniform hashing gives <=1/(1-alpha) expected unsuccessful probes
    HashProbability
    Medium
    12-5Design hash table with constant worst-case operations (perfect hashing)
    HashDesign
    Hard
    12-6Show Cuckoo hashing insertion, prove expected O(1) amortized
    HashCuckoo
    Hard
    12-7Problem 12.7
    Easy
    12-8Problem 12.8
    Medium
  • 13-1Prove greedy min-max-lateness scheduling optimal via exchange
    GreedyScheduling
    Hard
    13-2Design greedy interval scheduling for max non-overlapping intervals
    GreedyScheduling
    Easy
    13-3Find counterexample where greedy coin change fails
    GreedyCounterexample
    Easy
    13-4Prove greedy fractional knapsack optimal
    GreedyKnapsack
    Medium
    13-5Design greedy minimum platforms for train scheduling
    GreedyScheduling
    Medium
    13-6Prove exchange lemma: swapping preserves feasibility
    GreedyProof
    Hard
    13-7Solve task scheduling with deadlines/profits using greedy
    GreedyScheduling
    Medium
    13-8Problem 13.8
    Medium
  • 14-1Build Huffman tree for frequencies [a:45,b:13,c:12,d:16,e:9,f:5]
    GreedyHuffman
    Easy
    14-2Prove Huffman optimal via exchange argument on tree
    GreedyHuffman
    Hard
    14-3Implement Huffman encode/decode for text file
    GreedyHuffman
    Medium
    14-4Show prefix-free condition equivalent to full binary tree
    GreedyHuffman
    Medium
    14-5Generalize Huffman to ternary codes (alphabet size 3)
    GreedyHuffman
    Hard
    14-6Compute optimal bits for message from character frequencies
    GreedyHuffman
    Easy
    14-7Problem 14.7
    Easy
    14-8Problem 14.8
    Medium
  • 15-1Trace Prim on weighted 6-vertex graph from A
    MSTPrim
    Easy
    15-2Run Kruskal on 7-vertex, 12-edge graph
    MSTKruskal
    Easy
    15-3Prove cut property: lightest crossing edge in every MST
    MSTProof
    Medium
    15-4Implement union-find with path compression/union by rank
    UnionFindMST
    Medium
    15-5Prove cycle property: heaviest cycle edge not in any MST
    MSTProof
    Medium
    15-6Design max-spacing k-clustering using MST
    MSTClustering
    Medium
    15-7Show Prim with heap runs in O((E+V) log V)
    MSTPrim
    Hard
    15-8Prove Kruskal correctness via cut property
    MSTKruskal
    Medium
    15-9Design second-best MST algorithm
    MST
    Hard
  • 16-1Compute max-weight independent set in path [1,4,5,4] via DP
    DPGraph
    Easy
    16-2Solve 0/1 knapsack capacity 10 with given items
    DPKnapsack
    Easy
    16-3Prove optimal solution reconstruction from DP table correct
    DPProof
    Medium
    16-4Solve subset-sum: find subset summing to target
    DPSubsetSum
    Easy
    16-5Design DP partition: equal-sum subsets?
    DPPartition
    Medium
    16-6Solve unbounded knapsack (unlimited reuse) via DP
    DPKnapsack
    Medium
    16-7Prove weighted independent set DP has optimal substructure
    DPProof
    Medium
    16-8Problem 16.8
    Medium
  • 17-1Compute edit distance kitten->sitting, show alignment
    DPStrings
    Easy
    17-2Design DP for optimal BST given key probabilities
    DPBST
    Hard
    17-3Implement Kadane max-sum subarray, prove correctness
    DPArrays
    Easy
    17-4Compute LCS of ABCBDAB and BDCABA
    DPStrings
    Easy
    17-5Design DP for optimal convex polygon triangulation
    DPGeometry
    Hard
    17-6Solve matrix chain multiplication [5,4,6,2,7]
    DPMatrix
    Medium
    17-7Design O(n log n) LIS DP
    DPLIS
    Medium
    17-8Problem 17.8
    Medium
  • 18-1Trace Bellman-Ford on 5-vertex graph with negative edge
    BellmanFordSSSP
    Easy
    18-2Prove Bellman-Ford detects negative cycles from source
    BellmanFordNegCycle
    Medium
    18-3Run Floyd-Warshall on 4 vertices, show distance matrices
    FloydWarshallAPSP
    Easy
    18-4Prove Floyd-Warshall optimal substructure
    FloydWarshallProof
    Medium
    18-5Design O(n^2*2^n) DP for TSP using bitmask
    DPTSP
    Hard
    18-6Show all-pairs shortest path reduces to single-source case
    APSPSSSP
    Medium
    18-7Problem 18.7
    Easy
    18-8Problem 18.8
    Medium
  • 19-1Why TSP believed harder than MST: decision vs optimization?
    NPTSP
    Easy
    19-2Prove: P=NP implies every NP problem solves in polynomial time
    NPComplexity
    Medium
    19-3Show polynomial SAT solver implies P=NP
    NPSAT
    Hard
    19-4Classify: sorting, MST, max clique, 3-coloring, shortest path as P or NP-complete
    NPComplexity
    Easy
    19-5Define poly-time reducibility, show transitive
    NPReduction
    Medium
    19-6Explain NP-hard vs NP-complete with examples
    NPComplexity
    Easy
    19-7Problem 19.7
    Easy
    19-8Problem 19.8
    Medium
  • 20-1Design 2-approximation for vertex cover, prove ratio
    ApproximationVertexCover
    Medium
    20-2Apply local search to max-cut: flip vertices to improve
    LocalSearchMaxCut
    Medium
    20-3Prove greedy set cover achieves O(log n) approximation
    ApproximationSetCover
    Hard
    20-4Design 2-approximation for metric TSP via MST doubling
    ApproximationTSP
    Medium
    20-5Show greedy max cut achieves >= half optimal
    ApproximationMaxCut
    Medium
    20-6Prove MAX-3SAT not approximable within 7/8 unless P=NP
    ApproximationPCP
    Hard
    20-7Design factor-2 approximation for makespan on identical machines
    ApproximationScheduling
    Medium
    20-8Problem 20.8
    Medium
  • 21-1Design O(n^2*2^n) DP TSP, run on 5-vertex complete graph
    ExactTSP
    Hard
    21-2Apply color-coding for path of length k in O(2^k n^{O(1)})
    ExactColorCoding
    Hard
    21-3Use inclusion-exclusion to count set covers in O(2^m poly(n))
    ExactSetCover
    Hard
    21-4Show 3-coloring in O(1.3289^n) via branch/bound
    ExactGraphColoring
    Hard
    21-5Design meet-in-the-middle SUBSET SUM O(2^{n/2})
    ExactSubsetSum
    Medium
    21-6Prove max independent set in O(1.618^n) via branching
    ExactBranching
    Hard
    21-7Show SAT in O(1.5^n) via DPLL with unit propagation
    ExactSAT
    Medium
    21-8Problem 21.8
    Medium
  • 22-1Reduce 3SAT to INDEPENDENT SET via clause-variable gadget
    NPReduction
    Hard
    22-2Prove VERTEX COVER NP-complete from INDEPENDENT SET
    NPReduction
    Medium
    22-3Reduce SUBSET SUM to PARTITION
    NPReduction
    Medium
    22-4Prove HAMILTONIAN CYCLE NP-complete from 3SAT
    NPReduction
    Hard
    22-5Show CLIQUE NP-complete from 3SAT
    NPReduction
    Medium
    22-6Prove 3-COLOR NP-complete from 3SAT using OR-gadget
    NPReduction
    Hard
    22-7Reduce VERTEX COVER to DOMINATING SET
    NPReduction
    Hard
    22-8Problem 22.8
    Medium
  • 23-1Explain co-NP vs NP, give co-NP problem examples
    ComplexitycoNP
    Medium
    23-2Show NP != co-NP implies P != NP
    ComplexityProof
    Medium
    23-3Define polynomial hierarchy PH, relation to P/NP
    ComplexityPH
    Hard
    23-4Prove SAT phase transition at clause/variable ratio ~4.26
    ComplexitySAT
    Hard
    23-5Overview of circuit complexity and P/poly class
    ComplexityCircuits
    Medium
    23-6Significance of Exponential Time Hypothesis for algorithm design
    ComplexityETH
    Medium
    23-7Problem 23.7
    Easy
    23-8Problem 23.8
    Medium
  • 24-1Describe FCC auction as optimization, identify NP-hard aspects
    CaseStudy
    Easy
    24-2Design greedy approximation for spectrum allocation
    CaseStudyApproximation
    Medium
    24-3Why truthfulness matters in auction design
    CaseStudyMechanismDesign
    Medium
    24-4Show VCG mechanism applied to spectrum allocation
    CaseStudyMechanismDesign
    Hard
    24-5Analyze complexity of VCG payments computation
    CaseStudyComplexity
    Medium
    24-6Problem 24.6
    Easy
    24-7Problem 24.7
    Easy
    24-8Problem 24.8
    Medium