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
26 changes: 26 additions & 0 deletions searches/meta_binary_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
def meta_binary_search(arr, target):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file searches/meta_binary_search.py, please provide doctest for the function meta_binary_search

Please provide return type hint for the function: meta_binary_search. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: arr

Please provide type hint for the parameter: 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():

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file searches/meta_binary_search.py, please provide doctest for the function main

Please provide return type hint for the function: main. If the function does not return a value, please provide the type hint as: def function() -> None:

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()