Download presentation
Presentation is loading. Please wait.
1
More Trees Discrete Structures (CS 173)
03/14/13 Magritte Discrete Structures (CS 173) Derek Hoiem, University of Illinois
2
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
3
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
4
This lecture: more trees
Recursion trees for illustrating computation in recursive functions Another tree proof
5
Useful formulas 𝑚 𝑎 𝑏 = 𝑚 𝑎𝑏 𝑚 𝑎+𝑏 = 𝑚 𝑎 𝑚 𝑏 2 log 2 𝑛 =𝑛
𝑘=0 𝑛 𝑟 𝑘 = 1− 𝑟 𝑛+1 1−𝑟 𝑘=𝑚 𝑛 𝑟 𝑘 = 𝑟 𝑚 − 𝑟 𝑛+1 1−𝑟 𝑘=𝑖 𝑛 𝑘 = 𝑛(𝑛+1) 2 𝑘=0 𝑛 2 𝑘 = 𝑘=1 𝑛 2 𝑘 = 𝑘=0 𝑛 2 −2𝑘 = 𝑘=0 𝑛 2 𝑘+2 = 𝑚 𝑎 𝑏 = 𝑚 𝑎𝑏 𝑚 𝑎+𝑏 = 𝑚 𝑎 𝑚 𝑏 2 log 2 𝑛 =𝑛 log 𝑎 (𝑏) = log 2 (𝑏)/ log 2 𝑎 2 log 4 (𝑛)+2 =
6
Recursion trees 𝑇 1 =𝑐 𝑇 𝑛 =2𝑇 𝑛/2 +𝑛
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:
7
Recursion trees 𝑇 1 =𝑐 𝑇 𝑛 =2𝑇 𝑛−1 +𝑑
8
Recursion trees A 1 =𝑐 A 𝑛 =4𝐴 𝑛/2 +𝑛
9
Tree induction proof If 𝑇 is a binary tree with root 𝑟, then its rank is (a) 0 if 𝑟 has no children (b) 1+𝑞 if 𝑟 has two children, both with rank 𝑞 (c) otherwise, the maximum rank of any of the children
10
Tree induction proof If 𝑇 is a binary tree with root 𝑟, then its rank is (a) 0 if 𝑟 has no children (b) 1+𝑞 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 2 𝑞 leaves.
11
Have a great break!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.