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