Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a python code to sort an array A in ascending order with below pseudocode and include 5 test cases: _ _ _ _ _

Write a python code to sort an array A in ascending order with below pseudocode and include 5 test cases:
_____________________________________________
Heapsort(A as array)
BuildMaxHeap(A)
for i = n to 1
swap (A[1], A[i])
n = n-1
Heapify(A,1)
BuildMaxHeap (A as array)
n = elements_in (A)
for i = floor (n/2) to 1
Heapify(A,i)
Heapify(A as array, i 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)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

c. What groups were least represented? Why do you think this is so?

Answered: 1 week ago

Question

7. Describe phases of multicultural identity development.

Answered: 1 week ago