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

Download More Trees - More Trees Discrete Structures (CS 173) University of Illinois 1 Magritte. Rooted trees

If you can't read please download the document

Post on 26-Jun-2020

1 views

Category:

Documents

0 download

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

    3 overhead

  • 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