Counting sort
Në shqip: Renditja me numërim
ShpjegimiSQ
Kur vlerat janë numra të vegjël (p.sh. notat 1–5), counting sort thjesht numëron sa herë shfaqet secila dhe i shkruan me radhë. Punon në O(n) — më shpejt se çdo renditje me krahasime.
EnglishEN
When values are small numbers (e.g. grades 1–5), counting sort just counts how often each appears and writes them out in order. It runs in O(n) — faster than any comparison sort.
Si ta mendosh
Si numërimi i votave: s'i rendit fletët, thjesht numëron sa vota mori secili.
Lexoje në anglisht
Like counting votes: you don't sort the ballots, you just count how many each candidate got.
Shembull kodipython
notat = [5, 3, 5, 1, 4, 3]
numri = [0] * 6
for n in notat: numri[n] += 1
print([n for n in range(6) for _ in range(numri[n])])