Python programming.
![10 points] Provide different code snippets for each of the following complexities. O(n) O( log(n))](http://img.homeworklib.com/questions/82425f90-301d-11eb-b1ab-ef4a94bc873f.png?x-oss-process=image/resize,w_560)
Provide different code snippets for each of the following complexities.
O(n2)
O(n)
O(1)
O( nlog(n) )
O( log(n) )
Code Snippet For O(n2 )
def printList(lst):
for i in lst:
for j in lst:
print(i," ",j)
-------------------------------------------------------------
Code Snippet For O(n )
def printList(lst):
for i in lst:
print(i)
--------------------------------------------------------------------------------
Code Snippet For O(1 )
def printMessage():
print("Hello)
-------------------------------------------------------------------
Code Snippet For O(nlogn )
def rec(lst):
l=len(lst)
if l==1:
return 1
return rec(lst[:l/2]+lst[l/2:])
--------------------------------------------------------------------------------------
Code Snippet For O(logn )
def power2Finder(x):
power=0
while(x>1):
x=x/2
power=power+1
return power
Python programming. Provide different code snippets for each of the following complexities. O(n2) O(n) O(1) O(...
Q5 Match the following operations to their corresponding worst case time complexities Operations Finding the nert larger item in a Hash Table Time Complexities од) O (log n) O(n) O(n log n) O(n2) o(n3) O(n + m) O(m logn) O((n +m) log n) O(n2+nm) Trying to remove a non-eristing item from a Hash Table 2 3Finding the previous smaller item in a possibly unbalanced BST Updating a previous value into a new value in an AVL Tree Sorting m edges...
For each of the below code snippets, identify the bounding function (the big O) of the number of times the indicated line is run (justify your answer briefly): int i = 1: while (i < n) { printf ("Insert difficult work here!") i = i + i: } for(i = 0: i < n: i++) { for (j = 0: j < n: j++) { for (k = 0: k < n: k++) { if(i==j && j==k) arr[i] [j] [k]...
Which of the following could be false? A. n2/(log(n)) = O(n2). B. (log n)1000 = O(n1//1000). C. 1/n = O(1/(log(n))). D. 2(log(n))^2 = O(n2). E. None of the above.
For each pair of functions determine if f(n) ? ?(g(n)) or f(n) ? ?(g(n)) or f(n) ? O(g(n)) and provide a proof as specified. For each of the following, give a proof using the definitions. 1. f(n) = log(n), g(n) = log(n + 1) 2. f(n) = n3 + nlog(n) ? n, g(n) = n4 + n 3. f(n) = log(n!), g(n) = nlog(n) 4. f(n) = log3(n), g(n) = log2(n) 5. f(n) = log(n), g(n) = log(log(n))
What is the order of the following growth function? t(n)= 5 nlog n + 20n +20 O(log n) Oin log n) o O(n2) 0(1)
for java
5. What is the Output? (2 x 5p each -10p) For cach of the following code snippets write down what will be printed on the screen. (a) for(int a-0; a<5; a++) for (int b-0 b
Compare the following pairs of functions f, g. In each case, say whether f- o(g) f-w(g), or f = Θ(g), and prove your claim. 157. f(n) -100n+logn, gn) (logn)2. 158,介f(n) = logn, g(n) = log log(n2). 159. . f(n)-n2/log n, g(n) = n(log n)2. 160·介介f(n)-(log n)106.9(n)-n10-6 . 161. (n)logn, g(n) (log nlog n 162. f(n) n2, gn) 3.
Compare the following pairs of functions f, g. In each case, say whether f- o(g) f-w(g), or f = Θ(g), and prove...
Exercise 1: For each of the following high-level language code snippets, write the SRO assembly code. Assume that the variables A, B, C, X. are in memory locations MA, MB, MC, MX, respectively. a) XA+ 2B- 4C; b) if (A <0) else if (A> 0) else c) for (int i 1; 10; i++) X A+B+C (Hint: Use branch instructions to set up the loop)
Extensively Compare the Following Programming Languages (Provide Strengths and Weaknesses of Each Programming Language) and Provide Brief Note of Each Programming Language. C# Java PHP Python Ruby
What is the range of input sizes for the following time complexities to compute an answer in no more than 1 second? 1 to ____ for each: Solving for max possible value of n to produce an answer in 1 second O(lgn) O(square-root(n)) O(n) O(n2) O(n3)