arr = [11,22,33,44,55,66,77]
# [1 ]: l . t m . . r
# [2 ]: l m tr x x x x
# [3 ]: x x ltr x x x x
target = 33
l, r = 0, len(arr)-1 # r=6
ctr=0
found=False
while l<=r:
ctr+=1
print(f"[step {ctr}]: {arr[l:r+1]}")
m=(l+r)//2
if target == arr[m]:
found=True
print(f"Target:[{target}] found, index:[{m}] in {ctr} steps!")
break
elif target>arr[m]:
l=m+1
elif target<arr[m]:
r=m-1
if not found:
print(f"Target:[{target}] not found in {ctr} steps!")
[step 1]: [11, 22, 33, 44, 55, 66, 77]
[step 2]: [11, 22, 33]
[step 3]: [33]
Target:[33] found, index:[2] in 3 steps!
