Kiritish saralash
Dastur kodi :
#Kiritish saralash dasturi
import random
def kiritish(massiv):
for i in range(1, len(massiv)):
key = massiv[i]
j = i-1
while j >=0 and key < massiv[j] :
massiv[j+1] = massiv[j]
j -= 1
massiv[j+1] = key
massiv = []
for i in range(10):
i=random.randint(0,100)
massiv.append(i)
print("Tasodifiy sonlardan iborat massiv :",massiv)
kiritish(massiv)
print ("Kiritish saralangan massiv :",massiv )
Dastur natijasi (4 marta run qilingan):
Algoritm
|
Ma’lumotlar tuzilmasi
|
Vaqt bo’yicha murakkabligi
|
Qo’shimcha ma’lumotlar
|
|
|
Yaxshi
|
O’rta
|
Yomon
|
Yomon holatda
|
Tezkor saralash
|
Massiv
|
O(n log(n))
|
O(n log(n))
|
O(n2)
|
O(n)
|
Surish orqali saralash
|
Massiv
|
O(n log(n))
|
O(n log(n))
|
O(n log(n))
|
O(n)
|
Piramidali saralash
|
Massiv
|
O(n log(n))
|
O(n log(n))
|
O(n log(n))
|
O(1)
|
Pufakchali saralash
|
Massiv
|
O(n)
|
O(n2)
|
O(n2)
|
O(1)
|
Qo’yish orqali saralash
|
Massiv
|
O(n)
|
O(n2)
|
O(n2)
|
O(1)
|
Tanlash orqali saralash
|
Massiv
|
O(n2)
|
O(n2)
|
O(n2)
|
O(1)
|
Blokli saralash
|
Massiv
|
O(n+k)
|
O(n+k)
|
O(n2)
|
O(nk)
|
Razryad bo’yicha saralash
|
Massiv
|
O(nk)
|
O(nk)
|
O(nk)
|
O(n+k)
|
Do'stlaringiz bilan baham: |