Question: 3 Worst-case Runtime Complexity Analysis (20 points) Determine the runtime complexity of the following functions. 3.1 Mystery function 'f' (5 points) 3.2 Mystery function 'g'

 3 Worst-case Runtime Complexity Analysis (20 points) Determine the runtime complexity

3 Worst-case Runtime Complexity Analysis (20 points) Determine the runtime complexity of the following functions. 3.1 Mystery function 'f' (5 points) 3.2 Mystery function 'g' (5 points) def f(head): # 1 is the head of a linked list of length n cur - head out = None while cur: lc = cur while lc: if not out: out - ListCell(cur.val, None) else: out - Listcell(cur.val, out.next) lc - lc.next cur - out.next out - None def g(1): # 1 is a python list of integers of length n s = len(1) while s > 1 : for i in range(e, len(1),s): 1[i] += 1 Ses // 2 -[] on) ] 0(n^2) i O(n^3) ] on log n) [] 0(n) [] on log n) [ ] 0(log n) - [] O(n^2) 1 3.3 Mystery function 'h' (5 points) 3.4 Mystery function 'i' (5 points) VNNN this function takes as input a number 'i'. For the runtime analysis we should consider the storage required to represent the number as the input size 'n'. Recall that a number i' requires o(log i)' bits to be represented. For instance, if '32' is passed as input then 'n - log 32 - 5 def h(i): # a number i t = i result - for j in range (2,t+1): if j>t: break while (t % j) == 0: t.tilj result.append() return result | def i(l): # a python list 1 low = 0 high - len(1) - 1 while low != high: if 1[low]

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!