# more trees - more trees discrete structures (cs 173) university of illinois 1 magritte. rooted trees

Post on 26-Jun-2020

1 views

Category:

## Documents

Embed Size (px)

TRANSCRIPT

• More Trees

Discrete Structures (CS 173) University of Illinois 1

Magritte

• Rooted trees

2

root

• Terminology for rooted trees

Nodes: root, internal, leaf, level, tree height

Relations: parent/child/sibling, ancestor/descendant

• Another example

4

6 4

7

5

2

3

1 root

• Another example

5

6

4

7

5

2

3

1 root

6 4

7

5

2

3

1 root

• Decision trees

6

• Hierarchical data structure; HTML; XML

7

• Programs as trees

8

• Languages, parsing, parse trees

9

• More terminology

m-ary tree: each node can have at most m children

full: each node has either 0 children or π children

complete: all leaves have the same height

balanced: all leaves are approximately the same height

10

• Tree terminology

Nodes: root, internal, leaf, level, tree height

Relations: parent/child/sibling, ancestor/descendant

11

root

leaves

internal subtree

level = 0

level = 1

level = 2

level = 3

• More terminology for directed trees

m-ary tree: each node has at most m children

full: each node splits 0 or π times

complete: all leaves have the same height

12

• Induction on rooted trees

A full m-ary tree with i internal nodes has mi + 1 nodes

13

• 14

• 15

• 16

• Induction proof on trees

Claim: In a binary tree of height β, the number of nodes π β€ 2β+1 β 1.

17

• Induction proof on trees

Claim: There are at most πβ leaves in an m-ary tree of height h

18

• Useful formulas

ΰ·

π=0

π

ππ = 1 β ππ+1

1 β π ΰ·

π=π

π

ππ = ππ β ππ+1

1 β π ΰ·

π=π

π

π = π(π + 1)

2

19

ΰ·

π=0

π

2π = ΰ·

π=1

π

2π =

ΰ·

π=0

π

2β2π = ΰ·

π=0

π

2π+2 =

ππ π = πππ 2log2 π = π

logπ(π) = log2(π)/ log2 π

ππ+π = ππππ

2log4(π)+2 =

• 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

20

• 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.

TRY TO DO THIS AS AN EXERCISE.

21

Recommended