SUNY Geneseo Department of Computer Science


Performance of Alternative Height Algorithms

{Date}

CSci 141, Fall 2003
Prof. Doug Baldwin

Return to List of Lectures

Previous Lecture


Misc

Exam 2 Wednesday (Nov. 19)

Questions?

Guess at closed form for the "Size" Algorithm in Friday's lecture came mostly from past experience with similar recurrences.

Height Algorithm

    int height()
        if ! this.isEmpty()
            leftHeight = this.left().height()
            rightHeight = this.right().height()
            if leftHeight > rightHeight
                return 1 + leftHeight
            else
                return 1 + rightHeight
        else
            return 0

vs

    int height()
        if ! this.isEmpty()
            if this.left().height() > this.right().Height()
                return 1 + this.left().Height()
            else
                return 1 + this.right().Height()
        else
            return 0

Mini-assignment: what are the performance consequences

Plan

Recurrences

n = 2i - 1 f(n)
0 = 20 - 1 1
1 = 21 - 1 4 + 3f(0)
  = 4 + 3(1)
3 = 22 - 1 4 + 3f(1)
  = 4 + 3(4+3(1))
  = 4 + 3(4) + 32(1)

Next

Inserting new items into a binary search tree


Next Lecture