SUNY Geneseo Department of Computer Science


Recurrence Relations for Tree Traversals

{Date}

CSci 141, Fall 2003
Prof. Doug Baldwin

Return to List of Lectures

Previous Lecture


Misc

Lab available in lab sessions tomorrow

Exam 2 next Wednesday (Nov. 19)

Questions?

Recurrence relations and "display"

    display()
        if ( ! this.isEmpty() )
            print this.root()
            this.left().display()
            this.right().display()

Number of primitive tree messages

Recurrence relation:

Won't usually be n-1 nodes on one side and n-2 on other

Look for a pattern in f(n):

n   f(n)
0   1
1   4+f(0)+f(0) = 4 + 1 + 1
2   4 + f(1) + f(0)
    = 4 + 4 + 1 + 1 + 1
3   4 + f(n1) + f(n2)
  a) 4 + f(2) + f(0)
    = 4 + 4 + 4 + 1 + 1 + 1 + 1
  b) 4 + f(1) + f(1)
    = 4 + 4 + 1 + 1 + 4 + 1 + 1
    = 4 + 4 + 4 + 1 + 1 + 1 + 1

f(n) = 4n + (n+1) ?

Prove by strong induction on n

Due date for Lab 11 extended to Thursday, 11/13, so people can incorporate this idea into the other recurrences if they wish.

Next

Tree traversals


Next Lecture