Skip to content
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions DIRECTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,7 @@
* [Jump Search](searches/jump_search.py)
* [Linear Search](searches/linear_search.py)
* [Median Of Medians](searches/median_of_medians.py)
* [Meta Binary Search](searches/meta_binary_search.py)
* [Quick Select](searches/quick_select.py)
* [Sentinel Linear Search](searches/sentinel_linear_search.py)
* [Simple Binary Search](searches/simple_binary_search.py)
Expand Down
24 changes: 24 additions & 0 deletions searches/meta_binary_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
def meta_binary_search(arr, target):
low = 0
high = len(arr) - 1
while low <= high:
mid = (low + high) // 2
if arr[mid] == target:
return mid
elif arr[mid] < target:
low = mid + 1
else:
high = mid - 1
return -1

def main():
arr = [2, 5, 8, 12, 16, 23, 38, 56, 72, 91]
target = 23
result = meta_binary_search(arr, target)
if result != -1:
print("Element found at index: ", result)
else:
print("Element not found!")

if __name__ == "main":
main()