pointsConsider this code def f (n,p): for i in range(n): for j in range(i,p): for k...
Question 18 CLO3 Analyze the following code and answer the questions that follow def F(n): If n <= 1: return n else: return F(n-1)+F(n-2) for i in range (n) print (F(i)) Result: 0 1 1 2 3 5 8 13 a. Write number of operations as a function when the code is execute b If n 7, what is the total number of operations? c. What is the complexity of the algorithm behind the code? (2 Marks) (2 Marks) (1...
find complexity Problem 1 Find out the computational complexity (Big-Oh notation) of the code snippet: Code 1: for (int i = n; i > 0; i /= 2) { for (int j = 1; j < n; j *= 2) { for (int k = 0; k < n; k += 2) { // constant number of operations here } } } Code 2: Hint: Lecture Note 5, Page 7-8 void f(int n) { if (n...
def number(n): result = 1 for i in range(1, n+1): result = result * i return result In the above code, what is the "parameter?"
PYTHON QUESTION Given the following function: def sort(A, n): for i in range (1, n): for j in range(i-1, -1,-1): if A[j + 1] > A[j]: t = A[j+1] A[j+1] = A[j A[j] = t What would the output be for the following array: A = [3, 10, 2, 8,15]; where n = 5; for each iteration of i (i.e. when i = 1, i=2, i=3, i=4)? A. 10, 3, 2, 8, 15 B....
Given the following code, find their big(O) for I in range of n: for j in range of n: for k in range of 10000: print(“test”) If an algorithm takes n3+1000n2+1000n2+9999 time, what is the Big O for this algorithm? Proof: O(nK) < O (2n), need to do some research on polynomial time and exponential time.
Consider the following pseudo-code: // Assume i, j, k are integers for i = 1 to n do for j = n-i+1 to n { k = 1; while (k*k <= j) { perform <op>; k = k + 1; } } Find an expression for f(n), the number of times is performed. Find g(n) so that f(n) is Θ(g(n)). Prove your answer.
For each code write the time complexity.
For each of the following pieces of code, write down the time complexity that the code will run in, choosing from O(1), O(log n), O(n), O(n log n), O(n^2): def something (n) for i in range (n) return n Big-O:_____ for i in range (n) for j in range (5) print (i*j) Big-O:______ for i in range (n) for j in range (n n/3, 9): print (i*j) Big-O:_____ for i in range (521313*2213*11);...
identify the code that sorts the numbers in descending order. def selection_sort(numbers): for i in range(len(numbers) - 1): index = i XXX temp = numbers[i] numbers[i] = numbers[index] numbers[index] temp for j in range(i + 1, len(numbers): if numbers[j] > numbers[index]: index اله for j in range(i - 1, len(numbers): if numbers[j] > numbers[index]: index j for j in range(i + 1, len(numbers)): if numbers[j] < numbers[index]: index j for j in range(i 1, len(numbers): if numbers [j] < numbers[index]:...
K = 4
Let X → Geometric (p) where p such that P (X > n) =t. and k is number of letters in your j
Let X → Geometric (p) where p such that P (X > n) =t. and k is number of letters in your j
Python, given a code in class i just need help with the third
bullet point ; using a and n (defined in the second picture of
python code) find the first digit for k! for k =1,...,n. you dont
have to type in all this code just help me write the code in the
first picture where it says: def benford(a):
b = [0 for d in range(1,10)]
#Do everthything in here
return b
2.2 Generating data In this assignment...