Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment 1 For this assignment, you are to work in groups of 2 or 3 . This assignment should provide you with experience in the

Assignment 1
For this assignment, you are to work in groups of 2 or 3. This assignment should
provide you with experience in the analysis of algorithms.
What to include in your submission:
One .zip folder named appropriately1
containing:
o A PDF containing your answers to questions #2- #9.
o A Python file and a C file. Make sure each programs header (block)
comment includes your name.
Complete the following:
1.(2 marks) You are given a Python program, Assignment1.py, which will allow
you to perform experimental analysis of two algorithms which you will need to code.
a. Read the starter code to understand what it does.
b. Complete the program by writing the code for the two functions
prefix_averages1, and prefix_averages2 given the pseudocode
provided at the end of this document in Appendix A. Run the program on
small input sizes to ensure the functions execute as expected. For example, if
n =5, and your input array is [30,43,3,5,9], the prefix averages computed
would be: [30,36.5,25.33,20.25,18]. Please note: you are free to add any
other code to the program to help you during testing.
2.(2 mark) Once you are sure your program works, you are now ready to perform
experimental analysis on large input sizes. Decide on an appropriate initial input
size, n1, but keep in mind that the program will also execute on input sizes n2=2n1,
n3=2n2, n4=2n3, and n5=2n4.(So if n1 is 1000000, then n5 would be 16000000.)
a. For each function, record the times you obtained in a table like the one shown
below: (Note that the starter code is set up such that for each input size, the
algorithm will execute 3 times.)
1 Check the Class Plan for Assignment submission requirements
Input Size Run #1 Run #2 Run #3 Average Execution Time (sec)
n1=
n2=
n3=
n4=
n5=
Please note the following:
If your timings are erratic (e.g.0s or there is no clear increase in
time with respect to input size), try starting with a larger input size.
The goal is to slow the program down enough to be able to
determine how time grows as the input size grows.
You are not required to use the same initial input size for both
functions.
b. Plot the average running times obtained in part (a) as a function of n as scatter
plots on a linear scale for each algorithm.
3.(2 marks) For each function - prefix_averages1 and prefix_averages2- complete the
table given below to help you determine the growth of running time with respect to
the size of the input. Clearly state the experimental growth rate of the function given
your execution times: does it look more like ()(
2
)?
Input size Average
Execution
time in ms
(as determined
by
experiment)
Actual Time
Increase Ratio:
Calculate
1
Time increase
factor if O(n):
Calculate
1
Time increase
factor if O(n2
):
Calculate
2
1
2
n1= t1= N/A N/A N/A
n2= t2=
n3= t3=
n4= t4=
n5= t5=
4.(6 marks) Repeat Questions #1- #3 above using the C file, Assignment1.c, as
your starting point.
5.(1 mark) Given the experimental analysis you performed for prefix_averages1
and prefix_averages2 using Python and C, do the experimental growth rates
align with the theoretical growth rates of these 2 algorithms? If not, please provide
possible reasons for the discrepancies.
6.(3 marks) Al Gorythm, who is well versed in Pythons built-in functions, claims the
prefix averages algorithm could be improved if one uses Pythons built-in mean
function2
. The result is prefix_averages3 which is also given in Appendix A.
prefix_averages3 produces the correct output using fewer lines than the other
two versions, yet how does this version compare to prefix_averages1 and
prefix_averages2 in terms of growth rate? Add code to the Python program to
include prefix_averages3. Perform experimental analysis for this new version
as you did for prefix_averages1 and prefix_averages2 and report
your findings. Explain why or why not Als algorithm is the best of the three versions.
7.(2 marks) Assume prefix_averages1 on an input size of n =500000(five
hundred thousand) takes 3 minutes. Given that time, what do you predict the
execution time to be when the input size grows to 13n (i.e.,6500000)? Justify your
prediction.
8.(2 marks) Assume prefix_averages2 on an input size of n =500000000(500
million) takes 3.5 seconds. Given that time, what do you predict the execution time to
be when the input size grows to 13n (i.e.,6500000000)? Justify your prediction.

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

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

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

explain how organizations can promote a positive safety climate.

Answered: 1 week ago

Question

Explain the steps involved in training programmes.

Answered: 1 week ago

Question

What are the need and importance of training ?

Answered: 1 week ago