Question

In: Computer Science

Explain how you can utilize a minimum heap to sort the list of number in descending...

Explain how you can utilize a minimum heap to sort the list of number in descending order. Let n-be the number of elements in the list. What is the complexity of your sorting algorithm.Explain how you can utilize a minimum heap to sort the list of number in descending order. Let n-be the number of elements in the list. What is the complexity of your sorting algorithm.Please explain through example and give algorithem in written form (no code).

Solutions

Expert Solution

Heap sort is made up of two phases:

Phase 1: Construct a heap using the given elements.

Phase 2: Perform Continuous deletion of root element from the heap.

Heap Sort using min heap sorts in descending order where as max heap sorts in ascending order

Operations on utilizing Minimum Heap to sort the list of numbers in descending order:


1) getMini(): It returns the root element of Min Heap. Time Complexity of this operation is O(1).

2) extractMin(): Removes the minimum element from MinHeap. Time Complexity of this Operation is O(Logn) as this operation needs to maintain the heap property (by calling heapify()) after removing root.

3) decreaseKey(): Decreases value of key. The time complexity of this operation is O(Logn). If the decreases key value of a node is greater than the parent of the node, then we don’t need to do anything. Otherwise, we need to traverse up to fix the violated heap property.

4) insert(): Inserting a new key takes O(Logn) time. We add a new key at the end of the tree. IF new key is greater than its parent, then we don’t need to do anything. Otherwise, we need to traverse up to fix the violated heap property.

5) delete(): Deleting a key also takes O(Logn) time. We replace the key to be deleted with minum infinite by calling decreaseKey(). After decreaseKey(), the minus infinite value must reach root, so we call extractMin() to remove the key.

Time complexity :

n being the number of elements in the given list

It takes O(logn) for heapify and O(n) for constructing a heap. Hence, the overall time complexity of heap sort using min heap or max heap is O(nlogn)

Algorithm with example below :


1. Build a min heap from the input data.
2. At this point, the smallest item is stored at the root of the heap. Replace it with the last item of the heap followed by reducing the size of heap by 1.

3. Heapify the root of tree.
4. Repeat above steps while size of heap is greater than 1.

Example                               


Related Solutions

In this lab, you will implement Heap Sort algorithm in C++ and Report the number of...
In this lab, you will implement Heap Sort algorithm in C++ and Report the number of steps and the CPU running time in a table, please show the code and output Approximation the constant c in the complexity of heap sort (cnlgn) by inspecting the results For each algorithm, and for each n = 100, 200, 300, 400, 500, 1000, 4000, 10000, measure its running time and number of steps when the input is (1) already sort, i.e. n, n-1,...
Part A Write a 6-8 sentence summary explaining how you can use the Heap Sort algorithms...
Part A Write a 6-8 sentence summary explaining how you can use the Heap Sort algorithms to solve a real world problem. In your summary, provide a descriptive or visual explanation of your heapsort solution. Part B For this portion of the assignment you will design an algorithm to implement the solution described in part A. Your algorithm must be written in pseudocode. Note: Sample HeapSort Algorithm Pseudocode: Heapsort(A as array) BuildHeap(A) for i = n to 1 swap(A[1], A[i])...
Explain how you can utilize plant physiology in a real world scenario
Explain how you can utilize plant physiology in a real world scenario
Using Selection Sort on an any array of size 7, what will be the minimum/maximum number...
Using Selection Sort on an any array of size 7, what will be the minimum/maximum number of comparisons and number of exchanges? 1 for i = 1 to A.length-1 2 for j = i+1 to A.length 3 if A[j] < A[i] 4 exchange A[i] with A[j]
Explain how the movement of NaCl and water in the ascending and descending limbs of the...
Explain how the movement of NaCl and water in the ascending and descending limbs of the loop of Henle work as a countercurrent system. Use a diagram to help explain this.
Explain how the movement of NaCl and water in the ascending and descending limbs of the...
Explain how the movement of NaCl and water in the ascending and descending limbs of the loop of Henle work as a countercurrent system. You may use a diagram to help explain this.
The crossing number of a simple graph is the minimum number of crossings that can occur...
The crossing number of a simple graph is the minimum number of crossings that can occur when this graph is drawn in the plane, where no three curves representing edges are permitted to cross at the same point. Find the crossing numbers of (a) K3,3 (b) K5.
You are provided with an array of Strings and a list of Strings. Sort the elements...
You are provided with an array of Strings and a list of Strings. Sort the elements (1) in natural order, (2) in reverse natural order and (3) by the length of each String. You can fill in the details by using the following stub file: import java.util.Arrays; import java.util.Collections; import java.util.List; public class Midterm01 { public static void main(String[] args) { String[] arrayOfCities = { "Atlanta", "Savannah", "New York", "Dallas", "Rio" }; List<String> listOfCities = Arrays.asList("Atlanta", "Savannah", "New York", "Dallas",...
Can you please explain loop invariant for Heapsort, in which Min-Heapify and Build-Min-Heap are correct
Can you please explain loop invariant for Heapsort, in which Min-Heapify and Build-Min-Heap are correct
List the criteria that you would utilize to determine the optimal facilities plan
List the criteria that you would utilize to determine the optimal facilities plan
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT