Created
May 15, 2021 17:30
-
-
Save Park-Developer/6572365dfe1bc154a0ef51dce093d518 to your computer and use it in GitHub Desktop.
binary search using recursion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 재귀함수 | |
def binary_search_rec(seq, target, low,high): | |
if low > high: | |
return None | |
mid = (low+high)//2 | |
if target == seq[mid]: | |
return mid | |
elif target<seq[mid]: | |
return binary_search_rec(seq, target, low,mid-1) | |
else: | |
return binary_search_rec(seq, target, mid+1,high) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment