🖨️ Printing Instructions: Press Ctrl/Cmd + P and select "Save as PDF".
1

Divide & Conquer and Recurrences

2

Learning Goals

3

The Divide & Conquer Paradigm

4

🎬 See It First: Merge Sort

5

Strategy

6

Example: Merge Sort

7

Merge Sort Algorithm

MergeSort(A, p, r)
  if p < r
    q = floor((p+r)/2)
    MergeSort(A, p, q)
    MergeSort(A, q+1, r)
    Merge(A, p, q, r)
8

Analysis of Merge Sort

9

Solving Recurrences

10

What is a Recurrence?

11

Three Methods

12

Method 1: Recursion Tree

13

🎬 Try It First: Build a Recursion Tree

14

Visualizing Merge Sort

15

Tree Height

16

Total Cost

17

Example 2: Bad Split

18

Method 2: Substitution

19

🎬 See It First: Substitution Proof

20

Steps

21

Substitution Proof

22

Substitution Proof (Continued)

23

Method 3: The Master Theorem

24

🎬 See Why It Works

25

Standard Form

26

Compare f(n) vs Watersheld

27

Case 1: Leaves Win

28

Case 2: Tie

29

Case 3: Root Wins

30

Master Theorem Examples

31

Ex 1: Merge Sort

32

Ex 2: Binary Search

33

Ex 3: Matrix Multiplication (Strassen)

34

Ex 4: Root Heavy

35

When Master Theorem Fail

36

Gaps

37

Other Examples

38

Maximum Subarray Problem

39

Integer Multiplication (Karatsuba)

40

Practice Problems

41

Practice 1

42

Practice 2

43

Practice 3

44

Common Pitfalls & Anti-Patterns

45

Watch Out For...

46

Interactive Practice

47

Activity 1: Merge Sort Recurrence

48

Solution 1

49

Activity 2: Binary Search Recurrence

50

Solution 2

51

Activity 3: Bad Split

52

Solution 3

53

Activity 4: Ternary Search

54

Solution 4

55

Activity 5: Max Element D&C

56

Solution 5

57

Activity 6: Stooge Sort

58

Solution 6

59

Interactive: Merge Sort

60

Interactive: Master Theorem

61

Interactive: Recursion Tree

62

Interactive: Substitution Method

63

All Interactive Demos

64

Supplementary Resources