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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started