Skip to content

Instantly share code, notes, and snippets.

@dariodip
Last active March 20, 2021 13:32
Show Gist options
  • Save dariodip/f8110d1262241e3fed64f17e67ec8f76 to your computer and use it in GitHub Desktop.
Save dariodip/f8110d1262241e3fed64f17e67ec8f76 to your computer and use it in GitHub Desktop.

Revisions

  1. dariodip revised this gist Mar 20, 2021. 1 changed file with 13 additions and 13 deletions.
    26 changes: 13 additions & 13 deletions binary-search.py
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,13 @@
    from math import floor
    def bsa(l, n, t):
    L = 0
    R = n -1
    while L <= R:
    m = floor((L + R) / 2)
    if A[m] < T:
    L = m+1
    elif A[m] > T:
    R = m-1
    else:
    return m
    return -1
    from math import floor
    def bsa(a, n, t):
    lft = 0
    rgt = n -1
    while lft <= rgt:
    m = floor((lft + rgt) / 2)
    if a[m] < t:
    lft = m+1
    elif a[m] > t:
    rgt = m-1
    else:
    return m
    return -1
  2. dariodip created this gist Mar 20, 2021.
    13 changes: 13 additions & 0 deletions binary-search.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    from math import floor
    def bsa(l, n, t):
    L = 0
    R = n -1
    while L <= R:
    m = floor((L + R) / 2)
    if A[m] < T:
    L = m+1
    elif A[m] > T:
    R = m-1
    else:
    return m
    return -1