Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Class 16: Recursive Data Types

David Evans
October 25, 2016
4.9k

Class 16: Recursive Data Types

cs2102: Discrete Mathematics
University of Virginia, Fall 2016

See course site for notes:
https://uvacs2102.github.io

David Evans

October 25, 2016
Tweet

Transcript

  1. Class 16: Recursive Data Structures cs2102: Discrete Mathematics | F16

    uvacs2102.github.io David Evans University of Virginia
  2. Plan for Week Recursive Data Structures: Structural Induction (MCS Chapter

    7) o Book data structures: strings (balanced strings), non-negative integers, arithmetic expressions o Class data structures: lists (today), trees You should definitely read and understand what is in the book (and ask questions on slack about anything), but we will (mostly) do different examples in class.
  3. Main Idea We can show a property holds for all

    objects of a data type by: 1. Showing the property holds for all base objects. 2. Showing that all the ways of constructing new objects, preserve the property
  4. Pair Data Type set_first(p, c) ::= make_pair(c, pair_last(p)) Mutation is

    useful for efficient programming, but not for mathematical datatypes.
  5. Multuples A Quintuple is a Pair where the second part

    is a Quadruple A Sextuple is a Pair where the second part is a Quintuple A Septuple is a pair where the second part is a Sextuple An Octuple is group of octupi A ? is a Pair where the second part is a …? 12
  6. Lists 13 A List is either: a Pair where the

    second part is a List or, the empty list null in LISP, None in Python, for mathematical lists
  7. Defining List Definition 1. A List is an ordered sequence

    of objects. Definition 2. A List is either a Pair where the second part is a List or the empty list. Are these equivalent definitions?
  8. Defining Datatypes Definition. A set is an unordered collection of

    objects. A set is defined by its membership operation: ∈ is true if is in the set . Class 7: Set Today: List Definition. A list is an ordered sequence of objects. A list is either the empty list (), or the result of prepend(, ) for some object and list .
  9. Descriptive Definitions Definition. A set is an unordered collection of

    objects. A set is defined by its membership operation: ∈ is true if is in the set . Definition. A list is an ordered sequence of objects. A list is defined by Class 7: Set Today: List
  10. Constructive Definitions Definition. A set is an unordered collection of

    objects. A set is Class 7: Set Today: List Definition. A list is an ordered sequence of objects. A list is either the empty list (), or the result of prepend(, ) for some object and list .
  11. Charge Thursday: Structural Induction Problem Set 7 due Friday Send

    any questions you want for Thursday’s class