Where each thing comes from

Each header and each test cites the section, the example or the exercise of the book that it implements, and the tests are listed with their source in test/tests.txt; the solutions of the exercises are in the tests, one function per exercise. Each one is checked on the example of the book, on its edge cases and (where an enumeration is possible) on random instances against the enumeration. Since the license of the book does not allow its text in a repository under the LGPL, the code cites it instead of reproducing it.

Chapter

Section

What

Header

Tests

1

1.2

minimum, binary search

search/Minimum.h, search/BinarySearch.h

ch01.sec1.2.*

1.4

multiplication of Ahmes

numeric/BinaryInteger.h

ch01.sec1.4.ahmes

2

2.6

sum and products of binary integers, Karatsuba

numeric/BinaryInteger.h

ch02.sec2.6.*

2.7

Selection, Insertion, Merge, Counting Sort, lower bound

sort/

ch02.sec2.7.*

2.9

solutions of the recurrences (Teoremi 2.2–2.5)

algorithm/MasterTheorem.h

ch02.sec2.9.recurrences

3

3.2

SEQUENCE, SET, DICTIONARY

ADT.h

ch03.*

4

4.1

LIST, bidirectional circular with sentinel

sequence/List.h

ch04.spec.List

4.2

sequence on a vector that doubles

sequence/ArraySequence.h

ch04.spec.ArraySequence, ch04.sec4.2.doubling

4.2.1

binary counter, amortized analysis

algorithm/BinaryCounter.h

ch04.sec4.2.1.counter

4.3

STACK, QUEUE

ADT.h

4.3.1

stack simulated with a sequence

stack/SequenceStack.h

ch04.sec4.3.1.stack-on-list

4.3.2

stack on a vector

stack/ArrayStack.h

ch04.spec.ArrayStack

4.3.3

queue on a circular vector

queue/ArrayQueue.h

ch04.spec.ArrayQueue

4.4

towers of Hanoi, recursive and iterative

algorithm/Hanoi.h

ch04.sec4.4.hanoi

4.6

exercises 4.1–4.11; the singly linked list of 4.6 and the linked queue of 4.10

test/ch04.cpp, sequence/SinglyList.h, queue/LinkedQueue.h

ch04.ex4.*

5

5.1, 5.3

ordered TREE, parent/first child/sibling

tree/Tree.h

ch05.spec.Tree

5.2

previsit, postvisit, invisit, by levels

tree/Tree.h

ch05.sec5.2.visits

5.4

vector of parents

tree/ParentTree.h

ch05.sec5.4.parents

5.5

binary TREE and its visits, ordered tree as binary

tree/BinaryTree.h

ch05.spec.BinaryTree, ch05.sec5.5.*

5.6

complete d-ary tree in a vector

tree/BinaryTree.h

ch05.sec5.6.dary

5.8

exercises 5.1–5.13

test/ch05.cpp

ch05.ex5.*

6

6.1

binary search tree (ABR), DICTIONARY

tree/SearchTree.h

ch06.sec6.1.*

6.2

Red-Black tree, Teoremi 6.1–6.3

tree/SearchTree.h

ch06.spec.RedBlackTree, ch06.sec6.2.*

6.3

B+-tree, insertion, search, interval

tree/BPlusTree.h

ch06.sec6.3.*

6.4

exercises 6.1–6.10

test/ch06.cpp

ch06.ex6.*

7

7

table with direct access

dictionary/DirectTable.h

ch07.sec7.direct-access

7.1

extraction, XOR, division, multiplication, middle square

dictionary/HashFunctions.h

ch07.sec7.1.*

7.2

lists of overflow, open addressing, deleted places

dictionary/ChainedHashTable.h, dictionary/OpenHashTable.h

ch07.sec7.2.*

7.3

I(α) and S(α) measured against the formulas

dictionary/OpenHashTable.h

ch07.sec7.3.complexity

7.4

restructuring, amortized cost

dictionary/TableSize.h

ch07.sec7.4.restructure

–

exercises 7.1–7.10

test/ch07.cpp

ch07.ex7.*

8

8.1

SET on a boolean vector

set/BoolSet.h

ch08.sec8.1.boolean

8.2

SET on an unsorted list

set/ListSet.h

ch08.sec8.2.unsorted-list

8.3

SET on a sorted list, operations by merging

set/SortedListSet.h

ch08.sec8.3.sorted-list

8.4

SET on hash tables

set/DictionarySet.h, set/SetOperations.h

ch08.sec8.4.hash

8.5

SET on Red-Black trees

set/DictionarySet.h

ch08.sec8.5.tree

8.7

exercises 8.1–8.10, LinkedHashSet, multiset

set/LinkedHashSet.h, set/HashMultiset.h, test/ch08.cpp

ch08.ex8.*

9

9.1

definitions, the case of the duke McPollock

test/ch09.cpp

ch09.sec9.1.*

9.2, 9.4

GRAPH, lists and vectors of adjacency

graph/Graph.h, graph/ListGraph.h, graph/ArrayGraph.h

ch09.spec.ListGraph, ch09.sec9.3.matrices

9.3

adjacency matrix, incidence matrix

graph/MatrixGraph.h

ch09.spec.MatrixGraph, ch09.sec9.3.matrices

9.5

bfs, distances, dfs, components, dfs schema, cycles, topological order, strong components

graph/Visit.h

ch09.sec9.5.*

9.7

exercises 9.1–9.11

test/ch09.cpp

ch09.ex9.*

10

10.1

PRIORITYQUEUE on a d-ary heap, on lists, on a Red-Black tree

priority/

ch10.spec.*PriorityQueue, ch10.sec10.1.3.heap

10.1.4

heapBuild(), heapsort()

sort/Heapsort.h

ch10.sec10.1.4.heapsort

10.2

MFSET on a forest (rank, compression of the paths) and on lists, incremental components

mfset/

ch10.sec10.2.*

10.4

exercises 10.1–10.9

test/ch10.cpp

ch10.ex10.*

11

11.1–11.2

shortest paths, theorem of Bellman, the prototype

graph/ShortestPaths.h

ch11.sec11.1.bellman, ch11.sec11.2.prototype

11.3–11.5

Dijkstra, Johnson, Fredman-Tarjan on a Fibonacci heap

graph/ShortestPaths.h, priority/FibonacciHeapPriorityQueue.h

ch11.sec11.3.dijkstra, ch11.sec11.5.fibonacci

11.6–11.8

Bellman-Ford-Moore, the stack, Pape-D’Esopo on a dequeue

graph/ShortestPaths.h, queue/Dequeue.h

ch11.sec11.6.*, ch11.sec11.7.stack, ch11.sec11.8.pape

11.10

exercises 11.1–11.10

test/ch11.cpp

ch11.ex11.*

12

12.1

search by interpolation

search/InterpolationSearch.h

ch12.sec12.1.interpolation

12.2

Quicksort, its improvements, on lists

sort/QuickSort.h

ch12.sec12.2.*

12.3

products of polynomials, Karatsuba

numeric/Polynomial.h

ch12.sec12.3.polynomials

12.4

Strassen

numeric/Matrix.h

ch12.sec12.4.strassen

12.6

exercises 12.1–12.13

test/ch12.cpp

ch12.ex12.*

13

13

binomial coefficients, Fibonacci

numeric/Combinatorics.h

ch13.sec13.binomial, ch13.sec13.4.fibonacci

13.1

approximate string matching, edit distance

string/ApproximateMatching.h

ch13.sec13.1.matching

13.2

weighted independent intervals

optimization/WeightedIntervals.h

ch13.sec13.2.intervals

13.3

chain of matrices

numeric/MatrixChain.h

ch13.sec13.3.matrix-chain

13.5

Floyd-Warshall, insertion of an edge

graph/AllPairsShortestPaths.h

ch13.sec13.5.floyd-warshall

13.6

knapsack, by a table and by memoization

optimization/Knapsack.h

ch13.sec13.6.knapsack

13.7

LCS, diff, longest common substring, alignments

string/

ch13.sec13.7.lcs

13.8

exercises 13.1–13.13

test/ch13.cpp, algorithm/Subsequences.h

ch13.ex13.*

14

14

change with coins

optimization/CoinChange.h

ch14.sec14.change

14.1

real knapsack

optimization/FractionalKnapsack.h

ch14.sec14.1.real-knapsack

14.2

independent set of intervals, coloring, towers

optimization/Intervals.h

ch14.sec14.2.intervals

14.3

Kruskal and Prim, Teorema 14.1

graph/MinimumSpanningTree.h

ch14.sec14.3.*

14.4

code of Huffman

string/Huffman.h

ch14.sec14.4.huffman

14.5

exercises 14.1–14.10, Shortest Job First

test/ch14.cpp, optimization/ShortestJobFirst.h

ch14.ex14.*

15

15

local search of the minimum spanning tree

test/ch15.cpp

ch15.sec15.local-search

15.1

Shell Sort, four sequences of gaps

sort/ShellSort.h

ch15.sec15.1.*

15.2

maximum flow (Ford-Fulkerson, Edmonds-Karp, Dinic), minimum cut, circulations

graph/MaxFlow.h

ch15.sec15.2.max-flow

15.4

exercises 15.1–15.10, Eulerian cycle

test/ch15.cpp, graph/EulerianCycle.h

ch15.ex15.*

16

16.1

convex hull, O(n³) and Graham

geometry/ConvexHull.h

ch16.sec16.1.*

16.2

enumeration: subsets, permutations, derangements, subset sum

backtrack/Enumeration.h

ch16.sec16.2.subsets

16.3

Sudoku

backtrack/Sudoku.h

ch16.sec16.3.sudoku

16.4

exercises 16.1–16.8, n queens, tour of the knight, anagrams

backtrack/, test/ch16.cpp

ch16.ex16.*

17

17

Monte Carlo: null polynomial, Freivalds, half-satisfiability

algorithm/MonteCarlo.h

ch17.sec17.monte-carlo, ch17.ex17.4, ch17.ex17.5

17.1

selection of Hoare, median of medians

search/Selection.h

ch17.sec17.1.selection

17.2

Euclid, powers, Miller-Rabin, primality on 64 bits

numeric/NumberTheory.h

ch17.sec17.2.primality, ch17.ex17.1–ex17.3

17.3

RSA

numeric/RSA.h

ch17.sec17.3.rsa

18

18

the problems in NP, certificates and enumerations

complexity/Problems.h, complexity/Domino.h

ch18.sec18.examples

18.2–18.3

nondeterminism simulated by enumeration

complexity/Nondeterminism.h

ch18.sec18.2.nondeterminism

18.5–18.7

reductions, linear tiling in P, Teoremi 18.2–18.9

complexity/Reductions.h

ch18.sec18.5.*, ch18.sec18.7.*

18.9

exercises 18.1–18.16

test/ch18.cpp

ch18.ex18.*

19

19.1

pseudopolynomial algorithms, scheduling

intractable/Pseudopolynomial.h

ch19.sec19.1.subset-sum

19.2

approximation: ff, ffd, triangular salesman, apSubsetSum

intractable/Approximation.h

ch19.sec19.2.*

19.3

branch-&-bound: bbTsp, 1-tree, Little, clique, knapsack

intractable/BranchAndBound.h

ch19.sec19.3.bb-tsp

19.4

heuristics: greedyTsp, min-max-greedy, local search

intractable/Heuristics.h

ch19.sec19.4.*

19.5

the fifteen puzzle

intractable/FifteenPuzzle.h

ch19.sec19.5.fifteen

19.6

exercises 19.1–19.19

test/ch19.cpp

ch19.ex19.*

Conclusione

Tab. 19.1

easy twins of NP-hard problems, interval graphs

complexity/EasyCases.h

conclusion.*