Question: Please analyse each function and explain step by step,give an input and output ,explain why ? and write complexity . (1)def maximum(lst): lower = 0

Please analyse each function and explain step by step,give an input and output ,explain why ? and write complexity .

(1)def maximum(lst):

lower = 0

upper = len(lst)-1

while lower < upper :

if lst[lower]>lst[upper]:

upper=upper -1

else:

lower = lower +1

return lst[lower]

(2) input a list of positive integers lst with a length of at least two

def fill_gaps(lst):

lst.sort()

i = 0

while i < len(lst) -1 :

if lst[i+1]> lst[i]+1

lst.insert (i +1 , Lst[i] +1)

i+=1

return lst

(3)def mystery(lst):

total = 0

n = len(lst)

for i in range(n):

for j in range(i+1,n):

total += sum (lst[i:j])

return total

(4)def mystery (lst):

res =0

n= len(lst)

i =0

while i < n:

j =n

while j >=1:

res += lst [j]

j = j//2

i +=1

return res

(5)def mystery(lst):

n= len(lst)

s=0

left =0

right = n

while left <= right :

s +=sum (lst[left:right])

left += 1

right -= 1

return s

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!