Question

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])
        n = n - 1
        Heapify(A, 1)

BuildHeap(A as array)
    n = elements_in(A)
    for i = floor(n/2) to 1
        Heapify(A,i,n)

Heapify(A as array, i as int, n as int)
    left = 2i
    right = 2i+1

    if (left <= n) and (A[left] > A[i])
        max = left
    else 
        max = i

    if (right<=n) and (A[right] > A[max])
        max = right

    if (max != i)
        swap(A[i], A[max])
        Heapify(A, max)

Homework Answers

Answer #1

1).ANSWER:

GIVEN THAT:

Part 1

Heap sort is a sorting algorithm. This algorithm uses the binary heap data structure which is a complete binary tree.Here, first we create a tree data structure using the arrays.For creating tree from the array, we will make the element at the index 2i+1 as left child and at the index 2i+2 as right child of the tree.A max-heap is created by using the function heapify.Max-heap means the largest element will be at root node and both the children are smaller than the root node.After creating the max-heap, we will swap the element at the root node with the last element of the array.Now heapify the the max-heap by removing that last element.Repeat these step until array get sorted.

Part 2

Heapify(Arr as array, n as int, i as int)

{

max = i

left = 2i + 1

right = 2i + 2

if (left<= n) and (Arr[i] < Arr[left])

max = left

else

max = i

if (right <= n) and (Arr[max] > Arr[right])

max = right

if (max != i)

swap(Arr[i], Arr[max])

Heapify(Arr, n, max)

}

Heapsort(Arr as array)

{

n = length(Arr)

for i = n/2 to 1

Heapify(Arr, n ,i)

for i = n to 2

swap Arr[1] with Arr[i]

Arr.heapsize = Arr.heapsize - 1

Heapify(Arr, i, 0)

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Java : Modify the selection sort algorithm to sort an array of integers in descending order....
Java : Modify the selection sort algorithm to sort an array of integers in descending order. describe how the skills you have gained could be applied in the field. Please don't use an already answered solution from chegg. I've unfortunately had that happen at many occasion ....... ........ sec01/SelectionSortDemo.java import java.util.Arrays; /** This program demonstrates the selection sort algorithm by sorting an array that is filled with random numbers. */ public class SelectionSortDemo { public static void main(String[] args) {...
Test each algorithm (Counting Sort, Radix Sort, and Bucket Sort algorithms) on three different arrays of...
Test each algorithm (Counting Sort, Radix Sort, and Bucket Sort algorithms) on three different arrays of 1000 elements each with the following properties: By the way: To perform bucket sort the right way, convert the array elements to a value between 0 and 1 Array1: integers only in the range 0 through 999, already sorted in increasing order Array2: integers only in the range 0 through 999, already sorted in decreasing order Array3: integers only in the range 0 through...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world applications. In your summary, provide an example of a software project that you can create using STL templates and provide a brief explanation of the STL templates you will use to create this project. After that you will implement the software project you described . Your application must be a unique project and must incorporate the use of an STL container and/or iterator and...
For this lab assignment you will need to write some code and create some graphs. You...
For this lab assignment you will need to write some code and create some graphs. You may use excel to create your graphs, or other language of your choice. Your data needs to demonstrate the experimental running time for Selection Sort (code in book), Merge Sort (code in book), and the Arrays.sort() method. Here is a basic outline of how you need to code this assignment. 1) Create several arrays of size 100, 1000, 10000, 100000, 1000000, … (you need...
Using C++, Python, or Java, write a program that: In this programming exercise you will perform...
Using C++, Python, or Java, write a program that: In this programming exercise you will perform an empirical analysis of the QuickSort algorithm to study the actual average case behavior and compare it to the mathematically predicted behavior. That is, you will write a program that counts the number of comparisons performed by QuickSort on an array of a given size. You will run the program on a large number of arrays of a certain size and determine the average...
IN JAVA!! You may be working with a programming language that has arrays, but not nodes....
IN JAVA!! You may be working with a programming language that has arrays, but not nodes. In this case you will need to save your BST in a two dimensional array. In this lab you will write a program to create a BST modelled as a two-dimensional array. The output from your program will be a two-dimensional array.   THEN: practice creating another array-based BST using integers of your choice. Once you have figured out your algorithm you will be able...
import java.util.ArrayList; /* Rules:         1. Allow Tester to iterate through all nodes using the...
import java.util.ArrayList; /* Rules:         1. Allow Tester to iterate through all nodes using the in-order traversal as the default.             This means, in Tester the following code should work for an instance of this class             called bst that is storing Student objects for the data:                 BinarySearchTree_Lab08<String> bst = new BinarySearchTree_Lab08<String>();                 bst.add("Man");       bst.add("Soda");   bst.add("Flag");                 bst.add("Home");   bst.add("Today");   bst.add("Jack");                ...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT