61A Lecture 23 Friday, October 19 Trees with Internal Node Values - - PowerPoint PPT Presentation

61a lecture 23
SMART_READER_LITE
LIVE PREVIEW

61A Lecture 23 Friday, October 19 Trees with Internal Node Values - - PowerPoint PPT Presentation

Last day of Midterm 2 Material 61A Lecture 23 Friday, October 19 Trees with Internal Node Values 2 Trees with Internal Node Values Trees can have values at their roots as well as their leaves. 2 Trees with Internal Node Values Trees can


slide-1
SLIDE 1

61A Lecture 23

Friday, October 19

Last day

  • f Midterm

2 Material

slide-2
SLIDE 2

Trees with Internal Node Values

2

slide-3
SLIDE 3

Trees with Internal Node Values

Trees can have values at their roots as well as their leaves.

2

slide-4
SLIDE 4

Trees with Internal Node Values

Trees can have values at their roots as well as their leaves.

2

fib(6) fib(4) fib(2) 1 fib(5) fib(3) fib(1) fib(2) 1 fib(3) fib(1) fib(2) 1 fib(4) fib(2) 1 fib(3) fib(1) fib(2) 1

slide-5
SLIDE 5

Trees with Internal Node Values (Entries)

Trees need not only have values at their leaves.

3

A valid tree cannot be a subtree of itself (no cycles!)

slide-6
SLIDE 6

Trees with Internal Node Values (Entries)

Trees need not only have values at their leaves.

3

class Tree(object): A valid tree cannot be a subtree of itself (no cycles!)

slide-7
SLIDE 7

Trees with Internal Node Values (Entries)

Trees need not only have values at their leaves.

3

class Tree(object): def __init__(self, entry, left=None, right=None): A valid tree cannot be a subtree of itself (no cycles!)

slide-8
SLIDE 8

Trees with Internal Node Values (Entries)

Trees need not only have values at their leaves.

3

class Tree(object): def __init__(self, entry, left=None, right=None): self.entry = entry A valid tree cannot be a subtree of itself (no cycles!)

slide-9
SLIDE 9

Trees with Internal Node Values (Entries)

Trees need not only have values at their leaves.

3

class Tree(object): def __init__(self, entry, left=None, right=None): self.entry = entry self.left = left A valid tree cannot be a subtree of itself (no cycles!)

slide-10
SLIDE 10

Trees with Internal Node Values (Entries)

Trees need not only have values at their leaves.

3

class Tree(object): def __init__(self, entry, left=None, right=None): self.entry = entry self.left = left self.right = right A valid tree cannot be a subtree of itself (no cycles!)

slide-11
SLIDE 11

Trees with Internal Node Values (Entries)

Trees need not only have values at their leaves.

3

class Tree(object): def __init__(self, entry, left=None, right=None): self.entry = entry self.left = left self.right = right Valid if left and right are each either None or a Tree instance A valid tree cannot be a subtree of itself (no cycles!)

slide-12
SLIDE 12

Trees with Internal Node Values (Entries)

Trees need not only have values at their leaves.

3

class Tree(object): def __init__(self, entry, left=None, right=None): self.entry = entry self.left = left self.right = right def fib_tree(n): Valid if left and right are each either None or a Tree instance A valid tree cannot be a subtree of itself (no cycles!)

slide-13
SLIDE 13

Trees with Internal Node Values (Entries)

Trees need not only have values at their leaves.

3

class Tree(object): def __init__(self, entry, left=None, right=None): self.entry = entry self.left = left self.right = right def fib_tree(n): if n == 1: Valid if left and right are each either None or a Tree instance A valid tree cannot be a subtree of itself (no cycles!)

slide-14
SLIDE 14

Trees with Internal Node Values (Entries)

Trees need not only have values at their leaves.

3

class Tree(object): def __init__(self, entry, left=None, right=None): self.entry = entry self.left = left self.right = right def fib_tree(n): if n == 1: return Tree(0) Valid if left and right are each either None or a Tree instance A valid tree cannot be a subtree of itself (no cycles!)

slide-15
SLIDE 15

Trees with Internal Node Values (Entries)

Trees need not only have values at their leaves.

3

class Tree(object): def __init__(self, entry, left=None, right=None): self.entry = entry self.left = left self.right = right def fib_tree(n): if n == 1: return Tree(0) if n == 2: Valid if left and right are each either None or a Tree instance A valid tree cannot be a subtree of itself (no cycles!)

slide-16
SLIDE 16

Trees with Internal Node Values (Entries)

Trees need not only have values at their leaves.

3

class Tree(object): def __init__(self, entry, left=None, right=None): self.entry = entry self.left = left self.right = right def fib_tree(n): if n == 1: return Tree(0) if n == 2: return Tree(1) Valid if left and right are each either None or a Tree instance A valid tree cannot be a subtree of itself (no cycles!)

slide-17
SLIDE 17

Trees with Internal Node Values (Entries)

Trees need not only have values at their leaves.

3

class Tree(object): def __init__(self, entry, left=None, right=None): self.entry = entry self.left = left self.right = right def fib_tree(n): if n == 1: return Tree(0) if n == 2: return Tree(1) left = fib_tree(n-2) Valid if left and right are each either None or a Tree instance A valid tree cannot be a subtree of itself (no cycles!)

slide-18
SLIDE 18

Trees with Internal Node Values (Entries)

Trees need not only have values at their leaves.

3

class Tree(object): def __init__(self, entry, left=None, right=None): self.entry = entry self.left = left self.right = right def fib_tree(n): if n == 1: return Tree(0) if n == 2: return Tree(1) left = fib_tree(n-2) right = fib_tree(n-1) Valid if left and right are each either None or a Tree instance A valid tree cannot be a subtree of itself (no cycles!)

slide-19
SLIDE 19

Trees with Internal Node Values (Entries)

Trees need not only have values at their leaves.

3

class Tree(object): def __init__(self, entry, left=None, right=None): self.entry = entry self.left = left self.right = right def fib_tree(n): if n == 1: return Tree(0) if n == 2: return Tree(1) left = fib_tree(n-2) right = fib_tree(n-1) return Tree(left.entry + right.entry, left, right) Valid if left and right are each either None or a Tree instance A valid tree cannot be a subtree of itself (no cycles!)

slide-20
SLIDE 20

Trees with Internal Node Values (Entries)

Trees need not only have values at their leaves.

3

class Tree(object): def __init__(self, entry, left=None, right=None): self.entry = entry self.left = left self.right = right def fib_tree(n): if n == 1: return Tree(0) if n == 2: return Tree(1) left = fib_tree(n-2) right = fib_tree(n-1) return Tree(left.entry + right.entry, left, right) Demo Valid if left and right are each either None or a Tree instance A valid tree cannot be a subtree of itself (no cycles!)

slide-21
SLIDE 21

The Consumption of Time

Implementations of the same functional abstraction can require different amounts of time to compute their result.

4

slide-22
SLIDE 22

The Consumption of Time

Implementations of the same functional abstraction can require different amounts of time to compute their result.

4

def count_factors(n):

slide-23
SLIDE 23

The Consumption of Time

Implementations of the same functional abstraction can require different amounts of time to compute their result.

4

def count_factors(n):

(Demo)

slide-24
SLIDE 24

The Consumption of Time

Implementations of the same functional abstraction can require different amounts of time to compute their result.

4

Time (remainders)

def count_factors(n):

(Demo)

slide-25
SLIDE 25

The Consumption of Time

Implementations of the same functional abstraction can require different amounts of time to compute their result.

4

Time (remainders)

def count_factors(n): factors = 0 for k in range(1, n+1): if n % k == 0: factors += 1 return factors

(Demo)

slide-26
SLIDE 26

n

The Consumption of Time

Implementations of the same functional abstraction can require different amounts of time to compute their result.

4

Time (remainders)

def count_factors(n): factors = 0 for k in range(1, n+1): if n % k == 0: factors += 1 return factors

(Demo)

slide-27
SLIDE 27

n

The Consumption of Time

Implementations of the same functional abstraction can require different amounts of time to compute their result.

4

Time (remainders)

def count_factors(n): factors = 0 for k in range(1, n+1): if n % k == 0: factors += 1 return factors

(Demo)

slide-28
SLIDE 28

n

The Consumption of Time

Implementations of the same functional abstraction can require different amounts of time to compute their result.

4

Time (remainders)

def count_factors(n): factors = 0 for k in range(1, n+1): if n % k == 0: factors += 1 return factors sqrt_n = sqrt(n) k, factors = 1, 0 while k < sqrt_n: if n % k == 0: factors += 2 k += 1 if k * k == n: factors += 1 return factors

(Demo)

slide-29
SLIDE 29

n

bpnc

The Consumption of Time

Implementations of the same functional abstraction can require different amounts of time to compute their result.

4

Time (remainders)

def count_factors(n): factors = 0 for k in range(1, n+1): if n % k == 0: factors += 1 return factors sqrt_n = sqrt(n) k, factors = 1, 0 while k < sqrt_n: if n % k == 0: factors += 2 k += 1 if k * k == n: factors += 1 return factors

(Demo)

slide-30
SLIDE 30

The Consumption of Space

5

slide-31
SLIDE 31

The Consumption of Space

Which environment frames do we need to keep during evaluation?

5

slide-32
SLIDE 32

The Consumption of Space

Which environment frames do we need to keep during evaluation? Each step of evaluation has a set of active environments.

5

slide-33
SLIDE 33

The Consumption of Space

Which environment frames do we need to keep during evaluation? Each step of evaluation has a set of active environments. Values and frames in active environments consume memory.

5

slide-34
SLIDE 34

The Consumption of Space

Which environment frames do we need to keep during evaluation? Each step of evaluation has a set of active environments. Values and frames in active environments consume memory. Memory used for other values and frames can be reclaimed.

5

slide-35
SLIDE 35

The Consumption of Space

Which environment frames do we need to keep during evaluation? Each step of evaluation has a set of active environments. Values and frames in active environments consume memory. Memory used for other values and frames can be reclaimed.

5

Active environments:

slide-36
SLIDE 36

The Consumption of Space

Which environment frames do we need to keep during evaluation? Each step of evaluation has a set of active environments. Values and frames in active environments consume memory. Memory used for other values and frames can be reclaimed.

5

Active environments:

  • Environments for any statements currently being executed
slide-37
SLIDE 37

The Consumption of Space

Which environment frames do we need to keep during evaluation? Each step of evaluation has a set of active environments. Values and frames in active environments consume memory. Memory used for other values and frames can be reclaimed.

5

Active environments:

  • Environments for any statements currently being executed
  • Parent environments of functions named in active environments
slide-38
SLIDE 38

Fibonacci Memory Consumption

6

fib(6) fib(5) fib(3) fib(2) 1 fib(4) fib(2) 1 fib(3) fib(1) fib(2) 1 fib(1) fib(4) fib(2) 1 fib(3) fib(1) fib(2) 1

slide-39
SLIDE 39

Fibonacci Memory Consumption

6

fib(6) fib(5) fib(3) fib(2) 1 fib(4) fib(2) 1 fib(3) fib(1) fib(2) 1 fib(1) fib(4) fib(2) 1 fib(3) fib(1) fib(2) 1 Assume we have reached this step

slide-40
SLIDE 40

Fibonacci Memory Consumption

7

fib(6) fib(5) fib(3) fib(2) 1 fib(4) fib(2) 1 fib(3) fib(1) fib(2) 1 fib(1) fib(4) fib(2) 1 fib(3) fib(1) fib(2) 1 Assume we have reached this step

slide-41
SLIDE 41

Fibonacci Memory Consumption

7

fib(6) fib(5) fib(3) fib(2) 1 fib(4) fib(2) 1 fib(3) fib(1) fib(2) 1 fib(1) fib(4) fib(2) 1 fib(3) fib(1) fib(2) 1 Assume we have reached this step Has an active environment

slide-42
SLIDE 42

Fibonacci Memory Consumption

7

fib(6) fib(5) fib(3) fib(2) 1 fib(4) fib(2) 1 fib(3) fib(1) fib(2) 1 fib(1) fib(4) fib(2) 1 fib(3) fib(1) fib(2) 1 Assume we have reached this step Has an active environment Can be reclaimed

slide-43
SLIDE 43

Fibonacci Memory Consumption

7

fib(6) fib(5) fib(3) fib(2) 1 fib(4) fib(2) 1 fib(3) fib(1) fib(2) 1 fib(1) fib(4) fib(2) 1 fib(3) fib(1) fib(2) 1 Assume we have reached this step Has an active environment Can be reclaimed Hasn't yet been created

slide-44
SLIDE 44

Order of Growth

8

slide-45
SLIDE 45

Order of Growth

A method for bounding the resources used by a function as the "size" of a problem increases

8

slide-46
SLIDE 46

Order of Growth

A method for bounding the resources used by a function as the "size" of a problem increases

8

n: size of the problem

slide-47
SLIDE 47

Order of Growth

A method for bounding the resources used by a function as the "size" of a problem increases

8

n: size of the problem R(n): Measurement of some resource used (time or space)

slide-48
SLIDE 48

R(n) = Θ(f(n))

Order of Growth

A method for bounding the resources used by a function as the "size" of a problem increases

8

n: size of the problem R(n): Measurement of some resource used (time or space)

slide-49
SLIDE 49

R(n) = Θ(f(n))

Order of Growth

A method for bounding the resources used by a function as the "size" of a problem increases

8

n: size of the problem R(n): Measurement of some resource used (time or space) means that there are positive constants k1 and k2 such that

slide-50
SLIDE 50

R(n) = Θ(f(n)) k1 · f(n) ≤ R(n) ≤ k2 · f(n)

Order of Growth

A method for bounding the resources used by a function as the "size" of a problem increases

8

n: size of the problem R(n): Measurement of some resource used (time or space) means that there are positive constants k1 and k2 such that

slide-51
SLIDE 51

R(n) = Θ(f(n)) k1 · f(n) ≤ R(n) ≤ k2 · f(n)

Order of Growth

A method for bounding the resources used by a function as the "size" of a problem increases

8

n: size of the problem R(n): Measurement of some resource used (time or space) means that there are positive constants k1 and k2 such that for sufficiently large values of n.

slide-52
SLIDE 52

Iteration vs Memoized Tree Recursion

Iterative and memoized implementations are not the same.

9

def fib_iter(n): prev, curr = 1, 0 for _ in range(n-1): prev, curr = curr, prev + curr return curr @memo def fib(n): if n == 1: return 0 if n == 2: return 1 return fib(n-2) + fib(n-1) Time Space

slide-53
SLIDE 53

Iteration vs Memoized Tree Recursion

Iterative and memoized implementations are not the same.

9

def fib_iter(n): prev, curr = 1, 0 for _ in range(n-1): prev, curr = curr, prev + curr return curr @memo def fib(n): if n == 1: return 0 if n == 2: return 1 return fib(n-2) + fib(n-1) Time Space

Θ(n)

slide-54
SLIDE 54

Iteration vs Memoized Tree Recursion

Iterative and memoized implementations are not the same.

9

def fib_iter(n): prev, curr = 1, 0 for _ in range(n-1): prev, curr = curr, prev + curr return curr @memo def fib(n): if n == 1: return 0 if n == 2: return 1 return fib(n-2) + fib(n-1) Time Space

Θ(n) Θ(1)

slide-55
SLIDE 55

Iteration vs Memoized Tree Recursion

Iterative and memoized implementations are not the same.

9

def fib_iter(n): prev, curr = 1, 0 for _ in range(n-1): prev, curr = curr, prev + curr return curr @memo def fib(n): if n == 1: return 0 if n == 2: return 1 return fib(n-2) + fib(n-1) Time Space

Θ(n) Θ(n) Θ(1)

slide-56
SLIDE 56

Iteration vs Memoized Tree Recursion

Iterative and memoized implementations are not the same.

9

def fib_iter(n): prev, curr = 1, 0 for _ in range(n-1): prev, curr = curr, prev + curr return curr @memo def fib(n): if n == 1: return 0 if n == 2: return 1 return fib(n-2) + fib(n-1) Time Space

Θ(n) Θ(n) Θ(n) Θ(1)

slide-57
SLIDE 57

The Consumption of Time

Implementations of the same functional abstraction can require different amounts of time.

10

def count_factors(n): factors = 0 for k in range(1, n+1): if n % k == 0: factors += 1 return factors sqrt_n = sqrt(n) k, factors = 1, 0 while k < sqrt_n: if n % k == 0: factors += 2 k += 1 if k * k == n: factors += 1 return factors

Time Space

slide-58
SLIDE 58

The Consumption of Time

Implementations of the same functional abstraction can require different amounts of time.

10

def count_factors(n): factors = 0 for k in range(1, n+1): if n % k == 0: factors += 1 return factors sqrt_n = sqrt(n) k, factors = 1, 0 while k < sqrt_n: if n % k == 0: factors += 2 k += 1 if k * k == n: factors += 1 return factors

Time Space

Θ(n) Θ(1)

slide-59
SLIDE 59

The Consumption of Time

Implementations of the same functional abstraction can require different amounts of time.

10

def count_factors(n): factors = 0 for k in range(1, n+1): if n % k == 0: factors += 1 return factors sqrt_n = sqrt(n) k, factors = 1, 0 while k < sqrt_n: if n % k == 0: factors += 2 k += 1 if k * k == n: factors += 1 return factors

Time Space

Θ(n) Θ(1) Θ(√n) Θ(1)

slide-60
SLIDE 60

Exponentiation

11

slide-61
SLIDE 61

Exponentiation

Goal: one more multiplication lets us double the problem size.

11

slide-62
SLIDE 62

Exponentiation

Goal: one more multiplication lets us double the problem size.

11

def exp(b, n): if n == 0: return 1 return b * exp(b, n-1)

slide-63
SLIDE 63

bn =

  • 1

if n = 0 b · bn−1

  • therwise

Exponentiation

Goal: one more multiplication lets us double the problem size.

11

def exp(b, n): if n == 0: return 1 return b * exp(b, n-1)

slide-64
SLIDE 64

bn =

  • 1

if n = 0 b · bn−1

  • therwise

bn =      1 if n = 0 (b

1 2 n)2

if n is even b · bn−1 if n is odd

Exponentiation

Goal: one more multiplication lets us double the problem size.

11

def exp(b, n): if n == 0: return 1 return b * exp(b, n-1)

slide-65
SLIDE 65

bn =

  • 1

if n = 0 b · bn−1

  • therwise

bn =      1 if n = 0 (b

1 2 n)2

if n is even b · bn−1 if n is odd

Exponentiation

Goal: one more multiplication lets us double the problem size.

11

def exp(b, n): if n == 0: return 1 return b * exp(b, n-1) def square(x): return x*x

slide-66
SLIDE 66

bn =

  • 1

if n = 0 b · bn−1

  • therwise

bn =      1 if n = 0 (b

1 2 n)2

if n is even b · bn−1 if n is odd

Exponentiation

Goal: one more multiplication lets us double the problem size.

11

def exp(b, n): if n == 0: return 1 return b * exp(b, n-1) def square(x): return x*x def fast_exp(b, n):

slide-67
SLIDE 67

bn =

  • 1

if n = 0 b · bn−1

  • therwise

bn =      1 if n = 0 (b

1 2 n)2

if n is even b · bn−1 if n is odd

Exponentiation

Goal: one more multiplication lets us double the problem size.

11

def exp(b, n): if n == 0: return 1 return b * exp(b, n-1) def square(x): return x*x def fast_exp(b, n): if n == 0: return 1

slide-68
SLIDE 68

bn =

  • 1

if n = 0 b · bn−1

  • therwise

bn =      1 if n = 0 (b

1 2 n)2

if n is even b · bn−1 if n is odd

Exponentiation

Goal: one more multiplication lets us double the problem size.

11

def exp(b, n): if n == 0: return 1 return b * exp(b, n-1) def square(x): return x*x def fast_exp(b, n): if n == 0: return 1 if n % 2 == 0: return square(fast_exp(b, n//2))

slide-69
SLIDE 69

bn =

  • 1

if n = 0 b · bn−1

  • therwise

bn =      1 if n = 0 (b

1 2 n)2

if n is even b · bn−1 if n is odd

Exponentiation

Goal: one more multiplication lets us double the problem size.

11

def exp(b, n): if n == 0: return 1 return b * exp(b, n-1) def square(x): return x*x def fast_exp(b, n): if n == 0: return 1 if n % 2 == 0: return square(fast_exp(b, n//2)) else: return b * fast_exp(b, n-1)

slide-70
SLIDE 70

Exponentiation

Goal: one more multiplication lets us double the problem size.

12

def exp(b, n): if n == 0: return 1 return b * exp(b, n-1) def square(x): return x*x def fast_exp(b, n): if n == 0: return 1 if n % 2 == 0: return square(fast_exp(b, n//2)) else: return b * fast_exp(b, n-1) Time Space

slide-71
SLIDE 71

Exponentiation

Goal: one more multiplication lets us double the problem size.

12

def exp(b, n): if n == 0: return 1 return b * exp(b, n-1) def square(x): return x*x def fast_exp(b, n): if n == 0: return 1 if n % 2 == 0: return square(fast_exp(b, n//2)) else: return b * fast_exp(b, n-1) Time Space

Θ(n) Θ(n)

slide-72
SLIDE 72

Exponentiation

Goal: one more multiplication lets us double the problem size.

12

def exp(b, n): if n == 0: return 1 return b * exp(b, n-1) def square(x): return x*x def fast_exp(b, n): if n == 0: return 1 if n % 2 == 0: return square(fast_exp(b, n//2)) else: return b * fast_exp(b, n-1) Time Space

Θ(n) Θ(n) Θ(log n) Θ(log n)

slide-73
SLIDE 73

Comparing orders of growth (n is the problem size)

13

slide-74
SLIDE 74

Θ(bn)

Comparing orders of growth (n is the problem size)

13

slide-75
SLIDE 75

Θ(bn)

Comparing orders of growth (n is the problem size)

13

Exponential growth! Recursive fib takes

Θ(φn) φ = 1 + √ 5 2 ≈ 1.61828

steps, where

slide-76
SLIDE 76

Θ(bn)

Comparing orders of growth (n is the problem size)

13

Exponential growth! Recursive fib takes

Θ(φn) φ = 1 + √ 5 2 ≈ 1.61828

steps, where Incrementing the problem scales R(n) by a factor.

slide-77
SLIDE 77

Θ(bn) Θ(n2)

Comparing orders of growth (n is the problem size)

13

Exponential growth! Recursive fib takes

Θ(φn) φ = 1 + √ 5 2 ≈ 1.61828

steps, where Incrementing the problem scales R(n) by a factor.

slide-78
SLIDE 78

Θ(bn) Θ(n2)

Comparing orders of growth (n is the problem size)

13

Exponential growth! Recursive fib takes

Θ(φn) φ = 1 + √ 5 2 ≈ 1.61828

steps, where Incrementing the problem scales R(n) by a factor. Quadratic growth. E.g., operations on all pairs.

slide-79
SLIDE 79

Θ(bn) Θ(n2)

Comparing orders of growth (n is the problem size)

13

Exponential growth! Recursive fib takes

Θ(φn) φ = 1 + √ 5 2 ≈ 1.61828

steps, where Incrementing the problem scales R(n) by a factor. Quadratic growth. E.g., operations on all pairs. Incrementing n increases R(n) by the problem size n.

slide-80
SLIDE 80

Θ(bn) Θ(n) Θ(n2)

Comparing orders of growth (n is the problem size)

13

Exponential growth! Recursive fib takes

Θ(φn) φ = 1 + √ 5 2 ≈ 1.61828

steps, where Incrementing the problem scales R(n) by a factor. Quadratic growth. E.g., operations on all pairs. Incrementing n increases R(n) by the problem size n.

slide-81
SLIDE 81

Θ(bn) Θ(n) Θ(n2)

Comparing orders of growth (n is the problem size)

13

Exponential growth! Recursive fib takes

Θ(φn) φ = 1 + √ 5 2 ≈ 1.61828

steps, where Incrementing the problem scales R(n) by a factor. Linear growth. Resources scale with the problem. Quadratic growth. E.g., operations on all pairs. Incrementing n increases R(n) by the problem size n.

slide-82
SLIDE 82

Θ(bn) Θ(n) Θ(log n) Θ(n2)

Comparing orders of growth (n is the problem size)

13

Exponential growth! Recursive fib takes

Θ(φn) φ = 1 + √ 5 2 ≈ 1.61828

steps, where Incrementing the problem scales R(n) by a factor. Linear growth. Resources scale with the problem. Quadratic growth. E.g., operations on all pairs. Incrementing n increases R(n) by the problem size n.

slide-83
SLIDE 83

Θ(bn) Θ(n) Θ(log n) Θ(n2)

Comparing orders of growth (n is the problem size)

13

Exponential growth! Recursive fib takes

Θ(φn) φ = 1 + √ 5 2 ≈ 1.61828

steps, where Incrementing the problem scales R(n) by a factor. Linear growth. Resources scale with the problem. Logarithmic growth. These processes scale well. Quadratic growth. E.g., operations on all pairs. Incrementing n increases R(n) by the problem size n.

slide-84
SLIDE 84

Θ(bn) Θ(n) Θ(log n) Θ(n2)

Comparing orders of growth (n is the problem size)

13

Exponential growth! Recursive fib takes

Θ(φn) φ = 1 + √ 5 2 ≈ 1.61828

steps, where Incrementing the problem scales R(n) by a factor. Linear growth. Resources scale with the problem. Logarithmic growth. These processes scale well. Doubling the problem only increments R(n). Quadratic growth. E.g., operations on all pairs. Incrementing n increases R(n) by the problem size n.

slide-85
SLIDE 85

Θ(bn) Θ(n) Θ(log n) Θ(1) Θ(n2)

Comparing orders of growth (n is the problem size)

13

Exponential growth! Recursive fib takes

Θ(φn) φ = 1 + √ 5 2 ≈ 1.61828

steps, where Incrementing the problem scales R(n) by a factor. Linear growth. Resources scale with the problem. Logarithmic growth. These processes scale well. Doubling the problem only increments R(n). Quadratic growth. E.g., operations on all pairs. Incrementing n increases R(n) by the problem size n.

slide-86
SLIDE 86

Θ(bn) Θ(n) Θ(log n) Θ(1) Θ(n2)

Comparing orders of growth (n is the problem size)

13

Exponential growth! Recursive fib takes

Θ(φn) φ = 1 + √ 5 2 ≈ 1.61828

steps, where Incrementing the problem scales R(n) by a factor. Linear growth. Resources scale with the problem. Logarithmic growth. These processes scale well. Doubling the problem only increments R(n).

  • Constant. The problem size doesn't matter.

Quadratic growth. E.g., operations on all pairs. Incrementing n increases R(n) by the problem size n.

slide-87
SLIDE 87

Θ(bn) Θ(n) Θ(log n) Θ(1) Θ(n2)

Comparing orders of growth (n is the problem size)

13

Exponential growth! Recursive fib takes

Θ(φn) φ = 1 + √ 5 2 ≈ 1.61828

steps, where Incrementing the problem scales R(n) by a factor. Linear growth. Resources scale with the problem. Logarithmic growth. These processes scale well. Doubling the problem only increments R(n).

  • Constant. The problem size doesn't matter.

Quadratic growth. E.g., operations on all pairs. Incrementing n increases R(n) by the problem size n.

slide-88
SLIDE 88

Θ(bn) Θ(n) Θ(log n) Θ(1) Θ(n2)

Comparing orders of growth (n is the problem size)

13

Exponential growth! Recursive fib takes

Θ(φn) φ = 1 + √ 5 2 ≈ 1.61828

steps, where Incrementing the problem scales R(n) by a factor. Linear growth. Resources scale with the problem. Logarithmic growth. These processes scale well. Doubling the problem only increments R(n).

  • Constant. The problem size doesn't matter.

Quadratic growth. E.g., operations on all pairs. Incrementing n increases R(n) by the problem size n.

Θ(n6)

slide-89
SLIDE 89

Θ(bn) Θ(n) Θ(log n) Θ(1) Θ(n2)

Comparing orders of growth (n is the problem size)

13

Exponential growth! Recursive fib takes

Θ(φn) φ = 1 + √ 5 2 ≈ 1.61828

steps, where Incrementing the problem scales R(n) by a factor. Linear growth. Resources scale with the problem. Logarithmic growth. These processes scale well. Doubling the problem only increments R(n).

  • Constant. The problem size doesn't matter.

Quadratic growth. E.g., operations on all pairs. Incrementing n increases R(n) by the problem size n.

Θ(√n) Θ(n6)