Divide-Conquer-Glue Algorithms
Mergesort and Counting Inversions Tyler Moore
CSE 3353, SMU, Dallas, TX
Lecture 10
Some slides created by or adapted from Dr. Kevin Wayne. For more information see http://www.cs.princeton.edu/~wayne/kleinberg-tardos. Some code reused or adapted from Python Algorithms by Magnus Lie Hetland.
2
- Divide-and-conquer.
Divide up problem into several subproblems. Solve each subproblem recursively. Combine solutions to subproblems into overall solution.
Most common usage.
Divide problem of size into two subproblems of size in linear time. Solve two subproblems recursively. Combine two solutions into overall solution in linear time.
Consequence.
Brute force: Θ. Divide-and-conquer: Θ.
- 2 / 22
- 5. DIVIDE AND CONQUER
- mergesort
- counting inversions
- closest pair of points
- randomized quicksort
- median and selection
3 / 22
- Problem. Given a list of elements from a totally-ordered universe,
rearrange them in ascending order.
4
- 4 / 22