categories: computer science
Hello everyone,
Below you will find a video with a detailed explanation of the counting sort algorithm. Its operation, time complexity, and usefulness. Below you will also find ready-made code to copy if needed.
Code:
tab = [5, 3, 8, 2, 5, 9, 65, 4, 3, 2, 65, 3, 23]
def sort(tablica):
ile = [0] * (max(tab) + 1)
for i in range(len(tablica)):
ile[tablica[i]] += 1
posortowanaTablica = []
for j in range(len(ile)):
while ile[j] > 0:
ile[j] -= 1
posortowanaTablica.append(j)
return posortowanaTablica
print(sort(tab))
Video:
Thank you for reading!
Read more