Warm up What is 2π
π π=0
CS4102 Algorithms Fall 2020 Warm up 2 What is ? =0 Finite - - PowerPoint PPT Presentation
CS4102 Algorithms Fall 2020 Warm up 2 What is ? =0 Finite Geometric Series =0 If > 1 = The series The next term The series The first term multiplied by in the series 1 + + 2
π π=0
2
The series multiplied by π The series The first term 1 + π + π2 + β― + ππ π 1 + π + π2 + β― + ππ 1 ππ+1 1 The next term in the series
π π=0
3
The series multiplied by π The series The first term
1 + π + π2 + β― + ππ π 1 + π + π2 + β― + ππ 1 ππ+1 1 The next term in the series
π π=0
Solve for the series
9
2
π 2 + π
10
11
12
π π = π
log2 π π=1
= π log2 π
π π 2 π 2 π 4 π 4 π 4 π 4 1 1 1 1 1 1 A call to mergesort Size of the list βnon-recursiveβ work done Recursive Calls Base Cases!
13
14
15
def dc_mult(x, y): n = length of larger of x,y if n == 1: return x*y a = first n/2 digits of x b = last n/2 digits of x c = first n/2 digits of y d = last n/2 digits of y ac = dc_mult(a, c) ad = dc_mult(a, d) bc = dc_mult(b, c) bd = dc_mult(b, d) return ac*10^n + (ad + bc)*10^(n/2) + bd
Divide Conquer Combine
π 2 ππ + ππ + ππ
18
19
20
5π 5π 2 5 5π 2 5π 2
5π 2 5π 4 5π 4 5π 4 5π 4 5π 4 5π 4 5π 4
5π 4 5 5 5 5 5 5 5 5 5 5 5 5 5
log2 π π=0
21
log2 π π=0
22
23
a
b c d
def dc_mult(x, y): n = length of larger of x,y if n == 1: return x*y a = first n/2 digits of x b = last n/2 digits of x c = first n/2 digits of y d = last n/2 digits of y ac = dc_mult(a, c) bd = dc_mult(b, d) adbc = dc_mult(a+b, c+d) β ac β bd return ac*10^n + (adbc)*10^(n/2) + bd
Divide Conquer Combine
25
π 2
a
b c d
π 2
26
27
a
b c d
π 2 ππ + ππ + ππ
28
8π 8π 2 8π 2 8π 2
8π 4 8π 4 8π 4 8π 4 8π 4 8π 4
8 8 8 8 8 8 8 8 8 8
log2 π π=0
29
log2 π π=0
Lots of arithmetic (see pdf)
30
31
32
33
Inductive step must appeal to a base case or to the inductive hypothesis
35
π¦0+1 2
π¦0+1 2
π¦0+1 2
π¦0+1 2
π¦0+1 2
π¦0+1 2
37
x0+1 2
2
π¦0+1 2
π¦0+1 2
π¦0+1 2