Select Page

## North Carolina A & T State University Sorting Algorithm and Heaps Project requirements are in the attached file. But here they are: Problem 1: Sorting al

North Carolina A & T State University Sorting Algorithm and Heaps Project requirements are in the attached file. But here they are:

Problem 1:

Sorting algorithm comparison

In this problem you are asked to:

Implement in Java the Quicksort algorithm for arrays of integers.
Implement in Java the Hybrid Quicksort algorithm for arrays of integers, a variant of Quicksort that depends on an additional parameter k. The algorithm works as follows:

– if the size of the portion of the array to be sorted is greater than k, it recursively calls the Hybrid Quicksort method with the same k;

– if the size of the portion of the array to be sorted is less than or equals to k, it sorts that portion by using the Insertion Sort algorithm.

Empirically compare these two sorting algorithms for different values of k (k = {10,

20, 50, 100,…..}) and different array sizes n (n = {20, 100, 1000, 10000). Find out for which values of k and for which array sizes Hybrid Quicksort outperforms the standard Quicksort.

Problem 2:

You have learnt about heaps as a data structure that allows one to retrieve the maximum in a set of numbers in constant time. Moreover, a heap can be maintained in logarithmic time if we insert a new element and it eventually finds it place in the heap. Your task will be to realize priority queues using heaps in arrays.

Priority Queue is an extension of queue with following properties.

1.Every item has a priority associated with it.

2.An element with high priority is dequeued before an element with low priority.

3.If two elements have the same priority, they are served according to their order in the queue

.4.Here value of the element itself can be considered as its priority, greater the number,higher is the priority.

Implement priority queues as instances of the class:

public class PriorityQueue{

int maxSize;

int currentSize;

int[] queue;

public PriorityQueue(int maxSize){

this.maxSize = maxSize;

queue = new int[maxSize];

currentSize = 0;

}

}

An instance of this class can hold a heap of up to maxSize integers. Initially, the heap has size 0, which means that none of the elements of the array queue is considered to be a heap element.

You are now asked to implement the following methods for this class:

1.boolean empty(), which returns true iff the heap is empty;

2. boolean full(), which returns true iff the number of integers in the heap is equal to maxSize;

3. int extractMax(), which returns the maximum element of the heap, deletes it from the heap, and reorganizes the array so that it is a heap of the remaining elements; after this operation the currentSize of the priority queue is one less than it was before; clearly, the operation can only be applied if the priority queue is not empty, otherwise, an exception has to be raised;

4. void insert(int n), which inserts a number n and reorganizes the array so that it is a heap of the new, larger set of elements; after this operation the currentSize of the priority queue is one greater than it was before; clearly, the operation can only be applied if the priority queue is not full, otherwise, an exception has to be raised.

5. void printHeap(), which prints the heap. This method can be implemented as you wish as long as you mention how one should read the ordering of elements from printed Heap. Problem 1:
Sorting algorithm comparison
In this problem you are asked to:

Implement in Java the Quicksort algorithm for arrays of integers.

Implement in Java the Hybrid Quicksort algorithm for arrays of integers, a variant of
Quicksort that depends on an additional parameter k. The algorithm works as follows:
o if the size of the portion of the array to be sorted is greater than k, it recursively
calls the Hybrid Quicksort method with the same k;
o if the size of the portion of the array to be sorted is less than or equals to k, it
sorts that portion by using the Insertion Sort algorithm.

Empirically compare these two sorting algorithms for different values of k (k = {10,
20, 50, 100,…..}) and different array sizes n (n = {20, 100, 1000, 10000). Find out for
which values of k and for which array sizes Hybrid Quicksort outperforms the standard
Quicksort.
Problem 2:
You have learnt about heaps as a data structure that allows one to retrieve the maximum in a set
of numbers in constant time. Moreover, a heap can be maintained in logarithmic time if we insert
a new element and it eventually finds it place in the heap. Your task will be to realize priority
queues using heaps in arrays.
Priority Queue is an extension of queue with following properties.
1. Every item has a priority associated with it.
2. An element with high priority is dequeued before an element with low priority.
3. If two elements have the same priority, they are served according to their order in the
queue.
4. Here value of the element itself can be considered as its priority, greater the number,
higher is the priority.
Implement priority queues as instances of the class:
public class PriorityQueue{
int maxSize;
int currentSize;
int[] queue;
public PriorityQueue(int maxSize){
this.maxSize = maxSize;
queue = new int[maxSize];
currentSize = 0;
}
}
An instance of this class can hold a heap of up to maxSize integers. Initially, the heap has size
0, which means that none of the elements of the array queue is considered to be a heap element.
You are now asked to implement the following methods for this class:
1. boolean empty(), which returns true iff the heap is empty;
2. boolean full(), which returns true iff the number of integers in the heap is equal to
maxSize;
3. int extractMax(), which returns the maximum element of the heap, deletes it from the
heap, and reorganizes the array so that it is a heap of the remaining elements; after this operation
the currentSize of the priority queue is one less than it was before; clearly, the operation can
only be applied if the priority queue is not empty, otherwise, an exception has to be raised;
4. void insert(int n), which inserts a number n and reorganizes the array so that it is a
heap of the new, larger set of elements; after this operation the currentSize of the priority
queue is one greater than it was before; clearly, the operation can only be applied if the priority
queue is not full, otherwise, an exception has to be raised.
5. void printHeap(), which prints the heap. This method can be implemented as you wish
as long as you mention how one should read the ordering of elements from printed Heap.