Understanding Trees and Context-Free Grammars in Discrete Structures
220 likes | 358 Views
This lecture delves into the concepts of trees and context-free grammars (CFGs) in the realm of discrete structures. It covers key terminologies, different types of trees (like binary and m-ary trees), their properties, and how they relate to recursive functions. The session discusses the practical applications of trees in sorting, clustering, and decision-making processes, as well as demonstrating how CFGs generate parse trees. Additionally, it provides insights into induction proofs related to tree structures and contextual grammars, reinforcing these topics with examples.
Understanding Trees and Context-Free Grammars in Discrete Structures
E N D
Presentation Transcript
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 • Substitute base case value(s) and solve • Verifying closed form with induction
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
Tree terminology Nodes: root, internal, leaf, level, tree height Relations: parent/child/sibling, ancestor/descendant overhead
Another example 7 4 6 root 1 5 2 3
Another example root 1 7 4 6 2 root 1 5 2 3 4 6 3 5 7
Trees for sorting < > < >
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
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
Induction proof on trees Claim: In a binary tree of height , the number of nodes . overhead
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
CFG Example Example: Which of these strings can be generated by the grammar above? overhead
Examples of parse trees Language Fig: Johnson 2007
Examples of parse trees Scene parse Object Parse Figs: Zhu and Mumford 2007
Examples of parse trees Stochastic CFG for blackjack actions
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
CFG example * I like to eat apples and bananas overhead
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
Next class: more trees • Recursion trees and more proofs with trees