Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment you are to write a Python program to implement heapsort algorithm & apply it on a provided list. You are provided with

In this assignment you are to write a Python program to implement heapsort algorithm & apply it on a provided list.
You are provided with the template in which you must:
(1) implement Phase II of a heapsort algorithm:
(1.1) function that sifts down the value of the heap root to a correct position, and
(1.2) function that finds the largest child of a given heap node.
Your program must:
take a file containing input list of values as a command line argument and print the original list,
create a heap form a given list of values and print created heap,
sort given list using heapsort algorithm (1), and print sorted list.
Following is the output of the program run applied on a provided test file:
Together with your source code include a separate file Namingformat.py with your information as the values of the
following variables:
myName = 'first_name last_name'
myTechID ='0000000'
myTechEmail = 'abc123' #only your email id omit @latech.edu
You must properly cite the sources if you use any help from peers or any code/ideas from online resources. Failure to do
so will be treated as a plagiarism. Properly citing the sources should be done as a comment in your code. Some examples:
# found this code at:
# used idea from:
# helped me with this part
>python heapsort.py test.txt
Original list: [10,30,-100,50,20,30,-40,70,5,50]
Heapified list:
Heap size: 10.
Heap capacity: 10.
Elements of heap:
Value: 70 at index: 0
Value: 50 at index: 1
Value: 30 at index: 2
Value: 30 at index: 3
Value: 50 at index: 4
Value: -100 at index: 5
Value: -40 at index: 6
Value: 10 at index: 7
Value: 5 at index: 8
Value: 20 at index: 9
Sorted list: [-100,-40,5,10,20,30,30,50,50,70]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

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

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions

Question

What is a residual plot?

Answered: 1 week ago