SLIDE 1
Composition Announcements Linked Lists Linked List Structure A - - PowerPoint PPT Presentation
Composition Announcements Linked Lists Linked List Structure A - - PowerPoint PPT Presentation
Composition Announcements Linked Lists Linked List Structure A linked list is either empty or a first value and the rest of the linked list 4 Linked List Structure A linked list is either empty or a first value and the rest of the linked list
SLIDE 2
SLIDE 3
Linked Lists
SLIDE 4
Linked List Structure
A linked list is either empty or a first value and the rest of the linked list
4
SLIDE 5
Linked List Structure
A linked list is either empty or a first value and the rest of the linked list
4
3 , 4 , 5
SLIDE 6
Linked List Structure
A linked list is either empty or a first value and the rest of the linked list
4
3 , 4 , 5 first: 3 rest: Link instance
SLIDE 7
Linked List Structure
A linked list is either empty or a first value and the rest of the linked list
4
3 , 4 , 5 first: 3 rest: Link instance first: 4 rest: Link instance
SLIDE 8
Linked List Structure
A linked list is either empty or a first value and the rest of the linked list
4
3 , 4 , 5 first: 3 rest: Link instance first: 4 rest: Link instance first: 5 rest: Link instance
SLIDE 9
Linked List Structure
A linked list is either empty or a first value and the rest of the linked list
4
3 , 4 , 5 Link.empty first: 3 rest: Link instance first: 4 rest: Link instance first: 5 rest: Link instance
SLIDE 10
Linked List Structure
A linked list is either empty or a first value and the rest of the linked list
4
3 , 4 , 5 Link.empty first: 3 rest: Link instance first: 4 rest: Link instance first: 5 rest: Link instance A linked list is a pair
SLIDE 11
Linked List Structure
A linked list is either empty or a first value and the rest of the linked list
4
3 , 4 , 5 Link.empty first: 3 rest: Link instance first: 4 rest: Link instance first: 5 rest: Link instance A linked list is a pair The first (zeroth) element is an attribute value
SLIDE 12
Linked List Structure
A linked list is either empty or a first value and the rest of the linked list
4
3 , 4 , 5 Link.empty first: 3 rest: Link instance first: 4 rest: Link instance first: 5 rest: Link instance A linked list is a pair The first (zeroth) element is an attribute value The rest of the elements are stored in a linked list
SLIDE 13
Linked List Structure
A linked list is either empty or a first value and the rest of the linked list
4
3 , 4 , 5 Link.empty first: 3 rest: Link instance first: 4 rest: Link instance first: 5 rest: Link instance A linked list is a pair The first (zeroth) element is an attribute value The rest of the elements are stored in a linked list A class attribute represents an empty linked list
SLIDE 14
Linked List Structure
A linked list is either empty or a first value and the rest of the linked list
4
3 , 4 , 5 Link.empty first: 3 rest: Link instance first: 4 rest: Link instance first: 5 rest: Link instance Link(3, Link(4, Link(5, Link.empty))) A linked list is a pair The first (zeroth) element is an attribute value The rest of the elements are stored in a linked list A class attribute represents an empty linked list
SLIDE 15
Linked List Structure
A linked list is either empty or a first value and the rest of the linked list
5
3 , 4 , 5 first: 3 rest: Link instance first: 4 rest: Link instance first: 5 rest: Link instance Link.empty , Link.empty ) Link(3, Link(4, Link(5 )))
SLIDE 16
Linked List Structure
A linked list is either empty or a first value and the rest of the linked list
5
3 , 4 , 5 first: 3 rest: Link instance first: 4 rest: Link instance first: 5 rest: Link instance Link.empty , Link.empty ) Link(3, Link(4, Link(5 )))
SLIDE 17
Linked List Structure
A linked list is either empty or a first value and the rest of the linked list
5
3 , 4 , 5 first: 3 rest: Link instance first: 4 rest: Link instance first: 5 rest: Link instance Link.empty , Link.empty ) Link(3, Link(4, Link(5 )))
SLIDE 18
Linked List Structure
A linked list is either empty or a first value and the rest of the linked list
5
3 , 4 , 5 first: 3 rest: Link instance first: 4 rest: Link instance first: 5 rest: Link instance Link.empty , Link.empty ) Link(3, Link(4, Link(5 )))
SLIDE 19
Linked List Structure
A linked list is either empty or a first value and the rest of the linked list
5
3 , 4 , 5 first: 3 rest: Link instance first: 4 rest: Link instance first: 5 rest: Link instance , Link.empty ) Link(3, Link(4, Link(5 )))
SLIDE 20
Linked List Structure
A linked list is either empty or a first value and the rest of the linked list
5
3 , 4 , 5 first: 3 rest: Link instance first: 4 rest: Link instance first: 5 rest: Link instance Link(3, Link(4, Link(5 )))
SLIDE 21
Linked List Class
6
Link(3, Link(4, Link(5 )))
SLIDE 22
Linked List Class
6
Linked list class: attributes are passed to __init__ Link(3, Link(4, Link(5 )))
SLIDE 23
Linked List Class
class Link:
6
Linked list class: attributes are passed to __init__ Link(3, Link(4, Link(5 )))
SLIDE 24
Linked List Class
class Link:
6
Linked list class: attributes are passed to __init__ def __init__(self, first, rest=empty): Link(3, Link(4, Link(5 )))
SLIDE 25
Linked List Class
class Link:
6
Linked list class: attributes are passed to __init__ def __init__(self, first, rest=empty): assert rest is Link.empty or isinstance(rest, Link) Link(3, Link(4, Link(5 )))
SLIDE 26
Linked List Class
class Link:
6
Linked list class: attributes are passed to __init__ def __init__(self, first, rest=empty): assert rest is Link.empty or isinstance(rest, Link) self.first = first self.rest = rest Link(3, Link(4, Link(5 )))
SLIDE 27
Linked List Class
class Link:
6
Linked list class: attributes are passed to __init__ def __init__(self, first, rest=empty): assert rest is Link.empty or isinstance(rest, Link) self.first = first self.rest = rest Link(3, Link(4, Link(5 ))) Returns whether rest is a Link
SLIDE 28
Linked List Class
class Link:
6
Linked list class: attributes are passed to __init__ def __init__(self, first, rest=empty): assert rest is Link.empty or isinstance(rest, Link) self.first = first self.rest = rest Link(3, Link(4, Link(5 ))) Returns whether rest is a Link help(isinstance): Return whether an object is an instance of a class or of a subclass thereof.
SLIDE 29
Linked List Class
class Link: empty = ()
6
Linked list class: attributes are passed to __init__ def __init__(self, first, rest=empty): assert rest is Link.empty or isinstance(rest, Link) self.first = first self.rest = rest Link(3, Link(4, Link(5 ))) Returns whether rest is a Link help(isinstance): Return whether an object is an instance of a class or of a subclass thereof.
SLIDE 30
Linked List Class
class Link: empty = ()
6
Some zero-length sequence Linked list class: attributes are passed to __init__ def __init__(self, first, rest=empty): assert rest is Link.empty or isinstance(rest, Link) self.first = first self.rest = rest Link(3, Link(4, Link(5 ))) Returns whether rest is a Link help(isinstance): Return whether an object is an instance of a class or of a subclass thereof.
SLIDE 31
Linked List Class
class Link: empty = ()
6
Some zero-length sequence Linked list class: attributes are passed to __init__ def __init__(self, first, rest=empty): assert rest is Link.empty or isinstance(rest, Link) self.first = first self.rest = rest (Demo) Link(3, Link(4, Link(5 ))) Returns whether rest is a Link help(isinstance): Return whether an object is an instance of a class or of a subclass thereof.
SLIDE 32
Property Methods
SLIDE 33
Property Methods
In some cases, we want the value of instance attributes to be computed on demand
8
For example, if we want to access the second element of a linked list
SLIDE 34
Property Methods
In some cases, we want the value of instance attributes to be computed on demand >>> s = Link(3, Link(4, Link(5)))
8
For example, if we want to access the second element of a linked list
SLIDE 35
Property Methods
In some cases, we want the value of instance attributes to be computed on demand >>> s = Link(3, Link(4, Link(5))) >>> s.second 4
8
For example, if we want to access the second element of a linked list
SLIDE 36
Property Methods
In some cases, we want the value of instance attributes to be computed on demand >>> s = Link(3, Link(4, Link(5))) >>> s.second 4 >>> s.second = 6
8
For example, if we want to access the second element of a linked list
SLIDE 37
Property Methods
In some cases, we want the value of instance attributes to be computed on demand >>> s = Link(3, Link(4, Link(5))) >>> s.second 4 >>> s.second = 6 >>> s.second 6
8
For example, if we want to access the second element of a linked list
SLIDE 38
Property Methods
In some cases, we want the value of instance attributes to be computed on demand >>> s = Link(3, Link(4, Link(5))) >>> s.second 4 >>> s.second = 6 >>> s.second 6 >>> s Link(3, Link(6, Link(5)))
8
For example, if we want to access the second element of a linked list
SLIDE 39
Property Methods
In some cases, we want the value of instance attributes to be computed on demand >>> s = Link(3, Link(4, Link(5))) >>> s.second 4 >>> s.second = 6 >>> s.second 6 >>> s Link(3, Link(6, Link(5)))
8
No method calls! For example, if we want to access the second element of a linked list
SLIDE 40
Property Methods
In some cases, we want the value of instance attributes to be computed on demand >>> s = Link(3, Link(4, Link(5))) >>> s.second 4 >>> s.second = 6 >>> s.second 6 >>> s Link(3, Link(6, Link(5))) The @property decorator on a method designates that it will be called whenever it is looked up on an instance
8
No method calls! For example, if we want to access the second element of a linked list
SLIDE 41
Property Methods
In some cases, we want the value of instance attributes to be computed on demand >>> s = Link(3, Link(4, Link(5))) >>> s.second 4 >>> s.second = 6 >>> s.second 6 >>> s Link(3, Link(6, Link(5))) The @property decorator on a method designates that it will be called whenever it is looked up on an instance A @<attribute>.setter decorator on a method designates that it will be called whenever that attribute is assigned. <attribute> must be an existing property method.
8
No method calls! For example, if we want to access the second element of a linked list
SLIDE 42
Property Methods
In some cases, we want the value of instance attributes to be computed on demand >>> s = Link(3, Link(4, Link(5))) >>> s.second 4 >>> s.second = 6 >>> s.second 6 >>> s Link(3, Link(6, Link(5))) The @property decorator on a method designates that it will be called whenever it is looked up on an instance (Demo) A @<attribute>.setter decorator on a method designates that it will be called whenever that attribute is assigned. <attribute> must be an existing property method.
8
No method calls! For example, if we want to access the second element of a linked list
SLIDE 43
Tree Class
SLIDE 44
Tree Abstraction (Review)
10
2 3 1 1 1 1 1
SLIDE 45
Tree Abstraction (Review)
10
Recursive description (wooden trees):
2 3 1 1
Relative description (family trees):
1 1 1
SLIDE 46
Tree Abstraction (Review)
10
Recursive description (wooden trees): A tree has a root label and a list of branches
2 3 1 1
Relative description (family trees):
1 1 1
SLIDE 47
Tree Abstraction (Review)
10
Recursive description (wooden trees): A tree has a root label and a list of branches
2 3 1 1
Relative description (family trees):
1 1 1
Root label
SLIDE 48
Tree Abstraction (Review)
10
Recursive description (wooden trees): A tree has a root label and a list of branches
2 3 1 1
Relative description (family trees):
1 1 1
Root label Branch
SLIDE 49
Tree Abstraction (Review)
10
Recursive description (wooden trees): A tree has a root label and a list of branches Each branch is a tree
2 3 1 1
Relative description (family trees):
1 1 1
Root label Branch
SLIDE 50
Tree Abstraction (Review)
10
Recursive description (wooden trees): A tree has a root label and a list of branches Each branch is a tree
2 3 1 1
Relative description (family trees):
1 1 1
Root label Branch (also a tree)
SLIDE 51
Tree Abstraction (Review)
10
Recursive description (wooden trees): A tree has a root label and a list of branches Each branch is a tree A tree with zero branches is called a leaf
2 3 1 1
Relative description (family trees):
1 1 1
Root label Branch (also a tree)
SLIDE 52
Tree Abstraction (Review)
10
Recursive description (wooden trees): A tree has a root label and a list of branches Each branch is a tree A tree with zero branches is called a leaf
2 3 1 1
Relative description (family trees):
1 1 1
Root label Branch (also a tree) Leaf (also a tree)
SLIDE 53
Tree Abstraction (Review)
10
Recursive description (wooden trees): A tree has a root label and a list of branches Each branch is a tree A tree with zero branches is called a leaf A tree starts at the root
2 3 1 1
Relative description (family trees):
1 1 1
Root label Branch (also a tree) Leaf (also a tree)
SLIDE 54
Tree Abstraction (Review)
10
Recursive description (wooden trees): A tree has a root label and a list of branches Each branch is a tree A tree with zero branches is called a leaf A tree starts at the root
2 3 1 1
Relative description (family trees):
1 1 1
Root label Branch (also a tree) Leaf (also a tree) Root of the whole tree
SLIDE 55
Tree Abstraction (Review)
10
Recursive description (wooden trees): A tree has a root label and a list of branches Each branch is a tree A tree with zero branches is called a leaf A tree starts at the root
2 3 1 1
Relative description (family trees):
1 1 1
Root label Branch (also a tree) Leaf (also a tree) Root of the whole tree Root of a branch
SLIDE 56
Tree Abstraction (Review)
10
Recursive description (wooden trees): A tree has a root label and a list of branches Each branch is a tree A tree with zero branches is called a leaf A tree starts at the root
2 3 1 1
Relative description (family trees): Each location in a tree is called a node
1 1 1
Root label Branch (also a tree) Leaf (also a tree) Nodes Root of the whole tree Root of a branch
SLIDE 57
Tree Abstraction (Review)
10
Recursive description (wooden trees): A tree has a root label and a list of branches Each branch is a tree A tree with zero branches is called a leaf A tree starts at the root
2 3 1 1
Relative description (family trees): Each location in a tree is called a node Each node has a label that can be any value
1 1 1
Root label Branch (also a tree) Leaf (also a tree) Nodes Root of the whole tree Root of a branch
SLIDE 58
Tree Abstraction (Review)
10
Recursive description (wooden trees): A tree has a root label and a list of branches Each branch is a tree A tree with zero branches is called a leaf A tree starts at the root
2 3 1 1
Relative description (family trees): Each location in a tree is called a node Each node has a label that can be any value
1 1 1
Root label Branch (also a tree) Leaf (also a tree) Labels Nodes Root of the whole tree Root of a branch
SLIDE 59
Tree Abstraction (Review)
10
Recursive description (wooden trees): A tree has a root label and a list of branches Each branch is a tree A tree with zero branches is called a leaf A tree starts at the root
2 3 1 1
Relative description (family trees): Each location in a tree is called a node Each node has a label that can be any value One node can be the parent/child of another
1 1 1
Root label Branch (also a tree) Leaf (also a tree) Labels Nodes Root of the whole tree Root of a branch
SLIDE 60
Tree Abstraction (Review)
10
Recursive description (wooden trees): A tree has a root label and a list of branches Each branch is a tree A tree with zero branches is called a leaf A tree starts at the root
2 3 1 1
Relative description (family trees): Each location in a tree is called a node Each node has a label that can be any value One node can be the parent/child of another The top node is the root node
1 1 1
Root label Branch (also a tree) Leaf (also a tree) Labels Nodes Root of the whole tree Root of a branch
SLIDE 61
Tree Abstraction (Review)
10
Recursive description (wooden trees): A tree has a root label and a list of branches Each branch is a tree A tree with zero branches is called a leaf A tree starts at the root
2 3 1 1
Relative description (family trees): Each location in a tree is called a node Each node has a label that can be any value One node can be the parent/child of another The top node is the root node
1 1 1
Root label Branch (also a tree) Leaf (also a tree) Labels Nodes Root of the whole tree Root of a branch
- r Root Node
SLIDE 62
Tree Abstraction (Review)
10
Recursive description (wooden trees): A tree has a root label and a list of branches Each branch is a tree A tree with zero branches is called a leaf A tree starts at the root
2 3 1 1
Relative description (family trees): Each location in a tree is called a node Each node has a label that can be any value One node can be the parent/child of another The top node is the root node
1 1 1
Root label Branch (also a tree) Leaf (also a tree) Labels Nodes People often refer to labels by their locations: "each parent is the sum of its children" Root of the whole tree Root of a branch
- r Root Node
SLIDE 63
Tree Abstraction (Review)
10
Recursive description (wooden trees): A tree has a root label and a list of branches Each branch is a tree A tree with zero branches is called a leaf A tree starts at the root
2 3 1 1
Relative description (family trees): Each location in a tree is called a node Each node has a label that can be any value One node can be the parent/child of another The top node is the root node
1 1 1
Root label Branch (also a tree) Leaf (also a tree) Labels Nodes People often refer to labels by their locations: "each parent is the sum of its children" Root of the whole tree Root of a branch Path
- r Root Node
SLIDE 64
Tree Class
11
A Tree has a label and a list of branches; each branch is a Tree
SLIDE 65
Tree Class
class Tree:
11
A Tree has a label and a list of branches; each branch is a Tree
SLIDE 66
Tree Class
class Tree: def __init__(self, label, branches=[]):
11
A Tree has a label and a list of branches; each branch is a Tree
SLIDE 67
Tree Class
class Tree: def __init__(self, label, branches=[]): self.label = label
11
A Tree has a label and a list of branches; each branch is a Tree
SLIDE 68
Tree Class
class Tree: def __init__(self, label, branches=[]): self.label = label for branch in branches: assert isinstance(branch, Tree)
11
A Tree has a label and a list of branches; each branch is a Tree
SLIDE 69
Tree Class
class Tree: def __init__(self, label, branches=[]): self.label = label for branch in branches: assert isinstance(branch, Tree) self.branches = list(branches)
11
A Tree has a label and a list of branches; each branch is a Tree
SLIDE 70
Tree Class
class Tree: def __init__(self, label, branches=[]): self.label = label for branch in branches: assert isinstance(branch, Tree) self.branches = list(branches)
11
A Tree has a label and a list of branches; each branch is a Tree for branch in branches: assert is_tree(branch) return [label] + list(branches) def label(tree): return tree[0] def branches(tree): return tree[1:] def tree(label, branches=[]):
SLIDE 71
Tree Class
class Tree: def __init__(self, label, branches=[]): self.label = label for branch in branches: assert isinstance(branch, Tree) self.branches = list(branches) def fib_tree(n): if n == 0 or n == 1: return Tree(n) else: left = fib_tree(n-2) right = fib_tree(n-1) fib_n = left.label + right.label return Tree(fib_n, [left, right])
11
A Tree has a label and a list of branches; each branch is a Tree for branch in branches: assert is_tree(branch) return [label] + list(branches) def label(tree): return tree[0] def branches(tree): return tree[1:] def tree(label, branches=[]):
SLIDE 72
Tree Class
class Tree: def __init__(self, label, branches=[]): self.label = label for branch in branches: assert isinstance(branch, Tree) self.branches = list(branches) def fib_tree(n): if n == 0 or n == 1: return Tree(n) else: left = fib_tree(n-2) right = fib_tree(n-1) fib_n = left.label + right.label return Tree(fib_n, [left, right])
11
A Tree has a label and a list of branches; each branch is a Tree for branch in branches: assert is_tree(branch) return [label] + list(branches) def label(tree): return tree[0] def branches(tree): return tree[1:] def tree(label, branches=[]): def fib_tree(n): if n == 0 or n == 1: return tree(n) else: left = fib_tree(n-2) right = fib_tree(n-1) fib_n = label(left) + label(right) return tree(fib_n, [left, right])
SLIDE 73
Tree Class
class Tree: def __init__(self, label, branches=[]): self.label = label for branch in branches: assert isinstance(branch, Tree) self.branches = list(branches) def fib_tree(n): if n == 0 or n == 1: return Tree(n) else: left = fib_tree(n-2) right = fib_tree(n-1) fib_n = left.label + right.label return Tree(fib_n, [left, right]) (Demo)
11
A Tree has a label and a list of branches; each branch is a Tree for branch in branches: assert is_tree(branch) return [label] + list(branches) def label(tree): return tree[0] def branches(tree): return tree[1:] def tree(label, branches=[]): def fib_tree(n): if n == 0 or n == 1: return tree(n) else: left = fib_tree(n-2) right = fib_tree(n-1) fib_n = label(left) + label(right) return tree(fib_n, [left, right])
SLIDE 74
Tree Mutation
SLIDE 75
Example: Pruning Trees
Removing subtrees from a tree is called pruning Prune branches before recursive processing
13
SLIDE 76
Example: Pruning Trees
Removing subtrees from a tree is called pruning Prune branches before recursive processing
13
2 3 1 1 1 1 1
SLIDE 77
Example: Pruning Trees
Removing subtrees from a tree is called pruning Prune branches before recursive processing
13
2 3 1 1 1 1 1
SLIDE 78
Example: Pruning Trees
Removing subtrees from a tree is called pruning Prune branches before recursive processing
13
def prune(t, n): """Prune sub-trees whose label value is n.""" t.branches = [______________ for b in t.branches if _____________________] for b in t.branches: prune(_______________________________, _______________________________)
2 3 1 1 1 1 1
SLIDE 79
Example: Pruning Trees
Removing subtrees from a tree is called pruning Prune branches before recursive processing
13
def prune(t, n): """Prune sub-trees whose label value is n.""" t.branches = [______________ for b in t.branches if _____________________] for b in t.branches: prune(_______________________________, _______________________________)
2 3 1 1 1 1 1
b b.label != n
SLIDE 80
Example: Pruning Trees
Removing subtrees from a tree is called pruning Prune branches before recursive processing
13
def prune(t, n): """Prune sub-trees whose label value is n.""" t.branches = [______________ for b in t.branches if _____________________] for b in t.branches: prune(_______________________________, _______________________________)
2 3 1 1 1 1 1
b b.label != n b n
SLIDE 81
Example: Pruning Trees
Removing subtrees from a tree is called pruning Prune branches before recursive processing
13
def prune(t, n): """Prune sub-trees whose label value is n.""" t.branches = [______________ for b in t.branches if _____________________] for b in t.branches: prune(_______________________________, _______________________________)
2 3 1 1 1 1 1
b b.label != n b n (Demo)
SLIDE 82
Example: Pruning Trees
Removing subtrees from a tree is called pruning Prune branches before recursive processing
14
fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1
SLIDE 83
Example: Pruning Trees
Removing subtrees from a tree is called pruning Prune branches before recursive processing
14
fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 Memoization:
SLIDE 84
Example: Pruning Trees
Removing subtrees from a tree is called pruning Prune branches before recursive processing
14
Returned by fib
fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 Memoization:
SLIDE 85
Example: Pruning Trees
Removing subtrees from a tree is called pruning Prune branches before recursive processing
14
Returned by fib Found in cache
fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 Memoization:
SLIDE 86
Example: Pruning Trees
Removing subtrees from a tree is called pruning Prune branches before recursive processing
14
Returned by fib Found in cache
fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1
Skipped
Memoization:
SLIDE 87
Example: Pruning Trees
Removing subtrees from a tree is called pruning Prune branches before recursive processing
14
Returned by fib Found in cache
fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1
Skipped
Memoization:
SLIDE 88
Example: Pruning Trees
Removing subtrees from a tree is called pruning Prune branches before recursive processing
14
Returned by fib Found in cache
fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1
Skipped
Memoization:
SLIDE 89
Example: Pruning Trees
Removing subtrees from a tree is called pruning Prune branches before recursive processing
14
Returned by fib Found in cache
fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1
Skipped
Memoization:
SLIDE 90
Example: Pruning Trees
Removing subtrees from a tree is called pruning Prune branches before recursive processing
14
Returned by fib Found in cache
fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1
Skipped
Memoization:
SLIDE 91
Example: Pruning Trees
Removing subtrees from a tree is called pruning Prune branches before recursive processing
14
Returned by fib Found in cache
fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1
Skipped
Memoization:
SLIDE 92
Example: Pruning Trees
Removing subtrees from a tree is called pruning Prune branches before recursive processing
14
Returned by fib Found in cache
fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1
Skipped
Memoization:
SLIDE 93
Example: Pruning Trees
Removing subtrees from a tree is called pruning Prune branches before recursive processing
14
Returned by fib Found in cache
fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1
Skipped
Memoization:
SLIDE 94
Example: Pruning Trees
Removing subtrees from a tree is called pruning Prune branches before recursive processing
14
Returned by fib Found in cache
fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1
Skipped
Memoization:
SLIDE 95
Example: Pruning Trees
Removing subtrees from a tree is called pruning Prune branches before recursive processing
14
Returned by fib Found in cache
fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1
Skipped
Memoization:
SLIDE 96
Example: Pruning Trees
Removing subtrees from a tree is called pruning Prune branches before recursive processing
14
Returned by fib Found in cache
fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1
Skipped
Memoization:
SLIDE 97
Example: Pruning Trees
Removing subtrees from a tree is called pruning Prune branches before recursive processing
14
Returned by fib Found in cache
fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1
Skipped
Memoization:
SLIDE 98
Example: Pruning Trees
Removing subtrees from a tree is called pruning Prune branches before recursive processing
14
Returned by fib Found in cache
fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1
Skipped
Memoization:
SLIDE 99
Example: Pruning Trees
Removing subtrees from a tree is called pruning Prune branches before recursive processing
14
Returned by fib Found in cache
fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1
Skipped
Memoization:
SLIDE 100
Example: Pruning Trees
Removing subtrees from a tree is called pruning Prune branches before recursive processing
14
Returned by fib Found in cache
fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1
Skipped
Memoization:
SLIDE 101
Example: Pruning Trees
Removing subtrees from a tree is called pruning Prune branches before recursive processing
14
Returned by fib Found in cache
fib(5) fib(4) fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(2) fib(0) fib(1) 1 fib(3) fib(1) 1 fib(2) fib(0) fib(1) 1
Skipped
Memoization:
SLIDE 102
Example: Pruning Trees
Removing subtrees from a tree is called pruning Prune branches before recursive processing
14