Decrease and Conquer
- Decrease the problem instance to smaller instances of the same problem.
- Conquer the problem by solving these smaller instances.
- Extend the solution of smaller instances to obtain a solution to the original problem.
- Exploit the relationship between a solution to a given instance of a problem, and a solution to its smaller instance.
- 3 types:
- Decrease by constant
- Decrease by constant factor
- Variable size decrease
- Can be implemented either top-down or bottom-up.

Insertion Sort
Algorithm InsertionSort(A[0..n-1])
// sorts a given array by insertion sort
for i <- 1 to n-1 do:
v <- A[i]
j <- i-1
while j >= 0 and A[j] > v do:
A[j+1] <- A[j]
j <- j-1
A[j+1] <- v
Topological Sorting
- DAG → Directed Acyclic Graph
- Topological sorting arranges the vertices of a directed graph in a linear order such that for any edge (u, v) in the graph, vertex 'u' comes before vertex 'v' in the ordering. It's a way to order tasks or events where some tasks depend on others, ensuring that you always perform a task before any task that depends on it.
- A digraph has topological sorting iff it is a DAG.
- There are two algorithms:
- DFS
- Perform DFS traversal, noting the order in which the vertices are popped off the traversal stack.
- Print the stack in reverse order.
- Source-Removal
- Repeatedely identify and remove a source (vertex without incoming edges), and all the edges incident to it.
- Repeat until no vertex is left, or there is no source among the remaining vertices.