Answered step by step
Verified Expert Solution
Question
1 Approved Answer
For this task, you need to apply the greedy algorithm defined to address the previous task. Below I provide a function testGreedy that displays the
For this task, you need to apply the greedy algorithm defined to address the previous task. Below I provide a function testGreedy that displays the process time in terms of nanoseconds when the greedy algorithm is applied to process Cow data in a given file with a specific weight limit and a chosen sorting method.
#Using Greedy
import time
def testGreedyfilename constraint, method toPrintFalse:
items loadcowsfilename
start time.processtimens
printAt the beginning of processing formatfilename
printStart time in nanoseconds:
formatstart
taken, val greedyitems constraint, method
end time.processtimens
printAt the end of processing formatfilename
printEnd time in nanoseconds: formatend
print
Elapsed time to process in nanoseconds.".formatfilenameendstart
print
Total value of items taken formatval
for item in taken:
if toPrint:
print item
testGreedycowstxt
testGreedycowstxt
testGreedycowstxt
testGreedycowstxt
Based on the above applications of testGreedy function, you need to answer the following questions:
Compare the process time results by running the greedy algorithm based on sorted on the two data sets, describe the difference. Are you able to complete the sorting operation on the second data set?
Compare the process time results by running the greedy algorithm based on insertionSort on the two data sets, describe the difference. Are you able to complete the sorting operation on the second data set? If you cannot get a result on the second data set, don't feel bad as it takes too long to get a result. I had to stop running the program without a result.
Explain the processingtime differences to run your greedy algorithm on the two data sets.
Feel free to change the function call arguments when applying testGreedy.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started