Trees and Heaps - Data Structures - Homework #6 | CS 261, Assignments of Data Structures and Algorithms

Material Type: Assignment; Class: DATA STRUCTURES; Subject: Computer Science; University: Oregon State University; Term: Spring 2003;

Typology: Assignments

Pre 2010

Uploaded on 08/30/2009

koofers-user-wbu
koofers-user-wbu 🇺🇸

5

(1)

9 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 261 — Data Structures
Homework #6: Trees and Heaps (50 pts)
Due date: Monday, May 19, 2003 (5:00 PM)
Treat this paper as a specification for your assignment. Your code will be graded on correctness, read-
ability, and style. Study problems and exercises must be legible and will be graded on correctness.
What to do:
Programming:
1. Finding the largest value in a Binary Search Tree is no more difficult than finding the smallest value.
Create a new interface called FindMax that is similar to FindMin (with the exception that the
FindMax methods are called getLast and removeLast). Create a new class called AVLMax-
Tree that extends the AVLTree in the JDS library and implements the FindMax interface. (5 pts).
2. Create a class, BSTSet that extends the BinarySearchTree class in the JDS library and that
adds the following methods (15 pts).
(a) Sorted subSet(Object start, Object stop) — returns a sorted collection that
contains all the elements larger than or equal to start and smaller than stop.
(b) Sorted headSet(Object stop) — returns a sorted collection that contains all the ele-
ments smaller than stop.
(c) Sorted tailSet(Object start) — returns a sorted collection that contains all the ele-
ments larger than or equal to start.
Written homework:
Add the Integers 7, 4, 2, 5, 6, 8, 1, 3, 0 to an initially empty AVL tree in order. Examine the
toString() methods in jds/collection/AVLTree.java and write the output of the tree
after each insertion as it would be output by toString(). You can, if you want, write a small pro-
gram to create an AVL tree, insert the above values in the order indicated, and then invoke the
toString() method to generated the results (10 pts).
Chapter 14 Exercises 2 (5 pts) and 6 (5 pts).
E 14.2) Show the result after inserting the values 1, 3, 1, 4, 1, 5, 9 into an initially empty binary
search tree. Then show the result after deleting the root node.
E 14.6) Show all the AVL trees that could result after inserting the values 1, 2, 3, and 4 in various
permutations. How many different trees are there?
Chapter 15 Exercise 3 (10 pts).
E 15.3) The following tasks are intended to help you get a better feel for the implementation of the
operations in the Heap data type.
d. Create an initially empty heap, and verify that the method isEmpty will return
true.
e. Add the element 4 to the heap. Verify that isEmpty will now return false.
pf2

Partial preview of the text

Download Trees and Heaps - Data Structures - Homework #6 | CS 261 and more Assignments Data Structures and Algorithms in PDF only on Docsity!

CS 261 — Data Structures

Homework #6: Trees and Heaps (50 pts)

Due date: Monday, May 19, 2003 (5:00 PM) Treat this paper as a specification for your assignment. Your code will be graded on correctness, read- ability, and style. Study problems and exercises must be legible and will be graded on correctness.

What to do:

Programming:

  1. Finding the largest value in a Binary Search Tree is no more difficult than finding the smallest value. Create a new interface called FindMax that is similar to FindMin (with the exception that the FindMax methods are called getLast and removeLast). Create a new class called AVLMax- Tree that extends the AVLTree in the JDS library and implements the FindMax interface. ( 5 pts ).
  2. Create a class, BSTSet that extends the BinarySearchTree class in the JDS library and that adds the following methods ( 15 pts ).

(a) Sorted subSet(Object start, Object stop) — returns a sorted collection that contains all the elements larger than or equal to start and smaller than stop.

(b) Sorted headSet(Object stop) — returns a sorted collection that contains all the ele- ments smaller than stop.

(c) Sorted tailSet(Object start) — returns a sorted collection that contains all the ele- ments larger than or equal to start.

Written homework:

  • Add the Integers 7, 4, 2, 5, 6, 8, 1, 3, 0 to an initially empty AVL tree in order. Examine the toString() methods in jds/collection/AVLTree.java and write the output of the tree after each insertion as it would be output by toString(). You can, if you want, write a small pro- gram to create an AVL tree, insert the above values in the order indicated, and then invoke the toString() method to generated the results ( 10 pts ).
  • Chapter 14 Exercises 2 ( 5 pts ) and 6 ( 5 pts ).

E 14.2) Show the result after inserting the values 1, 3, 1, 4, 1, 5, 9 into an initially empty binary search tree. Then show the result after deleting the root node.

E 14.6) Show all the AVL trees that could result after inserting the values 1, 2, 3, and 4 in various permutations. How many different trees are there?

  • Chapter 15 Exercise 3 ( 10 pts ).

E 15.3) The following tasks are intended to help you get a better feel for the implementation of the operations in the Heap data type. d. Create an initially empty heap, and verify that the method isEmpty will return true. e. Add the element 4 to the heap. Verify that isEmpty will now return false.

f. Add the value 7. Show the structure of the new heap. g. Add the value 3. Show the structure of the new heap once the new value has been moved into place. h. Add the values 8, 9, 6, and 5, and show the structure of the final heap. i. Remove the value 3, and show the heap after is has been rebuilt. j. Remove each of the remaining values one by one, and show the heap after each operation.

What to turn in:

In class: a printout of written homework with illustrations (can be done using a text editor with additional handwritten illustrations or using Word or some other word processor) and printouts of your source files FindMax.java, AVLMaxTree.java, and BSTSet.java.

Via the web: the files Answers.txt (or Answers.doc or Answers.pdf), Find- Max.java, AVLMaxTree.java, and BSTSet.java.