Upload
elle
View
57
Download
0
Tags:
Embed Size (px)
DESCRIPTION
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 - PowerPoint PPT Presentation
Citation preview
03/12/13
Trees and CFGs
Discrete Structures (CS 173)Derek Hoiem, University of Illinois 1
Last class: recursive functions
base case recursive formula
• Process for finding closed form1. Unroll for several steps2. Write in terms of or 3. Substitute for value of that is base case4. Substitute base case value(s) and solve
• Verifying closed form with induction
2
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
3
Tree: special form of graph with “root” and no cycles
4
root
Tree terminologyNodes: root, internal, leaf, level, tree heightRelations: parent/child/sibling, ancestor/descendant
5overhead
Another example
6
64
7
5
2
3
1root
Another example
7
6
4
7
5
2
3
1 root
64
7
5
2
3
1root
Trees for sorting
8
><
><
Decision trees
9
Hierarchical data structure
10
Trees for clustering• Goal: create a function that maps from to
such that nearby N-dimensional points are mapped to the same integer
11
b>5
xx
x
x
x
x
x
xx
xx
1
2 3
a
b
5
6
a>6
1yes
no
no
yes
2 3
More terminologym-ary tree: each node can split into m subtreesfull: each node splits or timescomplete: all leaves have the same heightBalanced: 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 ?
12overhead
Induction proof on treesClaim: In a binary tree of height , the number of nodes .
13overhead
Context-free GrammarsA 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:
14overhead
CFG ExampleExample:
Which of these strings can be generated by the grammar above?
15overhead
Examples of parse trees
16
Language
Fig: Johnson 2007
Examples of parse trees
17Figs: Zhu and Mumford 2007
Scene parse
Object Parse
Examples of parse trees
18
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 (
19overhead
CFG example
20
*
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
21
Next class: more trees• Recursion trees and more proofs with trees
22