Algorithm Analysis (CSC 301 2015F) : EBoards

CSC301.01 2015F, Class 11: Binary Search Trees


Overview

Preliminaries

Admin

Upcoming Work

Extra Credit

Academic

Peer

Questions

How do I change the size of my vector?

I'd recommend that you build your hash tables as four element vectors (size, capacity, alpha, vector of lists). That way, when you expand them, you're just setting one element of the enclosing vector.

Do values have to move when we expand the hash table?

Almost certainly.

What will our code look like?

(vector-set hash-table 3 (expand-vector (vector-ref hash-table 3))

(vector-set hash-table 0 (vector-length (vector-ref hash-table 3))

(define expand-vector ...)

Do we have to write code to implement SetOfStrings?

No. Your goal is to consider various options for implementing them and assess their relative efficacy.

Trees, Formalized

Small group task: Describe trees formally.

This somewhat mathematical representation serves multiple purposes

For ordered trees, we add an i (in the natural numbers) to the child relationship, form , for "c is the ith child of p"

Terminology

Small group task: Think about what each of these terms means. Be prepared with a definition. (Your definitions can be formal or informal.)

Binary Trees

Binary trees are ordered trees in which no parent has more than two children (only valid indices are 0 and 1) without the requirement that having child 1 requires you to have child 0.

Traversing Trees

When talking about traversal, we focus on when we process a value in the tree. We may visit the values in a slightly different order.

Binary Search Trees

Binary trees in which all the values in the left subtree are less than (or equal to) the node, which is less than (or equal to0 all the values in the right subtree

In general, searcing in a binary search tree is O(height)

A binary tree with N nodes can have height O(logn), so this can be fast.

Can we balance our trees? Let's go for "almost balanced" - the height of subtrees shall not differ by more than 1.

Balancing Binary Search Trees

See white board. (They are probably in my outline, too.)