Algorithms
Index
Computational Geometry 1
Strings 1
Basic Graphs 2
Flow networks and matching [Intermediate/Advanced] 2
Dynamic Programming 2
Greedy 3
Number Theory 3
Maths (Probability, Counting, Game Theory, Group Theory, Generating functions, Permutation Cycles, Linear Algebra) 4
Data Structures 6
Search Techniques/Bruteforce writing techniques/Randomized algorithms 7
1. Computational Geometry
Graham Scan algorithm for Convex Hull O(n*log(n)).
a. Online construction of 3D convex hull in O(n^2).
b. Bentley Ottmann algorithm to list all intersection points of n line segments in O((n+I)*logn).
■ Suggested Reading
1. [Link]
c. Rotating Calipers Technique.
■ Suggested Reading - [Link]
■ Problems - Refer the article for a list of problems which can be solved using Rotating Calipers technique.
d. Line Sweep/Plane Sweep algorithms -
■ Area/Perimeter of Union of Rectangles.
■ Closest pair of points.
■ Suggested Reading -
1. [Link]
■ Problems - Follow the tutorial for list of problems.
e. Area of Union of Circles.
f. Delaunay Triangulation of n points in O(n*logn).
g. Voronoi Diagrams of n points in O(n*logn) using Fortune’s algorithm.
h. Point in a polygon problem -
■ O(n) solution without preprocessing.
■ O(logn) algorithm with O(n*logn) preprocessing for convex polygons.
i. Problems on computational geometry -
■ BSHEEP, BULK, S EGVIS, C ONDUIT, RUNAWAY, DIRVS, RAIN1, SHAMAN, T CUTTER, L ITEPIPE, R HOMBS, FSHEEP, FLBRKLIN, CERC07P,
BAC, ALTARS, CERC07C, NECKLACE, CH3D, RECTANGL, P OLYSSQ, FOREST2, KPPOLY, RAIN2, SEGMENTS, ARCHPLG, BALLOON,
CIRCLES, COMPASS, E OWAMRT, ICERINK on SPOJ.
■ Culture Growth, P olygon Cover on Topcoder.
j. Suggested Reading -
■ Computational Geometry: Algorithms and applications. Mark De Berg.
2. Strings
a. Knuth Morris Pratt algorithm
■ Problems - NHAY, PERIOD on SPOJ.
■ Suggested Reading -
1. Cormen chapter on Strings.
2. [Link]
b. Aho Corasick algorithm.
c. Suffix Arrays
■ O(n^2*logn) Naive method of suffix array construction
■ O(n*logn^2) method of suffix array construction
■ O(n*log n) method of suffix array construction.
■ O(n) method of suffix array construction
■ O(n) LCA preprocess on Suffix Arrays to solve a variety of string problems.
d. Suffix Trees
■ O(n) construction of Suffix trees using Ukkonen's algorithm.
■ O(n) construction of Suffix Trees if provided with Suffix Arrays using Farach’s algorithm.
e. Suffix Automata
■ O(n) Suffix Automaton construction.
f. Dictionary Of Basic Factors
■ O(n*log n) method of DBF construction using Radix Sort.
g. Manacher’s algorithm to find length of palindromic substring of a string centered at a position for each position in the string. Runtime -> O(n).
h. Searching and preprocessing Regular Expressions consisting of ‘?’, ‘*’.
i. Multi-dimensional pattern matching.
j. Problems on Strings [can be solved with a variety of techniques] -
■ DISUBSTR, PLD, MSTRING, REPEATS, JEWELS, ARCHIVER, P ROPKEY, LITELANG, EMOTICON, WORDS, AMCODES, UCODES, PT07H,
MINSEQ, TOPALIN, BWHEELER, BEADS, S ARRAY, LCS, LCS2, SUBST1, PHRASES, PRETILE on SPOJ
■ [Link]
3. Basic Graphs
a. Representation of graphs as adjacency list, adjacency matrix, incidence matrix and edge list and uses of different representations in different
scenarios.
b. Breadth First Search.
■ problems -
1. PPATH, O
NEZERO, W ATER on SPOJ
c. Depth First Search.
d. Strongly Connected Components.
■ problems -
1. TOUR and BOTTOM on SPOJ.
e. Biconnected Components, Finding articulation points and bridges.
■ problems -
1. RELINETS, PT07A on SPOJ.
f. Dijkstra algorithm -
■ problems -
1. SHPATH on SPOJ.
g. Floyd Warshall algorithm -
■ problems -
1. COURIER on SPOJ.
h. Minimum Spanning Tree
■ problems -
1. BLINNET on SPOJ.
i. Flood-fill algorithm
j. Topological sort
k. Bellman-Ford algorithm.
l. Euler Tour/Path.
■ problems - WORDS1 on SPOJ.
m. Suggested reading for most of the topics in Graph algorithms -
■ [Link]
■ Also refer to the tutorial for problems concerning these techniques.
■ Cormen chapter 22 to 24.
4. Flow networks and matching [Intermediate/Advanced]
a. Maximum flow using Ford Fulkerson Method.
■ Suggested Reading -
1. [Link]
■ problems - TAXI, POTHOLE, IM, QUEST4, MUDDY, EN, CABLETV, STEAD, N
ETADMIN, COCONUTS, OPTM on SPOJ.
b. Maximum flow using Dinic’s Algorithm.
■ Problems - PROFIT on spoj.
c. Minimum Cost Maximum Flow.
■ Successive Shortest path algorithm.
■ Cycle Cancelling algorithm.
■ Suggested Reading -
1. [Link]
d. Maximum weighted Bipartite Matching (Kuhn Munkres algorithm / Hungarian Method)
■ problems - GREED, S CITIES, TOURS on SPOJ | [Link]
e. Stoer Wagner min-cut algorithm.
f. Hopcroft Karp bipartite matching algorithm.
1. problems - ANGELS on SPOJ.
g. Maximum matching in general graph (blossom shrinking)
h. Gomory-Hu [Link]
■ i) Problems - MCQUERY on Spoj.
i. Chinese Postman Problem.
■ problems - [Link]
■ Suggested Reading - [Link]
j. Suggested Reading for the full category ->
■ Network flow - Algorithms and Applications by Ahuja
■ Cormen book chapter 25.
5. Dynamic Programming
a. Suggested Reading - Dynamic Programming(DP) as a tabulation method
■ Cormen chapter on DP
b. Standard problems (you should really feel comfortable with these types)
■ [Link]
■ [Link]
c. State space reduction
■ [Link]
■ [Link]
■ [Link]
d. Solving in the reverse - easier characterizations looking from the end
■ [Link]
■ [Link]
e. Counting/optimizing arrangements satisfying some specified properties
■ [Link]
■ [Link]
■ [Link]
■ [Link]
■ [Link]
■ [Link]
f. DP on probability spaces
■ [Link]
■ [Link]
■ [Link]
g. DP on trees
■ [Link]
■ [Link]
■ [Link]
h. DP with data structures
■ [Link]
■ [Link]
■ [Link]
■ [Link]
i. Symmetric characterization of DP state
■ [Link]
j. A good collection of problems
■ [Link]
■ [Link]
6. Greedy
a. Suggested Reading -
■ Chapter on Greedy algorithms in Cormen.
■ [Link]
b. problems - refer to the topcoder tutorial.
7. Number Theory
a. Modulus arithmetic - basic postulates [Including modular linear equations,Continued fraction and Pell's equation]
■ Suggested Reading -
1. Chapter 1 from Number Theory for Computing by SY Yan [ Recommended ]
2. 31.1, 31.3 and 31.4 from Cormen
3. [Link]/tc?module=Static&d1=tutorials&d2=primeNumbers
■ Problems
1. [Link]
2. [Link]
3. [Link]
4. [Link]
5. [Link]
b. Fermat's theorem, Euler’s Totient theorem ( totient function, order , primitive roots )
■ Suggested Reading
1. 1.6, 2.2 from Number Theory by SY Yan
2. 31.6 , 31.7 from Cormen
■ Problems
1. [Link]
2. [Link]
c. Chinese remainder theorem
■ Suggested Reading
1. 31.5 from Cormen
2. 1.6 from Number Theory by SY Yan
■ Problems
1. Project Euler 271
2. [Link]
d. Primality tests -
■ Deterministic O(sqrt(n) ) approach
■ Probabilistic primality tests - Fermat primality test, Miller-Rabin Primality test
1. Suggested Reading -
a. [Link]
b. Cormen 31.8
c. 2.2 from Number Theory by SY Yan
2. Problems -
a. PON, PRIC, SOLSTRAS on SPOJ
b. [Link]
e. Prime generation techniques - Sieve of Eratosthenes
■ Suggested Problems - PRIME1 on SPOJ
f. GCD using euclidean method
■ Suggested Reading
1. 31.2 Cormen
■ Problems -
1. GCD on SPOJ
2. [Link]
g. Logarithmic Exponentiation
■ Suggested Reading -
1. [Link]
h. Integer Factorization
■ Naive O(sqrt(n)) method
■ Pollard Rho factorization
■ Suggested Reading
1. 2.3 from Number Theory SY Yan
2. 31.9 Cormen
■ Problems -
1. [Link]
2. [Link]
3. [Link]
i. Stirling numbers
j. Wilson theorem
■ nCr % p in O(p) preprocess and O(log n ) query
k. Lucas Theorem
l. Suggested Reading for Number Theory -
■ Number theory for computing by Song Y Yan [ Simple book describing concepts in details ]
■ Concepts are also superficially covered in Chapter 31 of Introduction to Algorithms by Cormen
■ [Link]
■ [Link]
m. Problems on Number Theory -
■ [Link]
■ [Link]
8. Maths (Probability, Counting, Game Theory, Group Theory, Generating functions, Permutation Cycles, Linear Algebra)
a. Probability
Syllabus
■ Basic probability and Conditional probability
1. Suggested problems
a. [Link]
b. [Link]
■ Random variables, probability generating functions
■ Mathematical expectation + Linearity of expectation
1. Suggested problems
a. [Link]
b. [Link]
■ Special discrete and continuous probability distributions
1. Bernoulli, Binomial, Poisson, normal distribution
2. Suggested Problem
a. [Link]
■ Suggested Readings
1. Cormen appendix C (very basic)
2. Topcoder probabilty tutorial [Link]
3. [Link]
4. [Link]
5. William Feller, An introduction to probability theory and its applications
b. Counting
Syllabus
■ Basic principles - Pigeon hole principle, addition, multiplication rules
1. Suggested problems
a. [Link]
b. [Link]
3. Suggested readings
a. [Link]
b. [Link]
c. [Link]
■ Inclusion-exclusion
1. Suggested readings
a. [Link]
2. Suggested problems
a. [Link]
b. [Link]
■ Special numbers
1. Suggested reading - Stirling, eulerian, harmonic, bernoulli, fibonacci numbers
a. [Link]
b. [Link]
c. [Link]
d. [Link]
e. [Link]
f. Concrete mathematics by Knuth
2. Suggested problems
a. [Link]
b. [Link]
c. [Link]
d. [Link]
■ Advanced counting techniques - Polya counting, burnside lemma
1. Suggested reading
a. [Link]
b. [Link]
2. Suggested Problems
a. [Link]
b. [Link]
c. Game theory
Syllabus
■ Basic principles and Nim game
1. Sprague grundy theorem, grundy numbers
2. Suggested readings
a. [Link]
b. [Link]
c. [Link]
d. [Link]
3. Suggested problems
a. [Link]
b. [Link]
■ Hackenbush
1. Suggested readings
a. [Link]
b. [Link]
2. Suggested problems
a. [Link]
b. [Link]
d. Linear Algebra
Syllabus
■ Matrix Operations
1. Addition and subtraction of matrices
a. Suggested Reading
i. Cormen 28.1
2. Multiplication ( Strassen's algorithm ), logarithmic exponentiation
a. Suggested reading
i. Cormen 28.2
ii. Linear Algebra by Kenneth Hoffman Section 1.6
b. Problems
i. [Link]
3. Matrix transformations [ Transpose, Rotation of Matrix, Representing Linear transformations using matrix ]
a. Suggested Reading
i. Linear Algebra By Kenneth Hoffman Section 3.1,3.2,3.4,3.7
b. Problems
i. [Link]
ii. JPIX on Spoj
4. Determinant , Rank and Inverse of Matrix [ Gaussian Elimination , Gauss Jordan Elimination]
a. Suggested Reading
i. 28.4 Cormen
ii. Linear Algebra by Kenneth Chapter 1
b. Problems
i. [Link]
ii. [Link]
iii. [Link]
iv. HIGH on Spoj
5. Solving system of linear equations
a. Suggested Reading
i. 28.3 Cormen
ii. Linear Algebra by Kenneth Chapter 1
b. Problems -
i. [Link]
6. Using www exponentiation to solve recurrences
a. Suggested Reading
i. [Link]
b. Problems
i. REC, RABBIT1 , PLHOP on spoj
ii. [Link] ,
[Link]
[Link]
7. Eigenvalues and Eigenvectors
a. Problems
i. [Link]
■ Polynomials
1. Roots of a polynomial [ Prime factorization of a polynomial, Integer roots of a polynomial, All real roots of a polynomial ]
a. Problems
i. [Link]
ii. POLYEQ , ROOTCIPH on Spoj
2. Lagrange Interpolation
a. Problems
i. [Link]
ii. [Link]
e. Permutation cycles
■ Suggested Reading
1. Art of Computer Programming by Knuth Vol. 3
■ Problems
1. Shuffle Method, Permutation and Word Game on topcoder.
f. Group Theory
■ Burnside Lemma, Polya’s theorem
1. Suggested Reading
a. Hernstein's topics in algebra
b. [Link]
2. Problems
a. TRANSP on spoj
b. [Link]
b. Generating functions
■ Suggested Reading
1. Herbert Wilf's generating functionology
2. Robert Sedgewick and Flajoulet's Combinatorial analysis
9. Data Structures
i. Basic
a. Arrays/Stacks/Queues :
■ Problems
1. [Link]
2. [Link]
3. [Link]
■ Reading:
1. CLRS: section 10.1
2. [Link]
b. Singly/Doubly Linked List :
■ Problems
1. https://[Link]/problems/POSTERS/
■ Reading: CLRS: section 10.2, Mark Allen Weiess Chapter 3
c. Hash Tables :
■ Problems
1. [Link]
2. [Link]
■ Reading: CLRS: Chapter 11, Mark Allen Weiess Chapter 5
d. Circular linked list / queue
■ Problems
1. [Link]
e. Binary/nary Trees
■ Reading
1. CLRS: section 10.4
2. CLRS: Chapter 12
3. Mark Allen Weiess Chapter 4
4. http://[Link]/tc?module=Static&d1=tutorials&d2=binarySearchRedBlack
f. Heaps
■ Problems
1. [Link]
2. https://[Link]/problems/EXPEDI/
■ Reading : Mark Allen Weiess Chapter 6
ii. Advanced
a. Trie (Keyword tre
■ Problems
1. [Link]
2. [Link]
■ Reading
b. Interval trees / Segment Trees
■ Problems
1. [Link]
2. [Link]
■ Reading
c. Fenwick(Binary Indexed) trees
■ Problems
1. [Link]
■ Reading: [Link]
d. Disjoint data structures
■ Problems
1. [Link]
2. [Link]
■ Reading:
1. [Link]
2. Mark Allen Weiess Chapter 8
e. Range minimum Query(RMQ)
■ Problems
1. [Link]
■ Reading [Link]
f. Customized interval/segment trees (Augmented DS)
■ Problems
1. [Link]
2. [Link]
■ Reading: CLRS: Chapter 14 (augmented DS)
g. AVL Trees
■ Problems
1. [Link]
iii. Miscellaneous (Not to be covered)
a. Splay Trees
b. B/B+ Trees
c. k-d Trees
d. Red-black Trees
e. Skip List
f. Binomial/Fibonacci heaps
iv. Exercises
1. [Link] (Hint: Heaps)t
2. [Link] (Hint: Interval Trees)
3. [Link] (Hint: Heaps)
4. [Link] (Hint: Trie)
5. [Link] (Hint: Interval Trees)
6. [Link] (Hint: Disjoint )
7. [Link]
8. [Link]
9. [Link]
10. Search Techniques/Bruteforce writing techniques/Randomized algorithms
a. Backtracking - [Beginner].
■ problems ->
1. N queens problems
2. Knight’s Tour
3. Sudoku Problem
4. Tiling Problem.
5. 15 puzzle.
b. Dancing Links and Algorithm X given by Knuth - [Advanced]
■ problems - PRLGAME, SUDOKU, NQUEEN on SPOJ
■ Suggested reading -
1. [Link]
c. Binary Search - [Beginner].
■ problems - AGGRCOW on SPOJ. Refer the tutorial for more problems.
■ finding all real roots of a polynomial using binary search. [intermediate].
■ Suggested Reading -
1. [Link]
d. Ternary Search - [Intermediate].
■ problems -
1. [Link]
2. [Link]
3. [Link]
4. [Link]
5. [Link]
6. [Link]
7. [Link]
e. Meet in the middle [Intermediate].
■ problems -
1. [Link]
2. Hill Climbing [Advanced].
f. Regular Iteration to reach a fixed point [Advanced].
■ Newton-Raphson method to find root of a mathematical function.
■ Iterations to solve linear non homogeneous system of equations.
General programming issues in contests:
g. Arithmetic Precision - [Beginner].
■ Suggested Reading -
1. [Link]
h. Representing sets with bitmasks and manipulating bitmasks - [Beginner].
■ Suggested Reading -
1. [Link]
■ problems - refer to the tutorial link in Suggested reading section.