Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions BinarySearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import mysql.connector


def binsearch(arr, low, high, x):
if(low >= high):
mid = (low+high)//2
def binarysearch(arr, left, right, x):
if(left >= right):
mid = (left+right)//2
if(arr[mid] >x):
return binsearch(arr, low, mid-1,x)
return binarysearch(arr, left, mid-1,x)
elif(arr[mid] <x):
return binsearch(arr, mid+1, high,x)
return binarysearch(arr, mid+1, right,x)
elif(arr[mid] == x):
return mid
else:
Expand All @@ -26,7 +26,7 @@ def binsearch(arr, low, high, x):
arr = r_no.copy()
arr.sort()
x = int(input("Enter the Roll Number you want to search in the database:"))
x = binsearch(arr, 0, len(arr)-1, x)
x = binarysearch(arr, 0, len(arr)-1, x)

if (result!= -1):
print("The Roll No is found at the position: " + str(result+1) + " in the Database")
Expand Down