Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Outline the employee's role in the succession management process.

Answered: 1 week ago

Question

What is the principle of thermodynamics? Explain with examples

Answered: 1 week ago

Question

3. You can gain power by making others feel important.

Answered: 1 week ago

Question

Write down the circumstances in which you led.

Answered: 1 week ago