1 / 22

03/12/13

Trees and CFGs. 03/12/13. Discrete Structures (CS 173) Derek Hoiem, University of Illinois. Last class: recursive functions.  base case  recursive formula Process for finding closed form Unroll for several steps Write in terms of or Substitute for value of that is base case

mikasi
Download Presentation

03/12/13

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Trees and CFGs 03/12/13 Discrete Structures (CS 173) Derek Hoiem, University of Illinois

  2. Last class: recursive functions  base case  recursive formula • Process for finding closed form • Unroll for several steps • Write in terms of or • Substitute for value of that is base case • Substitute base case value(s) and solve • Verifying closed form with induction

  3. Today’s lecture: Trees and CFGs • Trees • Examples of uses • Terminology • Induction on trees • Context free grammars (CFGs) • What they are, how they work • Induction on CFG

  4. Tree: special form of graph with “root” and no cycles root

  5. Tree terminology Nodes: root, internal, leaf, level, tree height Relations: parent/child/sibling, ancestor/descendant overhead

  6. Another example 7 4 6 root 1 5 2 3

  7. Another example root 1 7 4 6 2 root 1 5 2 3 4 6 3 5 7

  8. Trees for sorting < > < >

  9. Decision trees

  10. Hierarchical data structure

  11. Trees for clustering • Goal: create a function that maps from to such that nearby N-dimensional points are mapped to the same integer b>5 1 x no yes x x x a>6 5 1 x x no yes x x x x x 2 3 b 3 2 a 6

  12. More terminology m-ary tree: each node can split into m subtrees full: each node splits or times complete: all leaves have the same height Balanced: all leaves are approximately the same height How many nodes in a full m-ary tree with internal nodes? What are the lower/upper bounds on the number of nodes of an m-ary tree with height ? overhead

  13. Induction proof on trees Claim: In a binary tree of height , the number of nodes . overhead

  14. Context-free Grammars A context-free grammar (CFG) is a set of rules that defines a set of possible parse trees. A CFG specifies a set of rules, valid start symbols, and valid terminals. Example: Start symbol: Terminals: overhead

  15. CFG Example Example: Which of these strings can be generated by the grammar above? overhead

  16. Examples of parse trees Language Fig: Johnson 2007

  17. Examples of parse trees Scene parse Object Parse Figs: Zhu and Mumford 2007

  18. Examples of parse trees Stochastic CFG for blackjack actions

  19. Induction proof on CFG Claim: For any string generated by the grammar above, the number of ’s will be equal to the number of ’s plus the number of ’s ( overhead

  20. CFG example * I like to eat apples and bananas overhead

  21. Things to remember • Trees are a special graph with root and no cycles, with many uses • Sorting, clustering, finding similar values • Decision tree: machine learning, modeling choices • Parse trees: representing hierarchical structures • Context free grammars: generate parse trees • Proofs on trees: split at root, use inductive hypothesis on subtrees headed by the root’s children

  22. Next class: more trees • Recursion trees and more proofs with trees

More Related