cs 61a lecture 11
play

CS 61A Lecture 11 Wednesday, February 18 Announcements 2 - PowerPoint PPT Presentation

CS 61A Lecture 11 Wednesday, February 18 Announcements 2 Announcements Optional Hog Contest due Wednesday 2/18 @ 11:59pm 2 Announcements Optional Hog Contest due Wednesday 2/18 @ 11:59pm Homework 3 due Thursday 2/19 @ 11:59pm 2


  1. CS 61A Lecture 11 Wednesday, February 18

  2. Announcements 2

  3. Announcements • Optional Hog Contest due Wednesday 2/18 @ 11:59pm 2

  4. Announcements • Optional Hog Contest due Wednesday 2/18 @ 11:59pm • Homework 3 due Thursday 2/19 @ 11:59pm 2

  5. Announcements • Optional Hog Contest due Wednesday 2/18 @ 11:59pm • Homework 3 due Thursday 2/19 @ 11:59pm • Project 2 due Thursday 2/26 @ 11:59pm 2

  6. Announcements • Optional Hog Contest due Wednesday 2/18 @ 11:59pm • Homework 3 due Thursday 2/19 @ 11:59pm • Project 2 due Thursday 2/26 @ 11:59pm § Bonus point for early submission by Wednesday 2/25 @ 11:59pm! 2

  7. Box-and-Pointer Notation

  8. The Closure Property of Data Types 4

  9. 
 The Closure Property of Data Types • A method for combining data values satisfies the closure property if: 
 The result of combination can itself be combined using the same method 4

  10. 
 The Closure Property of Data Types • A method for combining data values satisfies the closure property if: 
 The result of combination can itself be combined using the same method • Closure is powerful because it permits us to create hierarchical structures 4

  11. 
 The Closure Property of Data Types • A method for combining data values satisfies the closure property if: 
 The result of combination can itself be combined using the same method • Closure is powerful because it permits us to create hierarchical structures • Hierarchical structures are made up of parts, which themselves are made up of parts, and so on 4

  12. 
 The Closure Property of Data Types • A method for combining data values satisfies the closure property if: 
 The result of combination can itself be combined using the same method • Closure is powerful because it permits us to create hierarchical structures • Hierarchical structures are made up of parts, which themselves are made up of parts, and so on Lists can contain lists as elements (in addition to anything else) 4

  13. Box-and-Pointer Notation in Environment Diagrams Interactive Diagram 5

  14. Box-and-Pointer Notation in Environment Diagrams Lists are represented as a row of index-labeled adjacent boxes, one per element Interactive Diagram 5

  15. Box-and-Pointer Notation in Environment Diagrams Lists are represented as a row of index-labeled adjacent boxes, one per element Each box either contains a primitive value or points to a compound value Interactive Diagram 5

  16. Box-and-Pointer Notation in Environment Diagrams Lists are represented as a row of index-labeled adjacent boxes, one per element Each box either contains a primitive value or points to a compound value Interactive Diagram 5

  17. Box-and-Pointer Notation in Environment Diagrams Lists are represented as a row of index-labeled adjacent boxes, one per element Each box either contains a primitive value or points to a compound value Interactive Diagram 5

  18. Box-and-Pointer Notation in Environment Diagrams Lists are represented as a row of index-labeled adjacent boxes, one per element Each box either contains a primitive value or points to a compound value Interactive Diagram 6

  19. Sequence Operations

  20. Membership & Slicing Python sequences have operators for membership and slicing 8

  21. Membership & Slicing Python sequences have operators for membership and slicing Membership . 8

  22. Membership & Slicing Python sequences have operators for membership and slicing Membership . >>> digits = [1, 8, 2, 8] >>> 2 in digits True >>> 1828 not in digits True 8

  23. Membership & Slicing Python sequences have operators for membership and slicing Membership . >>> digits = [1, 8, 2, 8] >>> 2 in digits True >>> 1828 not in digits True Slicing. 8

  24. Membership & Slicing Python sequences have operators for membership and slicing Membership . >>> digits = [1, 8, 2, 8] >>> 2 in digits True >>> 1828 not in digits True Slicing. >>> digits[0:2] [1, 8] >>> digits[1:] [8, 2, 8] 8

  25. Membership & Slicing Python sequences have operators for membership and slicing Membership . >>> digits = [1, 8, 2, 8] >>> 2 in digits True >>> 1828 not in digits True Slicing. >>> digits[0:2] Slicing creates a new object [1, 8] >>> digits[1:] [8, 2, 8] 8

  26. Membership & Slicing Python sequences have operators for membership and slicing Membership . >>> digits = [1, 8, 2, 8] >>> 2 in digits True >>> 1828 not in digits True Slicing. >>> digits[0:2] Slicing creates a new object [1, 8] >>> digits[1:] [8, 2, 8] 8

  27. Membership & Slicing Python sequences have operators for membership and slicing Membership . >>> digits = [1, 8, 2, 8] >>> 2 in digits True >>> 1828 not in digits True Slicing. >>> digits[0:2] Slicing creates a new object [1, 8] >>> digits[1:] [8, 2, 8] 8

  28. Trees

  29. Tree Abstraction 10

  30. Tree Abstraction 5 2 3 1 1 1 2 0 1 0 1 1 1 0 1 10

  31. Tree Abstraction 5 2 3 1 1 1 2 0 1 0 1 1 1 0 1 A tree has a root value and a sequence of branches; each branch is a tree 10

  32. Tree Abstraction Root 5 2 3 1 1 1 2 0 1 0 1 1 1 0 1 A tree has a root value and a sequence of branches; each branch is a tree 10

  33. Tree Abstraction Root 5 2 3 Branch 1 1 1 2 0 1 0 1 1 1 0 1 A tree has a root value and a sequence of branches; each branch is a tree 10

  34. Tree Abstraction Root 5 2 3 Branch 1 1 1 2 0 1 0 1 1 1 0 1 A tree has a root value and a sequence of branches; each branch is a tree A tree with zero branches is called a leaf 10

  35. Tree Abstraction Root 5 2 3 Branch 1 1 1 2 0 1 Leaf 0 1 1 1 0 1 A tree has a root value and a sequence of branches; each branch is a tree A tree with zero branches is called a leaf 10

  36. Tree Abstraction Root 5 2 3 Branch 1 1 1 2 0 1 Leaf 0 1 1 1 0 1 A tree has a root value and a sequence of branches; each branch is a tree A tree with zero branches is called a leaf 10

  37. Tree Abstraction Root 5 2 3 Branch 1 1 1 2 0 1 Leaf 0 1 1 1 0 1 A tree has a root value and a sequence of branches; each branch is a tree A tree with zero branches is called a leaf The root values of sub-trees within a tree are often called node values or nodes 10

  38. Tree Abstraction Root 5 2 3 Branch 1 1 1 2 0 1 Leaf 0 1 1 1 Sub-tree 0 1 A tree has a root value and a sequence of branches; each branch is a tree A tree with zero branches is called a leaf The root values of sub-trees within a tree are often called node values or nodes 10

  39. Tree Abstraction Root 5 2 3 Branch 1 1 1 2 Node 0 1 Leaf 0 1 1 1 Sub-tree 0 1 A tree has a root value and a sequence of branches; each branch is a tree A tree with zero branches is called a leaf The root values of sub-trees within a tree are often called node values or nodes 10

  40. Implementing the Tree Abstraction 11

  41. Implementing the Tree Abstraction A tree has a root value and a sequence of branches; each branch is a tree 11

  42. Implementing the Tree Abstraction A tree has a root value and a sequence of branches; each branch is a tree 3 1 2 1 1 11

  43. Implementing the Tree Abstraction A tree has a root value and a sequence of branches; each branch is a tree 3 1 2 1 1 >>> tree(3, [tree(1), ... tree(2, [tree(1), ... tree(1)])]) 11

  44. Implementing the Tree Abstraction A tree has a root value and a sequence of branches; each branch is a tree 3 1 2 1 1 >>> tree(3, [tree(1), ... tree(2, [tree(1), ... tree(1)])]) [3, [1], [2, [1], [1]]] 11

  45. Implementing the Tree Abstraction def tree(root, branches=[]): A tree has a root value and a sequence of branches; each branch is a tree 3 1 2 1 1 >>> tree(3, [tree(1), ... tree(2, [tree(1), ... tree(1)])]) [3, [1], [2, [1], [1]]] 11

  46. Implementing the Tree Abstraction def tree(root, branches=[]): A tree has a root value and return [root] + branches a sequence of branches; each branch is a tree 3 1 2 1 1 >>> tree(3, [tree(1), ... tree(2, [tree(1), ... tree(1)])]) [3, [1], [2, [1], [1]]] 11

  47. Implementing the Tree Abstraction def tree(root, branches=[]): A tree has a root value and return [root] + branches a sequence of branches; each branch is a tree def root(tree): 3 1 2 1 1 >>> tree(3, [tree(1), ... tree(2, [tree(1), ... tree(1)])]) [3, [1], [2, [1], [1]]] 11

  48. Implementing the Tree Abstraction def tree(root, branches=[]): A tree has a root value and return [root] + branches a sequence of branches; each branch is a tree def root(tree): return tree[0] 3 1 2 1 1 >>> tree(3, [tree(1), ... tree(2, [tree(1), ... tree(1)])]) [3, [1], [2, [1], [1]]] 11

Recommend


More recommend