Escolar Documentos
Profissional Documentos
Cultura Documentos
Tempo Linear
Classificao e Pesquisa de
Dados
Aula 10
Classificao em Tempo Linear O(n): Counting Sort,
Radix Sort e Bucket Sort
UFRGS
Principais Algoritmos
INF01124
Counting sort
Radix sort
Bucket sort
Classificao de Dados em
Tempo Linear
n
n
O algoritmo estvel
2
Counting Sort
Exemplo (Cont.)
C[A[j]] C[A[j]] - 1;
end
for i 2 to k
do C[i] C[i] + C[i-1];
C[A[j]] C[A[j]] - 1;
end
end
VERIFICAR
Counting Sort
Exemplo
for i 2 to k
do C[i] C[i] + C[i-1];
for j length[A] downto 1 do
begin
4 C
J=5
J=4
J=2
B 1 1
B 1 1
1
1
J=3
J=1
for i 1 to length[A]
do C[A[i]] C[A[i]] + 1;
J=6
for i 1 to length[A]
do C[A[i]] C[A[i]] + 1;
3
4
B 1 1 3 3 4
8
8
8
C 2
C 1
C 1
C 1
C 0
C 0
4 6
57
C 0
Exerccios
1
2
1
B[C[A[j]]] A[j];
C[A[j]] C[A[j]] - 1;
end
end
6
Princpio de classificao
n
n
n
11
Exerccios
BOI
329
720
720
329
827
SIM
457
355
329
355
501
COM
657
436
436
436
489
XIS
839
457
839
457
263
MEL
436
657
355
657
012
CEM
720
329
457
720
575
LAR
355
839
657
839
10
12
Princpio de classificao
n
15
Bucket Sort
Exemplo
B
.78
.17
.12
.17
.39
.21
.23
.26
.39
.72
.68
6
7
8
.94
.21
.12
.23
10
.68
4
5
.26
.72
.78
/
.94
14
16