Chapter 3 (Time Complexity) (30 points) Write down the time complexity (The big-O) of the following algorithms and show
Posted: Fri Jul 01, 2022 5:45 am
Question 1: (40 points) Implement a function with signature transfer(5, T) that transfers all elements from stack S onto stack T, so that the element that starts at the top of S is the top of stack T as well, and the element at the bottom of 5 ends up at the bottom of too Question 2: (30 points) Implement a function that reverses a list of elements of a stack (Hint: Use a queue)
Chapter 3 (Time Complexity) (30 points) Write down the time complexity (The big-O) of the following algorithms and show the time for each step like what we done in lecture: Algorithm def Function1(arr,n,x): for i in range(0, n): if (arr-x) return i return-1 def Function2(ar): n-len(arr) for i in range(n): swapped-False for j in range(0, n-i-1) if arri]> anj+1]: am], arri+1]-arr[j+1], arr[j] swapped - True if swapped-False: break def binary search(arr, x): low -0 high-len(arr) - 1 mid-0 while low high mid (high+low) // 2 if arr[mid] <x low-mid + 1 elif arr[mid]>x high-mid-1 else: return mid return-1 Chapter (5 and 6) Completity