Def linear search(list, item): for n in range(len(list))


Download 1.44 Mb.
Sana08.03.2023
Hajmi1.44 Mb.
#1252465
Bog'liq
21.02.2023


21.02.2023
def linear_search(list, item):
for n in range(len(list)):
if list[n]==item:
return n
return None
def binary_search(list, item):
low=0
high=len(list)-1
while low<=high:
mid=(low+high)//2
guess=list[mid]
if guess==item:
return mid
if guess>item:
high=mid-1
else:
low=mid+1
return None
myList1=[1,3,4,6,7,8,10,12,23]
print(linear_search(myList1,11))
print(binary_search(myList1,11))

myList1=[1,3,4,6,7,8,10,12,23]


print(linear_search(myList1,12))
print(binary_search(myList1,12))

myList1=[1,3,4,6,7,8,10,12,23]


print(linear_search(myList1,23))
print(binary_search(myList1,23))

28.02.2023
Mavzu: for sikl operatori bilan ishlash
range(stop)

range(start, stop)



range(start, stop, step)

a va b sonlar orasidagi sonlar.

S=1+1/2+1/3+… 1/n yig’indini hisoblash.

S=(n+1)^2 +(n+2)^2+…+(n+n)^2

S=1,1-1,2+1,3-1,4+…+

S=1!+2!+3!+…+n!


O’zida n ta fibonachi sonni chiqaring.
Download 1.44 Mb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling