Skip to content

Instantly share code, notes, and snippets.

@PaperDevil
Last active February 2, 2020 18:13
Show Gist options
  • Select an option

  • Save PaperDevil/53be5954c6e9579c6712f23b0525d1b9 to your computer and use it in GitHub Desktop.

Select an option

Save PaperDevil/53be5954c6e9579c6712f23b0525d1b9 to your computer and use it in GitHub Desktop.

Revisions

  1. PaperDevil revised this gist Feb 2, 2020. No changes.
  2. PaperDevil revised this gist Feb 2, 2020. No changes.
  3. PaperDevil created this gist Feb 2, 2020.
    10 changes: 10 additions & 0 deletions binary_search.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    def binary_search(area, item):
    mid = len(area) // 2
    low, high = 0, len(area) - 1

    while low <= high:
    if area[mid] == item: return mid
    if item > area[mid]: low = mid + 1
    else: high = mid - 1
    mid = (low + high) // 2
    return None