Divide and Conquer
They break the problem into several subproblems that are similar to the original problem but smaller in size, solve the subproblems recursively, and then combine these solutions to create a solution to the original problem.
Recursion Tree
In a recursion tree, each node represents the cost of a single subproblem somewhere in the set of recursive function invocations. We sum the costs within each level of the tree to obtain a set of per-level costs, and we sum all the per-level costs to determine the total cost of all levels of the recursion.
The master theorem
Let be the constants, let be a function, and let be defined on the nonnegative integers by the recurrence
where we interpret n/b to mean either . Then has the following asymptotic bounds:
- If for some constant , then .
- If , then .
- If for some constant , and if for some constant and all sufficiently large n, then .
In terms of the recursion tree, the three cases of the master theorem correspond to cases in which the total cost of the tree is (1) dominated by the costs in the leaves, (2) evenly distributed among the levels of the tree, or (3) dominated by the cost of the root.
Breadth-first search
Given a graph G=(V,E) and distinguished source vertex s, breadth-first search systematically explores the edges of G to "discover" every vertex that is reachable from s. It computes the distance (smallest number of edges) from s to each reachable vertex. It also produces a "breadth-first tree" with root s that contains all reachable vertices. For any vertex v reachable from s, the simple path in the breadth-first tree from s to v corresponds to a "shortest path" from s to v in G, that is, a path containing the smallest number of edges. The algorithm works on both directed and undirected graphs.
Depth-first search
Depth-first search explores edges out of the most recently discovered vertex v that still has unexplored edges leaving it. Once all of v's edges have been explored, the search "backtracks" to explore edges leaving the vertex from which v was discovered.
Shortest-path distance
Define from s to v as the minimum number of edges in any path from vertex s to vertex v; if there is no path from s to v, then . We call a path of length from s to v ashortest path from s to v.