03/14/13

11
03/14/13 More Trees Discrete Structures (CS 173) Derek Hoiem, University 1 Magritte

Upload: fox

Post on 05-Jan-2016

26 views

Category:

Documents


0 download

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 Presentation

TRANSCRIPT

Page 1: 03/14/13

03/14/13

More Trees

Discrete Structures (CS 173)Derek Hoiem, University of Illinois 1

Magritte

Page 2: 03/14/13

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

Page 3: 03/14/13

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

Page 4: 03/14/13

This lecture: more trees

• Recursion trees for illustrating computation in recursive functions

• Another tree proof

4

Page 5: 03/14/13

Useful formulas

∑𝑘=0

𝑛

𝑟 𝑘=1−𝑟𝑛+1

1−𝑟 ∑𝑘=𝑚

𝑛

𝑟 𝑘= 𝑟𝑚−𝑟𝑛+1

1−𝑟 ∑𝑘=𝑖

𝑛

𝑘=𝑛(𝑛+1)2

5

∑𝑘=0

𝑛

2𝑘=∑𝑘=1

𝑛

2𝑘=¿

(𝑚𝑎 )𝑏=𝑚𝑎𝑏

2 log2𝑛=𝑛log𝑎(𝑏)=log2(𝑏)/ log2 (𝑎)

𝑚𝑎+𝑏=𝑚𝑎𝑚𝑏

2 log4 (𝑛)+2=¿

Page 6: 03/14/13

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:

Page 7: 03/14/13

Recursion trees

7

Page 8: 03/14/13

Recursion trees A A

8

Page 9: 03/14/13

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

Page 10: 03/14/13

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

Page 11: 03/14/13

Have a great break!

11