Lecture 2: Divide and Conquer
Background Material
- Recursive Programs
- Iterative constructs (for, while)
- Geometric and Arithmetic Series
- logarithm
Reading
- Chapter 2 (sec. 2.2, 2.5, 2.8, 2.9) of the text.
- Chapter 3 (sec. 3.1-3.4,3.10,3.11) of the text. This material
will be covered in greater detail next lecture.
Topics
- Reasoning about programs (correctness)
- Proving properties of iterative programs (loop invariants)
- computing powers
- gcd
- insertion sort
- Proving properties of recursive programs
- computing powers
- gcd
- insertion sort
- Reasoning about programs (cost)
- Analyzing the running time of a program
- Big-Oh and approximate running time
- Sums and loops
- computing powers
- gcd
- insertion sort
- Recurrence relations and recursion
- computing powers
- gcd
- insertion sort
- Divide and Conquer
- Divide and conquer recurrence
- Merge Sort
- Karatsuba's algorithm for integer product
Lecture Notes
Programs
- sort.cpp - insertion sort and merge sort
- power.cpp - 4 functions (recursive
and iterative) to compute powers
- gcd.cpp - Euclidean algorithm
- minmax.cpp - recursive function to
simultaneously compute the minimum and maximum elements of a vector.
Resources
Assignments
Created: Oct. 4, 2004 (revised Oct. 6, 2004) by jjohnson@cs.drexel.edu