| CS 261 | University of Puget Sound | Spring, 2020 |
|
Computer Science II
|
||
|
Abstract Data Types and their Implementations,
Some Basic Algorithms,
Object-oriented Problem Solving, and Efficiency |
||
Warning:
This course is under development.
Although the basic structure of this course is largely established,
nothing on this Web site should be considered official or even possibly
correct.
DO NOT MAKE PLANS BASED ON THE CONTENTS OF THIS SITE UNTIL JANUARY, 2020.
This lab provides more experience with binary search trees, building on the previous lab on trees.
Work in this lab involves the following classes that were introduced in the previous lab.
Be sure that these classes are available within the eclipse environment and available for further development.
The reading for this lab defines the length of a path within a tree, the depth or level of a node within a tree, and the height of a tree.
Today's reading draws upon Computer Science 2: Principles of Software Engineering, Data Types, and Algorithms by Henry M. Walker [Scott, Foresman and Company, 1989]. In particular, the reading defines when a tree is balanced or completely balanced.
Consider tree B above, and consider tree A below:
Determine if either of these trees is balanced. In each case, justify your answer.
Today's reading also defines when a tree is height-balanced.
Apply this definition to determine if the trees in Tree C and Tree D (below) are height balanced.
In the original Tree B, suppose we wish to remove the root, node k. We cannot just remove node k, since it connects two subtrees. Also, we cannot just move the left or right subtree upward to the root, because we must include the other subtree in the final structure as well. Instead, we first consider what values might replace 'k' in the root. In order to retain the ordering of nodes within a search tree, there are only two choices:
Consider a binary search tree of Person objects, as defined at the start of this lab and in the reading. Write a method
Person findLongest (BSTree<Person>)
that searches the tree for the Person with the longest first
name (i.e., the first name of the Person has the most number
of letters). In case the first names in two or more Persons
have the same number of letters, findLongest should return
the Person for which the first name comes last in dictionary
order.
(As with other steps in this labs, the use of global
variables for this method wil be subject to a substantial
penalty — up to 75%.)
For your findLongest method in step 11, suppose the initial tree contains n nodes, and suppose the height of the overall tree is k. Analyze your code to determine the order O(???) of the algorithm— giving both the careful analysis of work done and a clear statement of the conclusion.
|
created 21 April 2000 revised 24 March 2005 revised 24 April 2012 revised 3 November 2018 minor editing 31 January 2020 |
|
| For more information, please contact Henry M. Walker at walker@cs.grinnell.edu. |