Ordenamiento por Selección

Recibe este nombre porque selecciona para intercambiar valor, entre dos elementos, a aquellos que rompan la secuencia "el elemento actual debe ser menor o igual que el elemento siguiente".

Diagrama de Flujo que explica el Ordenamiento por Selección

El Ordenamiento se efectua de la sig. forma
Valores Iniciales: n = 6 i = 1 . . . n-1, j = i+1 . . . n

Para i = 1; t = x(i) t = 3; p = i p = 1
    Para j = i+1 j = 2; x = {3, 21, 9, 8, 2, 1}
    ¿Es tx(j)? No t = x(j) t = 21;
                                 p = j p = 2

    Para j = 3; t = 21, x = {3, 21, 9, 8, 2, 1}
    ¿Es tx(j)? No t = x(j) t = 9;
                                 p = j p = 3

    Para j = 4; t = 9, x = {3, 21, 9, 8, 2, 1}
    ¿Es tx(j)? No t = x(j) t = 8;
                                 p = j p = 4

    Para j = 5; t = 8, x = {3, 21, 9, 8, 2, 1}
    ¿Es tx(j)? No t = x(j) t = 2;
                                 p = j p = 5

    Para j = 6; t = 2, x = {3, 21, 9, 8, 2, 1}
    ¿Es tx(j)? No t = x(j) t = 1;
                                 p = j p = 6


¿Es p = i? No Intercambiar valor entre x(i) y x(p) x = {1, 21, 9, 8, 2, 3}

Para i = 2; t = x(i) t = 21; p = i p = 2
    Para j = i+1 j = 3; x = {1, 21, 9, 8, 2, 3}
    ¿Es tx(j)? No t = x(j) t = 9;
                                 p = j p = 3

    Para j = 4; t = 9, x = {1, 21, 9, 8, 2, 3}
    ¿Es tx(j)? No t = x(j) t = 8;
                                 p = j p = 4

    Para j = 5; t = 8, x = {1, 21, 9, 8, 2, 3}
    ¿Es tx(j)? No t = x(j) t = 2;
                                 p = j p = 5

    Para j = 6; t = 2, x = {1, 21, 9, 8, 2, 3}
    ¿Es tx(j)? Sí


¿Es p = i? No Intercambiar valor entre x(i) y x(p) x = {1, 2, 9, 8, 21, 3}

Para i = 3; t = x(i) t = 9; p = i p = 3
    Para j = i+1 j = 4; x = {1, 2, 9, 8, 21, 3}
    ¿Es tx(j)? No t = x(j) t = 8;
                                 p = j p = 4

    Para j = 5; t = 8, x = {1, 2, 9, 8, 21, 3}
    ¿Es tx(j)? Sí

    Para j = 6; t = 8, x = {1, 2, 9, 8, 21, 3}
    ¿Es tx(j)? No t = x(j) t = 3;
                                 p = j p = 6


¿Es p = i? No Intercambiar valor entre x(i) y x(p) x = {1, 2, 3, 8, 21, 9}

Para i = 4; t = x(i) t = 8; p = i p = 4
    Para j = i+1 j = 5; x = {1, 2, 3, 8, 21, 9}
    ¿Es tx(j)? Sí

    Para j = 6; t = 8, x = {1, 2, 3, 8, 21, 9}
    ¿Es tx(j)? Sí


¿Es p = i? Sí

Para i = 5; t = x(i) t = 21; p = i p = 5
    Para j = i+1 j = 6; x = {1, 2, 3, 8, 21, 9}
    ¿Es tx(j)? No t = x(j) t = 9;
                                 p = j p = 6

¿Es p = i? No Intercambiar valor entre x(i) y x(p) x = {1, 2, 3, 8, 9, 21}