Department of Computer Science

Principles of Object Oriented Programming

Fall Semester 2011

Dr. Maury Eggen

Homework Laboratory Assignment 3:

Homework laboratory assignment three involves more 'self referential data structures.' We already know about linked lists, and that the treatment of linked lists has lots of applications.

Now comes the fun part. A binary tree can be envisioned as nothing more than a doubly linked list. We include a reference to the left subtree, and a reference (link) to the right subtree. As such, a binary tree is not much more abstract than a doubly linked list.

As discussed in class, you should implement binary search trees in two ways: a nodes and references approach, like a doubly linked list, and a list of lists approach, where the subtrees are merely sublists of the parent list. Again, as with much of object oriented programming, if the top level classes are implemented correctly, the underlying classes should be transparent to the application.

The binary search tree application should include insert, search, inorder, preorder and postorder traversals, depth, size, min, max. As you exercise your application, count the number of comparisons it takes to search for a particular item. Deleting from a BST is more difficult. You may include delete if you wish additional credit.

The nifty thing about a binary search tree is that if we perform an inorder traversal of the tree, the nodes come out in sorted order. Thus, we get a sorting algorithm for free. How good is the algorithm? Is it competitive with some of the better sorting algorithms? Why or why not? Use your BST to sort files of size 1000, 2000, 4000, 8000, 16000, 32000, 64000 and 128000 elements. Which of the implementations is superior? Time each (since it is so easy to do in Python) and record your times. Include a discussion.

Follow the discussion in class for the "nodes and references" approach to the binary search tree. The design of the list of lists approach is totally your own. (But I'll bet it shouldn't be much different!)

Make sure you can fill your binary search tree from a file. We don't want to have to enter values from the keyboard. You can include a keyboard entry as well if you would like to use it for testing.

Due date: March 2, 2012

Make a folder entitled
youruserid.linkedstructures
and place everything you wish me to see in this folder. Copy the folder into my public directory on or before the due date using the command

cp -r youruserid.bst /users/meggen/Public