= [11,22,33,44,55,66,77]
arr # [1 ]: l . t m . . r
# [2 ]: l m tr x x x x
# [3 ]: x x ltr x x x x
= 33
target = 0, len(arr)-1 # r=6
l, r =0
ctr=False
foundwhile l<=r:
+=1
ctrprint(f"[step {ctr}]: {arr[l:r+1]}")
=(l+r)//2
mif target == arr[m]:
=True
foundprint(f"Target:[{target}] found, index:[{m}] in {ctr} steps!")
break
elif target>arr[m]:
=m+1
lelif target<arr[m]:
=m-1
rif 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!