Assignment 4 : Heap Sort and Sorting Sections of Array
- preparation of Piped Multiple-level Merge-Sort
Dr. Huaqing Wang
I. Heap, Heap-sort, and Heap Heap-Sort of section of Array
- An array or a section of array can be treated as a complete binary tree.
- An heap cound be min-heap or a max-heap. A min-heal is defined as binary tree with the
following features:
Each non-leaf node holds a value/object which is less than or equal to
direct children ( or child if parent has only one chaild ).
If the less-than or equal-to (<=) relationship change to "larger-than-orequal-to".
The heap will be max-heap.
- Heap-sort will sort the data based heap which have n*LOG2(N)
- To be able to sorting multiple sections of one array concurrently. We want the heap-sort
will be able to a section array.
II. Description: Define following classes
1. Define a class for holdig the starting and endibg indices or lower-upper boundaries
inclusively of a section of an array.
2. Define Generic Heap class which will take a array, and starting and ending indices,
The heap object has sort() and sort(T[], int sarting, int ending) which will sort the
data in the secton indicated by starting and ending indices inclusively.
III. To Test Your Implementation with the following Menu-Driven Program:
============================ 3390 Assignment 4 =======================
Heap Sort - Entire or Part of Arry
======================================================================
G/g: Do the following:
1. Ask two integers (N, K): N is array size and K is number of
sections. The size of each section can be calcualtedd by
Section size = N / K. The last section could have size
between section size and 2 * section-size - 1 depending
on N and K.
2. Declare array (say dArr) of Comparable objects, The 'dArr'
is a pointer to array of pointers to comparable objects.
3. Declare an array , say bArr, of K Border objects. The
bArr points at array of pointer to Border objects.
4. Fill the boarder pointer array with border objects and
each border object holds the starting index and size of
a section in array (dArr). All but last section shold have
the same size..
5. Fill the T array with Integer objects containing randomly
generated int values.
B/b: Show border information in in following format:
0:[0, 9], 1:[10, 19] ..... 8:[80, 89], 9:[90, 109] -- before heap is introduced.
0:[0, 10], 1:[10, 10] ..... 8:[80, 10], 9:[90, 19] -- for the convenience of heapsort.
for N = 109, K = 10, section size = 109 / 10 =10
A/a: Show all integers in the data arry one secrion integers
per line prefixed with section number and border info.
S/s: Ask for secion number (0...K-1). Sort and dislay the required
section. Ff the number is between 0 and k-1 sort and display the
entire array. Notice tha with Min-heap the the array data will
in descending order. If Max-heap is used, the array will be
sorted in acending order.
D/d: Ask for an integer S and display array by the 0 <= S < k show
data in the section. Display entire array if s is out of range.
M/m: Scrable/Mix the data in the entire array.
======================================================================
H/h/?: Show this menu.
E/e: Exit the project.
======================================================================
public Class Border {
public int start, size;;
public Border ( int l, int sz ) { lb = l; ub = sz; }
}