Académique Documents
Professionnel Documents
Culture Documents
Algoritmos
Bubble Sort
Selection Sort
Insertion Sort
Quick Sort
1
Algoritmo de la Burbuja (bubblesort)
Algoritmo de la Burbuja
2
Complejidad Algoritmo Burbuja
void bubbleSort(int numbers[], int i j
array_size)
{ int i, j, temp; n-1 n-1
for (i = (array_size - 1); i >= 0; i--)
{ for (j = 1; j <= i; j++)
n-2 n-2
{ if (numbers[j-1] > numbers[j]) n-3 n-3
{ temp = numbers[j-1];
numbers[j-1] = numbers[j];
numbers[j] = temp; 0 0
}
}
} n 1 n
n(n + 1)
} total = k = k n = n
k =1 k =1 2
Algoritmo de la Burbuja
3
Algoritmo de Seleccin
0 6 1 4 9 2 5 3 8 7
01 6 4 9 2 5 3 8 7
0 1 2 4 9 6 5 3 8 7
0 1 2 3 9 6 5 4 8 7
0 12 3 4 6 5 9 8 7
0 1 2 3 4 5 6 9 8 7
0 1 2 3 4 5 6 9 8 7
0 1 2 3 4 5 6 7 8 9
4
Algoritmo Seleccin
5
Complejidad Algoritmo Seleccin
n 1 n n 1 n 1
n(n 1)
1 = (n i ) = k =
i =1 j =i +1 i =1 k =1 2
Algoritmo Insercin
6
Algoritmo de Insercin
8 6 1 4 9 2 5 3 0 7
6 8 1 4 9 2 5 3 0 7
16 8 4 9 2 5 3 0 7
1 4 6 8 9 2 5 3 0 7
1 4 6 8 9 2 5 3 0 7
1 24 6 8 9 5 3 0 7
1 2 4 5 6 8 9 3 0 7
1 2 3 4 5 6 8 9 0 7
0 1 2 3 4 5 6 8 9 7
7
Anlisis Algoritmo de Insercin
void Insertar(int A[], int n) Consideremos como
{ int i, j, x; barmetro la instruccin
for (i=1; i<n; i++) j>=0 y x<A[j]
{ x = A[i]; Para el valor i, en el peor
j = i-1; caso x = A[i] se tiene que
while((j>=0) && (x<A[j])) comparar con los valores
{ A[j+1] = A[j]; A[i-1], , A[0] (i veces)
j = j-1; Por tanto, el nmero total
} de operaciones a realizar
es:
A[j+1] = x;
} n
n(n + 1)
i =
} 1
i =1 2
Algoritmo QuickSort
8
Algoritmo QuickSort
Algoritmo QuickSort
9
Actividad
10