03/14/13
DESCRIPTION
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 - PowerPoint PPT PresentationTRANSCRIPT
03/14/13
More Trees
Discrete Structures (CS 173)Derek Hoiem, University of Illinois 1
Magritte
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
2
Tree terminologyNodes: root, internal, leaf, level, tree heightRelations: parent/child/sibling, ancestor/descendant
3
root
leaves
internal
parent, child
subtree
level = 0
level = 1
level = 2
level = 3
This lecture: more trees
• Recursion trees for illustrating computation in recursive functions
• Another tree proof
4
Useful formulas
∑𝑘=0
𝑛
𝑟 𝑘=1−𝑟𝑛+1
1−𝑟 ∑𝑘=𝑚
𝑛
𝑟 𝑘= 𝑟𝑚−𝑟𝑛+1
1−𝑟 ∑𝑘=𝑖
𝑛
𝑘=𝑛(𝑛+1)2
5
∑𝑘=0
𝑛
2𝑘=∑𝑘=1
𝑛
2𝑘=¿
(𝑚𝑎 )𝑏=𝑚𝑎𝑏
2 log2𝑛=𝑛log𝑎(𝑏)=log2(𝑏)/ log2 (𝑎)
𝑚𝑎+𝑏=𝑚𝑎𝑚𝑏
2 log4 (𝑛)+2=¿
Recursion trees
6
cost of input
cost of subproblemsplit 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
7
Recursion trees A A
8
Tree induction proofIf 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
9
Tree induction proofIf 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.
10
Have a great break!
11