SUNY Geneseo Department of Computer Science


Performance of Tree Searches

{Date}

CSci 141, Spring 2005
Prof. Doug Baldwin

Return to List of Lectures

Previous Lecture


Questions?

Ordered tree algorithm from lab? How to create unordered trees to test on?

    OrderedTree t = new OrderedTree()
    t.insertNode( new Integer(5) )
    t.getLeft().insertNode( new Integer(10) )
    ....

Performance of Search-Style Algorithms

Section 13.3.5

Search time depends on height more than number of items

Fully balanced tree has two children at every node in every non-leaf level, both subtrees fully balanced and of same height

Tree of height h, worst-case search time = Θ(h)

What if tree is totally unbalanced?

[A Tree with Only One Child per Node]

Search time in terms of n

Decision Trees

Trees used to classify things - useful model for complex conditionals, AI, etc.

[A Tree of Questions for Classifying Animals]

What can you say about how fast a decision tree with n possible outcomes can make a decision?

Height of tree in terms of number of leaves

Work it out

[Tree with n Leaves and Height h]

Reading said one more leaf than non-leaf nodes for fully-balanced trees

Decision time Θ(h) = Θ( log2n + 1 )

Other extreme? completely unbalanced tree?

Next

Deletion from ordered trees

section 13.5.1


Next Lecture