Trees and CFGs Discrete Structures CS 173 Derek

  • Slides: 22
Download presentation
Trees and CFGs Discrete Structures (CS 173) Derek Hoiem, University of Illinois 03/12/13 1

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

Last class: recursive functions • 2

Last class: recursive functions • 2

Today’s lecture: Trees and CFGs • Trees – Examples of uses – Terminology –

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 root 4

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

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

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

Another example 7 4 6 root 1 5 2 3 6

Another example 7 4 6 root 1 5 2 3 6

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

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

Trees for sorting < > 8

Trees for sorting < > 8

Decision trees 9

Decision trees 9

Hierarchical data structure 10

Hierarchical data structure 10

Trees for clustering • b>5 1 x x no x x a>6 5 1

Trees for clustering • b>5 1 x x no x x a>6 5 1 x x x 2 b x no yes 3 2 a yes 6 3 11

More terminology • overhead 12

More terminology • overhead 12

Induction proof on trees • overhead 13

Induction proof on trees • overhead 13

Context-free Grammars • overhead 14

Context-free Grammars • overhead 14

CFG Example • overhead 15

CFG Example • overhead 15

Examples of parse trees Language Fig: Johnson 2007 16

Examples of parse trees Language Fig: Johnson 2007 16

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

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

Examples of parse trees Stochastic CFG for blackjack actions 18

Examples of parse trees Stochastic CFG for blackjack actions 18

Induction proof on CFG • overhead 19

Induction proof on CFG • overhead 19

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

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

Things to remember • Trees are a special graph with root and no cycles,

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

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