Skip to content

Latest commit

 

History

History
247 lines (237 loc) · 16.1 KB

File metadata and controls

247 lines (237 loc) · 16.1 KB

Common Algorithms

For leetcode problems, the Python3 Solutions are published in jupyter notebook (still in progress). Check out more in Jupyter nbviewer.

Here, I summarized top common algorithms to deal with classic leetcode problems.

Binary Search

  1. Search for exact match
  2. Search for position to insert
  3. Sub-function (hard)

Tree

  1. Post-order Traversal Tree Problems
  2. Segment Tree / Binary Indexed Tree (Fenwick Tree)
  3. Morris Tree Traversal

Graph

  1. Disjoint Sets (Union Find)
  2. Shortest Paths Problems
  3. Kahn's Algorithm - Topological sorting
  4. Cycle Detection Algorithms
  5. DFS
  6. Tarjan's algorithm
    Strongly Connected Components (SCC)
  7. Kruskal's Algorithm
  8. Maze router Problems
    • Lee algorithm
  9. Euler Path (Hierholzer's algorithm)

Dynamic Programming

  1. Permutations and Combinations
  2. Classic DP
  3. Knapsack problem
    1. 0/1 Knapsack
    2. Complete Knapsack
  4. Kadane's algorithm (DP approach to solve the largest contiguous elements in an array)
  5. Two-dimensional DP
  6. Game Theory Other Solution: MinMax

Misc

  1. Interval Scheduling
    Solution: Greedy / Boundary Counting
  2. Sliding window
  3. PreSum
  4. Stack
    1. Monotonic stack
    2. RPN (Reversed Polish Notation)
    3. Good stack problems
  5. Bit Operation
  6. Sieve of Eratosthenes
  7. Integer Factorization
  8. Fourier Transform
  9. Modulo Arithmetic
  10. Link Analysis
  11. Reservoir Sampling
  12. Boyer-Moore Majority Vote algorithm
  13. Bézout's identity (GCD)
  14. Euclidean
  15. SLR(1)
  16. DFA - Deterministic Finite Automaton
  17. Round Robin

Tricky Solutions

* [65. Valid Number]() - DFA
* [136. Single Number]() - XOR
* [240. Search a 2D Matrix II]() - Start from Right-top Corner

String

  1. TBD