Question: Question 1 : Consider the following two implementations of a function that if given a list, lst , create and return a new list containing

Question 1:
Consider the following two implementations of a function that if given a list, lst, create and return a new list containing the elements of lst in reverse order.
def reverse1(lst): rev_lst =[]
i=0
while(i < len(lst)):
rev_lst.insert(0, lst[i])
i +=1 return rev_lst
def reverse2(lst): rev_lst =[]
i = len(lst)-1 while (i >=0):
rev_lst.append(lst[i])
i -=1 return rev_lst
If lst is a list of n integers,
1. Whatistheworstcaserunningtimeofreverse1(lst)?Explainofyour
answer.
2. Whatistheworstcaserunningtimeofreverse2(lst)?Explainofyour
answer.

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 Programming Questions!