PYTHON this is an single assignment and i need a complete code of it. Half work
ID: 3869686 • Letter: P
Question
PYTHONthis is an single assignment and i need a complete code of it. Half work is already been done but where it says add your code here you have to add the code there ITS PYTHON AND DONE IN PYTHON
THIS IS THE CODE AND YOU HAVE TO FINISH IT. Inputing the code in the assignment where it says add your code here. The purpose of this assignment is to help you: Refresh knowledge on order of growth of running time and big-O notation. Learn how to write simple code to sort a list. Do a little bit study on different modules in python. 3. Background 3.1. Time complexity As computer science students, writing code is something you do every day. It is important to make sure we write efficient code. How do you know the code you have written is good enough? A good way is to find out the time complexity using the big-O notation. The big-O notation describes the order of growth of running times when input size increases. Note in the big-O notation, the running time considered is always the worst-case running time. NAME Constant time Linear time Quadratic time Cubic time GROWTH RATE O(n) O(n2) O(n')
Explanation / Answer
import time
import math
###Selection Sort
def selectionsort(L):
start = time.time()
###Add your code here
for i in range( len( L ) ):
least = i
for k in range( i + 1 , len( L ) ):
if L[k] < L[least]:
least = k
tmp = L[least]
L[least] = L[i]
L[i] = tmp
end = time.time()
return L,end - start
def sumksquare2(k):
start = time.time()
###Add your code here
total = 0;
i=1;
while i<=k:
total = total + i*i;
i=i+1
end = time.time()
return total,end - start
def sumksquare(k):
start = time.time()
###Add your code here
total = (k * (k + 1)*(2*k + 1 )) / 6
end = time.time()
return total,end - start
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.