From bf493d486c458ee961e12808d837c0dbfab6aee5 Mon Sep 17 00:00:00 2001 From: RITIKA CHAUBE Date: Mon, 8 Jun 2026 16:13:24 -0400 Subject: [PATCH] Done with Precourse 2 --- Exercise_1.py | 19 ++++++++++++++--- Exercise_2.py | 27 +++++++++++++++++++------ Exercise_3.py | 27 ++++++++++++++++++++----- Exercise_4.py | 49 +++++++++++++++++++++++++++++--------------- Exercise_5.py | 56 +++++++++++++++++++++++++++++++++++++++++++++++---- 5 files changed, 144 insertions(+), 34 deletions(-) diff --git a/Exercise_1.py b/Exercise_1.py index 3e6adcf4..06de3c22 100644 --- a/Exercise_1.py +++ b/Exercise_1.py @@ -3,11 +3,24 @@ # It returns location of x in given array arr # if present, else returns -1 + +# Time and Space Complexity +# Time Complexity is O(log N) where N is the nuber of elements that are present in the given arr +# Space Complexity is O(1) as the variables are constant irrespective of the array size def binarySearch(arr, l, r, x): #write your code here + while l<=r: + mid=(l+r)//2 + if arr[mid]==x: + return mid + elif x1: + mid=len(arr)//2 + left=arr[:mid] + right=arr[mid:] + + mergeSort(left) + mergeSort(right) + + i=j=k=0 + while i=0: + h=stack[top] + top=top-1 + l=stack[top] + top=top-1 + + p=partition(arr,l,h) + + if l