Recursive Binary Search | Python

Implement recursive binary search in Python

def recursive_binary_search(arr,ele):

	if len(arr) == 0:
		return False

	else:
		mid = len(arr)/2

		if arr[mid] == ele:
			return True
		else:
			if ele < arr[mid]:
				return recursive_binary_search(arr[:mid], ele)
			else:
				return recursive_binary_search(arr[mid+1:], ele)

d = recursive_binary_search([1,2,3,4,5],22)
print d

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s