atom-community / atom-community/atom-script

Doesnt compile for a simple binary search code. How do i fix this?

Open
#1,734 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
730
Forks
264
PR merge metrics
No merged PRs in 30d

Description

`#NON RECURSIVE BINARY SEARCH
def non_rec_bs(list, ele):
low=0
high = len(list)-1

while(low<=high):
mid=(low+high)//2
if list[mid] == ele:
print("The element was found at index", mid)
return True
elif ele>list[mid]:
low=mid+1
else:
high=mid-1

print("The element is not in the List")
return False

#RECURSIVE BINARY SEARCH
def rec_bs(list, ele, low, high):
if low>high:
print("Element is not in the list")
return False
else:
mid=(low+high)//2
if ele==list[mid]:
print("Element is at index", mid)
return True
elif ele>list[mid]:
return rec_bs(list, ele, mid+1, high)
else:
return rec_bs(list, ele, low, mid-1)

list=[1,5,6,8,10,56,500,705]
ele=int(input("Enter element to search for:"))
non_rec_bs(list,ele)
rec_bs(list,ele,0,len(list))
`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.