110 likes | 249 Views
More Trees. 03/14/13. M agritte. Discrete Structures (CS 173) Derek Hoiem, University of Illinois. Last class: trees and CFGs. Trees are a special graph with root and no cycles, with many uses Sorting, clustering, finding similar values Decision tree: machine learning, modeling choices
E N D
More Trees 03/14/13 Magritte Discrete Structures (CS 173) Derek Hoiem, University of Illinois
Last class: trees and CFGs • 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
Tree terminology Nodes: root, internal, leaf, level, tree height Relations: parent/child/sibling, ancestor/descendant root level = 0 parent, child level = 1 internal subtree level = 2 level = 3 leaves
This lecture: more trees • Recursion trees for illustrating computation in recursive functions • Another tree proof
Recursion trees cost of input cost of subproblem split in 2 How many levels before base case? Sum of values in each level? How many leaf nodes? Total cost = sum of leaf costs + sum of internal costs:
Recursion trees A A
Tree induction proof If is a binary tree with root , then its rank is (a) if has no children (b) if has two children, both with rank (c) otherwise, the maximum rank of any of the children
Tree induction proof If is a binary tree with root , then its rank is (a) if has no children (b) if has two children, both with rank (c) otherwise, the maximum rank of any of the children Claim: A tree with rank has at least leaves.