Question: Please help with this data structure problem! updated Exercise 1- Write a tester program that counts and displays the number of iterations of the following

Please help with this data structure problem! updated

Exercise 1- Write a tester program that counts and displays the number of iterations of the following loop: while problemSize > 0: problemSize = problemSize // 2

Exercise 2- Run the program you created in Exercise 1 using problem sizes of 1,000, 2,000, 4,000, 10,000, and 100,000. As the problem size doubles or increases by a factor of 10, what happens to the number of iterations?

Example:

Consider a simple, if unrealistic, example. The following program implements an algo- rithm that counts from 1 to a given number. Thus, the problem size is the number. You start with the number 10,000,000, time the algorithm, and output the running time to the terminal window. You then double the size of this number and repeat this process. After five such increases, there is a set of results from which you can generalize. Here is the code for the tester program:

""" File: timing1.py Prints the running times for problem sizes that double, using a single loop. """ import time

problemSize = 10000000 print("%12s%16s" % ("Problem Size", "Seconds")) for count in range(5):

start = time.time() # The start of the algorithm

work = 1 for x in range(problemSize):

work += 1

work -= 1 # The end of the algorithm elapsed = time.time() - start

print("%12d%16.3f" % (problemSize, elapsed)) problemSize *= 2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!