Please show your work clearly and thank you in advance. 1) Build the heap tree, then apply the HEAPSORT algorithm to sort the array A = [9, 0, 8, 12, 11, 5, 4, 8, 1, 2, 7] in ascending order.(You must perform the HEAPSORT algorithm step-by-step) Your response is below but is not completed. Please draw the tree Definition: Heap sort is one of the sorting algorithms used to arrange a list of elements in order and used for a comparison-based sorting technique based on the binary heap data structure. The step-by-step information to applying the HEAPSORT algorithm to sort the given array A in ascending order: Explanation : Build the heap tree start by creating a binary tree representation of the input array A and each node is a value in A with the parent-child relationship. The root node is the first element of A, then left child of a node at index i in A is the node at index 2i+1, Later, right child of a node at index i in A is the node at index 2i+2. 12 11 5 4     / \ / 12 <=  this tree must satisfy the heap property. Solution Perform the HEAPSORT algorithm to sort array A in ascending order. I will build a max heap from input array A then I will swap the root node. After the first swap, array A is [7, 0, 8, 12, 11, 5, 4, 8, 1, 2, 9] Here, I will perform a heapify operation on the root node to restore the heap property. After the first heapify operation, the array A is [8, 0, 5, 12, 11, 4, 2, 8, 1, 7, 9] I will repeat the steps until the entire array is sorted. After the second iteration, the array A is [8, 8, 5, 12, 11, 4, 2, 0, 1, 7, 9] third iteration [7, 8, 5, 12, 11, 4, 2, 0, 1, 8, 9] fourth iteration [5, 8, 4, 12, 11, 2, 1, 0, 7, 8, 9] fifth iteration [4, 8, 2, 12, 11, 1, 0, 5, 7, 8, 9] sixth iteration [2, 8, 1, 12, 11, 0, 4, 5, 7, 8]

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Subj - Design Algorithm

Please show your work clearly and thank you in advance.

1) Build the heap tree, then apply the HEAPSORT algorithm to sort the array A = [9, 0, 8, 12, 11, 5, 4, 8, 1, 2, 7] in ascending order.(You must perform the HEAPSORT algorithm step-by-step)

Your response is below but is not completed. Please draw the tree

Definition: Heap sort is one of the sorting algorithms used to arrange a list of elements in order and used for a comparison-based sorting technique based on the binary heap data structure.

The step-by-step information to applying the HEAPSORT algorithm to sort the given array A in ascending order:

Explanation :

  1. Build the heap tree start by creating a binary tree representation of the input array A and each node is a value in A with the parent-child relationship.

The root node is the first element of A, then left child of a node at index i in A is the node at index 2i+1, Later, right child of a node at index i in A is the node at index 2i+2.

12 11 5 4

    / \ /

  • 12 <=  this tree must satisfy the heap property.

Solution

  1. Perform the HEAPSORT algorithm to sort array A in ascending order. I will build a max heap from input array A then I will swap the root node. After the first swap,

array A is [7, 0, 8, 12, 11, 5, 4, 8, 1, 2, 9]

Here, I will perform a heapify operation on the root node to restore the heap property.

After the first heapify operation, the array A is [8, 0, 5, 12, 11, 4, 2, 8, 1, 7, 9]

I will repeat the steps until the entire array is sorted.

After the second iteration, the array A is [8, 8, 5, 12, 11, 4, 2, 0, 1, 7, 9]

third iteration [7, 8, 5, 12, 11, 4, 2, 0, 1, 8, 9]

fourth iteration [5, 8, 4, 12, 11, 2, 1, 0, 7, 8, 9]

fifth iteration [4, 8, 2, 12, 11, 1, 0, 5, 7, 8, 9]

sixth iteration [2, 8, 1, 12, 11, 0, 4, 5, 7, 8]

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Binomial Heap
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education