structure ARRAY(value, index)
declare CREATE() ----> array
RETRIEVE(array, index) ----> value
STORE(array, index, value) ----> array
for all A perteneciente a array
i, j perteneciente a index
x perteneciente a value
let
RETRIEVE(CREATE,i) ====> error
RETRIEVE(STORE(A,i,x),j) ====> if EQUAL(i,j) then x else RETRIEVE(A,j)
end
end ARRAY
Donde :
F U N C I O N E S A R R E G L O S
( Matematicas ) ( Informatica )
..................>..................... ..................>.....................
. . . .
. .............>............... . . .............>............... .
. . . . . . . .
*-------------------* *-------------------* *-------------------* *-------------------*
| . . | | . . | | . . | | . . |
| . . | ..|...x x x x x | | . . | ..|...x x x x x |
| x x x....|..>... | | | x x x....|..>... | |
| | | x x x x x | | | | x x x x x |
| | | | | | | |
| | | x x x x x | | | | x x x x x |
| | | | | | | |
| x x......|..>... | x x x x x | | x x......|..>... | x x x x x |
| . | . | | | . | . | |
| .............|..>....|...x x x x x | | .............|..>....|...x x x x x |
| | | | | | | |
| | | x x x x x | | | | x x x x x |
| x x x....|..>... | | | x x x....|..>... | |
| . . | ..|...x x x x x | | . . | ..|...x x x x x |
| . . | | . . | | . . | | . . |
*-------------------* *-------------------* *-------------------* *-------------------*
. . . . . . . .
. .............>.................. . . .............>.................. .
. . . .
..................>..................... ..................>.....................
D O M I N I O C O D O M I N I O I N D E X S E T V A L U E S E T
Arreglos de 1 dimensión ( indice1 ) ( i1 )
Arreglos de 2 dimensiones ( indice1, indice2 ) ( i1, i2 )
.......................
Arreglos de n dimensiones ( indice1, indice2, .........., indicen ) ( i1, i2, ..........., in )
M ( j ) ------|---------------------------------------------------|------>
M ( m:v ) m v j
A ( i1 ) -----------------|----------------------|------------------------>
A ( l1:u1 ) l1 u1 i1
Funcion j = f(i1) = m + ( i1 - 1 )
A ( i1, i2 ) ----------|------------------------------------|----------------->
A ( l1:u1, l2:u2 ) l2 u2 i2
Funcion j = f( i1, i2 ) = m + ( i1 - 1 ) u2
+ ( i2 - 1 )
A ( i1, i2, i3 ) ----------------------------|-------------------------|---------->
A ( l1:u1, l2:u2, l3:u3 ) l3 u3 i3
Funcion j = f( i1, i2, i3 ) = m + ( i1 - 1 ) u2u3
+ ( i2 - 1 ) u3
+ ( i3 - 1 )
A ( i1, i2, .........., in ) -------------------|---------------------|----------------------->
A ( l1:u1, l2:u2, .........., ln:un ) in un in
Funcion j = f( i1, i2, i3, ..., in ) = m + ( i1 - 1 ) u2u3...un
+ ( i2 - 1 ) u3u4...un
+ ( i3 - 1 ) u4u5...un
+ ....................
+ ( in - 1 )
Ejemplo de 1 dimension
A ( i1 )
A ( l1:u1 )
A ( 3:7 )
Cantidad de elementos = ( u1 - l1 + 1 ) =
( 7 - 3 + 1 ) =
5 elementos
Si m1 = 1000 luego v1 = m1 + cantidad de elementos - 1 = 1000 + 5 - 1 = 1000 + 5 -1 = 1004
Ejemplo de 4 dimensiones
A ( i1, i2, i3, i4 )
A ( l1:u1, l2:u2, l3:u3, l4:u4, )
A ( 4:5, 2:4, 1:2, 3:4, )
Cantidad de elementos = ( u1 - l1 + 1 ) * ( u2 - l2 + 1 ) * ( u3 - l3 + 1 ) * ( u4 - l4 + 1 ) =
( 5 - 4 + 1 ) * ( 4 - 2 + 1 ) * ( 2 - 1 + 1 ) * ( 4 - 3 + 1 ) =
24 elementos
Si m1 = 1000 luego v1 = m1 + cantidad de elementos - 1 = 1000 + 24 - 1 = 1000 + 24 -1 = 1023
Arreglos de 2 dimensiones ( indice1, indice2 )
Ordenamiento por filas
*----*----*----*----*
| 00 | 01 | 02 | 03 |
*----*----*----*----* *----*----*----*----*----*----*----*----*----*----*----*----*
| 04 | 05 | 06 | 07 | ------> | 00 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 |
*----*----*----*----* *----*----*----*----*----*----*----*----*----*----*----*----*
| 08 | 09 | 10 | 11 |
*----*----*----*----*
Ordenamiento por columnas
*----*----*----*----*
| 00 | 01 | 02 | 03 |
*----*----*----*----* *----*----*----*----*----*----*----*----*----*----*----*----*
| 04 | 05 | 06 | 07 | ------> | 00 | 04 | 08 | 01 | 05 | 09 | 02 | 06 | 10 | 03 | 07 | 11 |
*----*----*----*----* *----*----*----*----*----*----*----*----*----*----*----*----*
| 08 | 09 | 10 | 11 |
*----*----*----*----*
Ordenamiento por arreglos
*----* *----*
| --|--------> | 00 | ( fila 0 )
*----* *----*
| --|-----+ | 01 |
*----* | *----*
| --|--+ | | 02 |
*----* | | *----*
| | | 03 |
| | *----*
| |
| | *----*
| +--> | 04 | ( fila 1 )
| *----*
| | 05 |
| *----*
| | 06 |
| *----*
| | 07 |
| *----*
|
| *----*
+-----> | 08 | ( fila 2 )
*----*
| 09 |
*----*
| 10 |
*----*
| 11 |
*----*
Observar que el caso de ordenamiento por arreglos la variable apunta a un
arreglo de arreglos. Si bien el arreglo multidimensional de dos dimensiones
puede definirse como integer[][] numeros = new integer[3][4], donde existen
3 filas y 4 columnas, numeros[i], variando i de 0 a 2, determinan las filas,
y numeros[i][j], variando i de 0 a 2 y j de 0 a 3, determinan cada celda.
En la disposicion de ordenamiento por arreglos, conmutar una fila por otra,
es tan economico como conmutar un apuntador de fila por otro. En las otras
disposiciones es mucho mas complejo.
Usuario
*------------------------------------------------------------*
| |
| Funciones Secundarias |
| |
| |
| *---------------------------------* |
| | | |
| | Funciones Primitivas | |
| | | |
| | | |
| | *-------* | |
| | | | | |
| | | Datos | | |
| | | | | |
| | *-------* | |
| | | |
| | | |
| | | |
| | | |
| *---------------------------------* |
| |
| |
| |
| |
*------------------------------------------------------------*
|<------------------ Numero Fijo de Componentes ( n ) ----------------->|
*-----------------------------------------------------------------------*
| | |X| | |X|X|X| | | | | |X|X| | | |X|X|X|X|X|X| | | | |X|X| | | | | | |
*-----------------------------------------------------------------------*
A
|
Indice ( 0, n-1 ) --------+ X = Componentes ( Todos del mismo Tipo )
crearArreglo(arreglo)
recuperarComponente(arreglo, posicion, componente)
almacenarComponente(arreglo, posicion, componente, arreglo)
crearArreglo(capacidad, arreglo)
averiguarCapacidad(arreglo, capacidad)
ejecutarCopia(arreglo, arreglo)
ejecutarLlenado(arreglo, componente, arreglo)
ejecutarLlenadoRango(arreglo, posicionDesde, posicionHasta, componente arreglo)
ejecutarClasificacion(arreglo, arreglo)
ejecutarClasificacionRango(arreglo, posicionDesde, posicionHasta, arreglo)
ejecutarBusqueda(arreglo, componente, posicion)
ejecutarBusquedaRango(arreglo, posicionDesde, posicionHasta, componente, posicion)
ejecutarIgualdad(arreglo, arreglo, boolean)
Las variables en negrita son variables de salida.
Los arreglos son estructuras de datos que viven en memoria principal de la computadora y la característica fundamental, de la memoria principal, es que el acceso a cualquier posición de memoria, es constante, ya sea para almacenar datos o recuperar datos de una posición de memoria. Estamos entonces ante una estructura de datos que responde con un órden de magnitud O(1) para almacenar y recuperar datos de un elemento del arreglo. Claro está que el espacio que demanda un arreglo, es de un órden de magnitud O(n), o sea lineal.
R1 R2 R3 Ri Rn
........------------------.......--------.......--------.......
| | | | | | | |
........------------------.......--------.......--------.......
Indice int int float int boolean int string Registros
*----* *----* *----------* *----* *--------* *----* *-------------------*
0 | | | | | | | | | | | | | | R1
*----* *----* *----------* *----* *--------* *----* *-------------------*
1 | | | | | | | | | | | | | | R2
......*----*.*----*.*----------*.*----*.*--------*.*----*.*-------------------*......
2 . | | | | | | | | | | | | | | . slot R3
......*----*.*----*.*----------*.*----*.*--------*.*----*.*-------------------*......
3 | | | | | | | | | | | | | | R4
*----* *----* *----------* *----* *--------* *----* *-------------------*
4 | | | | | | | | | | | | | | R5
*----* *----* *----------* *----* *--------* *----* *-------------------*
5 | | | | | | | | | | | | | | R6
*----* *----* *----------* *----* *--------* *----* *-------------------*
. . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
*----* *----* *----------* *----* *--------* *----* *-------------------*
n - 3 | | | | | | | | | | | | | | Rn-2
*----* *----* *----------* *----* *--------* *----* *-------------------*
n - 2 | | | | | | | | | | | | | | Rn-1
*----* *----* *----------* *----* *--------* *----* *-------------------*
n - 1 | | | | | | | | | | | | | | Rn
*----* *----* *----------* *----* *--------* *----* *-------------------*