Programming Assignment 3 | Data Structure and Algorithms | CS 303, Assignments of Computer Science

Material Type: Assignment; Class: Algorithms and Data Structures; Subject: Computer Science; University: University of Alabama - Birmingham; Term: Spring 2008;

Typology: Assignments

Pre 2010

Uploaded on 04/12/2010

koofers-user-5db-1
koofers-user-5db-1 ๐Ÿ‡บ๐Ÿ‡ธ

4

(1)

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 303L Data Structure and Algorithm
February 7, 2008
Programming Assignment 3
(Due on February 21, 2008)
A Binary min-heap can be seen as a binary tree with two additional constraints: (1) the
shape property, and (2) heap property.
(1) The shape property: all levels of the tree, except possibly the last one (deepest) are fully
filled, and if the bottom level of the tree is not complete, the nodes of that level are filled
from left to right.
(2) The heap property: each node is less than or equal to each of its child nodes according to
some comparison predicate which is fixed for the entire data structure.
In this assignment, you will use the heap property of the binary min-heap to for sorting a
dataset in descending order.
There are two templates in the source code provided, including: Heap.java and HeapSort.java
The first class is Heap.java which enables you to build and manipulate a binary min-heap tree.
The Heap class contains an inner class โ€œNodeโ€ which is identical to the one provided in our
previous exercise and programming assignment.
(1) The constructor of Heap() allows you to build a binary min-heap tree for the given dataset.
To build the binary min-heap tree. You will need to implement the insert() method. This
method allows you to insert an element to the binary min-heap tree in ๐‘‚ log ๐‘› . Hence,
you can successively insert your data to build the tree in ๐‘‚ ๐‘›log ๐‘› .
(2) Once the binary min-heap tree is built, you are going to generate the sorting result. All you
need to do is to implement the delete() in the Heap class. The delete () method allows you
to remove the root node from the binary min-heap structure, and return the value of the
removed root.
The second one is HeapSort.java. You should use the binary min-heap structure for sorting the
dataset provided.
(1) Create the binary min-heap tree.
(2) Return the sorting result.
Two-page report is required.
(Bonus) Figure out an optimal method to build the binary min-heap tree in ๐‘‚ ๐‘› .

Partial preview of the text

Download Programming Assignment 3 | Data Structure and Algorithms | CS 303 and more Assignments Computer Science in PDF only on Docsity!

CS 303L Data Structure and Algorithm

February 7, 2008

Programming Assignment 3

(Due on February 21, 2008)

A Binary min-heap can be seen as a binary tree with two additional constraints: (1) the shape property, and (2) heap property.

(1) The shape property: all levels of the tree, except possibly the last one (deepest) are fully filled, and if the bottom level of the tree is not complete, the nodes of that level are filled from left to right. (2) The heap property: each node is less than or equal to each of its child nodes according to some comparison predicate which is fixed for the entire data structure. In this assignment, you will use the heap property of the binary min-heap to for sorting a dataset in descending order.

There are two templates in the source code provided, including: Heap.java and HeapSort.java

The first class is Heap.java which enables you to build and manipulate a binary min-heap tree. The Heap class contains an inner class โ€œNodeโ€ which is identical to the one provided in our previous exercise and programming assignment.

(1) The constructor of Heap() allows you to build a binary min-heap tree for the given dataset. To build the binary min-heap tree. You will need to implement the insert() method. This method allows you to insert an element to the binary min-heap tree in ๐‘‚ log ๐‘›. Hence, you can successively insert your data to build the tree in ๐‘‚ ๐‘› log ๐‘›. (2) Once the binary min-heap tree is built, you are going to generate the sorting result. All you need to do is to implement the delete() in the Heap class. The delete () method allows you to remove the root node from the binary min-heap structure, and return the value of the removed root.

The second one is HeapSort.java. You should use the binary min-heap structure for sorting the dataset provided.

(1) Create the binary min-heap tree. (2) Return the sorting result.

Two-page report is required.

( Bonus ) Figure out an optimal method to build the binary min-heap tree in ๐‘‚ ๐‘›.