Download - COLAS DE PRIORIDAD
![Page 1: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/1.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
1
COLAS DE PRIORIDAD
Las colas de prioridad son estructuras de datos que resultan ser útiles en muchas aplicaciones informáticas.
![Page 2: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/2.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
2
COLAS DE PRIORIDAD
Las colas de prioridad son estructuras de datos que resultan ser útiles en muchas aplicaciones informáticas.
Es utila pensar en los valores de las claves asociados con los elementos como prioridades.
Así, las claves obedecen a un relación de orden total.
![Page 3: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/3.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
3
COLAS DE PRIORIDAD
Las colas de prioridad son estructuras de datos que resultan ser útiles en muchas aplicaciones informáticas.
Es útil pensar en los valores de las claves asociados con los elementos como prioridades.
Así, las claves obedecen a un relación de orden total.
Ejemplos:
Planificación de trabajos en un sistema multiusuario.
Simulación de sucesos discretos
Desarrollo de códigos de prefijos óptimos
![Page 4: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/4.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
4
COLAS DE PRIORIDAD
Las operaciones más importantes en un TDA de colas de prioridad se refieren aquellas que permiten repetidamente seleccionar el elemento de la cola de prioridad que tiene como clave el valor máximo (mínimo).
Esto conlleva a que una cola de prioridad debe soportar las siguientes operaciones:
![Page 5: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/5.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
5
COLAS DE PRIORIDAD
Las operaciones más importantes en un TDA de colas de prioridad se refieren aquellas que permiten repetidamente seleccionar el elemento de la cola de prioridad que tiene como clave el valor máximo (mínimo).
Esto conlleva a que una cola de prioridad P debe soportar las siguiente operaciones:
ColaPrioridad(T)
Insertar(P,x): añade el elemento x a la cola de prioridad
![Page 6: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/6.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
6
COLAS DE PRIORIDAD
Las operaciones más importantes en un TDA de colas de prioridad se refieren aquellas que permiten repetidamente seleccionar el elemento de la cola de prioridad que tiene como clave el valor mínimo (máximo).
Esto conlleva a que una cola de prioridad P debe soportar las siguiente operaciones:
ColaPrioridad(T)
Insertar(P,x): añade el elemento x a la cola de prioridad
EncontrarMin(P): Devuelve el elemento de P con la priridad con menor valor.
![Page 7: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/7.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
7
COLAS DE PRIORIDAD
Las operaciones más importantes en un TDA de colas de prioridad se refieren aquellas que permiten repetidamente seleccionar el elemento de la cola de prioridad que tiene como clave el valor mínimo (máximo).
Esto conlleva a que una cola de prioridad P debe soportar las siguiente operaciones:
ColaPrioridad(T)
Insertar(P,x): añade el elemento x a la cola de prioridad
EncontrarMin(P): Devuelve el elemento de P con la priridad con menor valor.
EliminarMin(P): Quite y devuelve el elemento con la priridad con menor valor.
![Page 8: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/8.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
8
Implementaciones de un TDA de Cola de Prioridad
•Arboles equilibrados (AVL, ROJO y NEGRO)
Permite las operaciones en O(log n).
Se mantiene la propiedad de ABB sin nesecidad.
Se añade costo adicional por las operaciones de equilibrio sin necesidad.
COLAS DE PRIORIDAD
![Page 9: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/9.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
9
Implementaciones de un TDA de Cola de Prioridad
•Arboles equilibrados (AVL, ROJO y NEGRO)
Permite las operaciones en O(log n).
Se mantiene la propiedad de ABB sin nesecidad.
Se añade costo adicional por las operaciones de equilibrio sin necesidad.
•Montículos Binarios Montículos-d
COLAS DE PRIORIDAD
![Page 10: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/10.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
10
Implementaciones de un TDA de Colad de Prioridad
•Arboles equilibrados (AVL, ROJO y NEGRO)
Permite las operaciones en O(log n).
Se mantiene la propiedad de ABB sin nesecidad.
Se añade costo adicional por las operaciones de equilibrio sin necesidad.
•Montículos Binarios, Montículos-d
•Montículos a la izquierda
COLAS DE PRIORIDAD
![Page 11: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/11.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
11
Implementaciones de un TDA de Colad de Prioridad
•Arboles equilibrados (AVL, ROJO y NEGRO)
Permite las operaciones en O(log n).
Se mantiene la propiedad de ABB sin nesecidad.
Se añade costo adicional por las operaciones de equilibrio sin necesidad.
•Montículos Binarios, Montículos-d
•Montículos a la izquierda
•Montículos oblicuos. ( Estructura amortizada)
COLAS DE PRIORIDAD
![Page 12: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/12.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
12
Implementaciones de un TDA de Colad de Prioridad
•Arboles equilibrados (AVL, ROJO y NEGRO)
Permite las operaciones en O(log n).
Se mantiene la propiedad de ABB sin nesecidad.
Se añade costo adicional por las operaciones de equilibrio sin necesidad.
•Montículos Binarios
•Montículos a la izquierda
•Montículos oblicuos. ( Estructura amortizada)
•Colas binomiales, colas binomiales perezosas, colas Fibonacci
COLAS DE PRIORIDAD
![Page 13: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/13.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
13
MONTÍCULOS BINARIOS
Es una estructura de datos simple que da soporte eficiente al TDA de colas de prioridad.
Un montículo binario (o simplemente montículo o heap) es un árbol binario semicompleto en el que el valor de la clave almacenada en cualquier nodo es menor o igual que los valores claves de sus hijos
![Page 14: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/14.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
14
MONTÍCULOS BINARIOS
•Propiedad de ordenamiento parcial: la clave almacenada en cualquier nodo es menor o igual que los valores claves de sus hijos.
Un Monticúlo binario entonces debe satisfacer dos propiedades
2
8 3
10 16 7 18
13 15
![Page 15: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/15.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
15
MONTÍCULOS BINARIOS
•Propiedad de ordenamiento parcial: la clave almacenada en cualquier nodo es menor o igual que los valores claves de sus hijos.
•Propiedad de la forma: árbol binario semicompleto
Nodos hojas, sin huecos
2
8 3
10 16 7 18
13 15
![Page 16: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/16.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
16
MONTÍCULOS BINARIOS
•Propiedad de ordenamiento parcial: la clave almacenada en cualquier nodo es menor o igual que los valores claves de sus hijos.
•Propiedad de la forma: árbol binario semicompleto
Nodos hojas, sin huecos
2
8 3
10 16 7 18
13 15
![Page 17: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/17.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
17
MONTÍCULOS BINARIOS
Ventajas: el hecho de ser semicompleto hace que sea posible una representación secuencial.
2
8 3
10 16 7 18
13 15
2 8 3 210 16 7 18 13 15
![Page 18: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/18.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
18
MONTÍCULOS BINARIOS
La propiedad de la forma implica entonces:
•Si un nodo está almacenado en la posición i.
•Su hijo izquierdo, si existe, se encuentra en la posición 2i.
•Su hijo derecho, si existe, se encuentra en la posición 2i+1.
•El padre se encuentra en la posición i/2.
2
8 3
10 16 7 18
13 15 2 8 3 210 16 7 18 13 15
i=3
2*3=6 2*3+1=7i/2=1
![Page 19: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/19.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
19
MONTÍCULOS BINARIOS
Se cálcula fácil y rápidamente, realizando un dezplazamiento de un bit a la izquierda o a la derecha.
No hay necesidad de almacenar punteros como en los ABB.
Los cálculos de índices tardan menos tiempo que los de desreferencia de punteros asociados a una representación enlazada.
![Page 20: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/20.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
20
MONTÍCULOS BINARIOS
MANTENIMIENTO DE MONTICULOS
La operación EncontrarMin() se realiza en orden constante ya que solo será necesario acceder al valor de la raíz.
Las operaciones Insertar(x) y EliminarMin() no tienen implantaciones triviales en un montículo binario. Es necesario asegurar que ambas operaciones no destruyan las propiedades de un montículo.
![Page 21: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/21.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
21
MONTÍCULOS BINARIOS
Insertar (x):
Al insertar un elemento x en un montículo de n elementos debe resultar un árbol binario de n+1 elementos, esto es:
•El nodo se añade como una hoja extrema creciendo de izquierda a derecha (n+1).
![Page 22: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/22.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
22
MONTÍCULOS BINARIOS
Insertar (x):
Al insertar un elemento x en un montículo de n elementos debe resultar un árbol binario de n+1 elemntos, esto es:
•El nodo se añade como una hoja extrema creciendo de izquierda a derecha (n+1). (garantiza la propiedad de forma)
•Se garantiza la propiedad de ordenamiento parcial
2
8 3
10 16 7 18
13 15
2 8 3 210 16 7 18 13 15
4
4
![Page 23: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/23.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
23
MONTÍCULOS BINARIOS
2
8 3
10 4 7 18
13 15
2 8 3 210 4 7 18 13 15
16
16
![Page 24: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/24.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
24
MONTÍCULOS BINARIOS
4 3
10 8 7 18
13 15
2 4 3 210 8 7 18 13 15
16
16
2
![Page 25: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/25.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
25
MONTÍCULOS BINARIOS
4 3
10 8 7 18
13 15
2 4 3 210 8 7 18 13 15
16
16
2
![Page 26: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/26.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
26
MONTÍCULOS BINARIOS
2 4 3 210 8 7 18 13 15 16
2 8 3 210 16 7 18 13 15 4
2 8 3 210 4 7 18 13 15 16
2 4 3 210 8 7 18 13 15 16
I=10
I=5
I=2
I=1
![Page 27: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/27.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
27
MONTÍCULOS BINARIOS
Eliminar():
Al eliminar un elemento x en un montículo de n elementos, se elimina el elemento de clave mínima, es decir el elemento de la raíz.
•Se debe garantizar la propiedad de ordenamiento parcial??
2
8 3
10 16 7 18
13 15
2 8 3 210 16 7 18 13 15
![Page 28: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/28.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
28
MONTÍCULOS BINARIOS
15
8 3
10 16 7 18
13 15
15 8 3 210 16 7 18 13 n=n-1
![Page 29: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/29.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
29
MONTÍCULOS BINARIOS
15
8 3
10 16 7 18
13
15 8 3 210 16 7 18 13
![Page 30: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/30.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
30
MONTÍCULOS BINARIOS
3
8 15
10 16 7 18
13
3 8 15 210 16 7 18 13
![Page 31: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/31.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
31
MONTÍCULOS BINARIOS
3
8 7
10 16 15 18
13
3 8 7 210 16 15 18 13
![Page 32: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/32.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
32
MONTÍCULOS BINARIOS
En la operación de inserción es necesario realizar un subir (filtrado ascendente) del nodo pivote o insertador para asegurar la propiedad de forma.
En la operación de eliminación es necesario realizar un hundir (filtrado descendente) del nodo pivote o insertador para asegurar la propiedad de forma.
![Page 33: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/33.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
33
MONTÍCULOS BINARIOS
Creación de un montículo a partir de una colección existente de datos.
•Sol 1: Hacer n inserciones en un montículo inicialmente vacío O(nlog n). Enfoque de arriba hacia abajo.
![Page 34: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/34.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
34
MONTÍCULOS BINARIOS
Creación de un montículo a partir de una colección existente de datos.
•Sol 1: Hacer n inserciones en un montículo inicialmente vacío O(nlog n). Enfoque de arriba hacia abajo.
•Sol 2: Utilizar un enfoque de abajo hacia arriba, O(n).
![Page 35: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/35.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
35
MONTÍCULOS BINARIOS
Sol 2: Utilizar un enfoque de abajo hacia arriba, O(n).
Pasos:
•Almacenar arbitariamente los n elementos en el árbol.
19
2 13
18 15 3 7
16
19 2 13 218 15 3 7 16
8
8
![Page 36: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/36.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
36
MONTÍCULOS BINARIOS
Pasos:
•Almacenar arbitariamente los n elementos en el árbol.
•Con el nodo [n/2] procesando en orden decreciente hasta el nodo 1, montificar el subárbol con raíz en cada nodo por medio de un hundir.
16
19
2 13
18 15 3 7
19 2 13 218 15 3 7 16
8
8
4
32
1
![Page 37: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/37.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
37
MONTÍCULOS BINARIOS
16
19
2 13
8 15 3 7
19 2 13 28 15 3 7 16
18
18
32
1
![Page 38: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/38.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
38
MONTÍCULOS BINARIOS
16
19
2 3
8 15 13 7
19 2 3 28 15 13 7 16
18
18
2
1
![Page 39: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/39.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
39
MONTÍCULOS BINARIOS
16
19
2 3
8 15 13 7
19 2 3 28 15 13 7 16
18
18
![Page 40: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/40.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
40
MONTÍCULOS BINARIOS
16
2
19 3
8 15 13 7
2 19 3 28 15 13 7 16
18
18
![Page 41: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/41.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
41
MONTÍCULOS BINARIOS
16
2
19
38
15 13 7
2 8 3 219 15 13 7 16
18
18
![Page 42: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/42.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
42
MONTÍCULOS BINARIOS
16
2
19
38
15 13 7
2 8 3 216 15 13 7 19
18
18
![Page 43: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/43.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
43
MONTÍCULOS BINARIOS
Template<class T> class Monticulo{
T elemento[max];
int n=0;
protected:
Flotar(int i);
Hundir(int i);
public:
Montículo(const T& elem);
Montículo(T* elem);
Montículo();
![Page 44: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/44.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
44
MONTÍCULOS BINARIOS
void Inserta(const T& elem);
T& EncontrarMin();
T& EliminarMin();
Booleano Vacio() const;
inline void HacerVacio(); // operadores .>> <<
![Page 45: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/45.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
45
MONTÍCULOS BINARIOS
Template<class T>
void Monticulo::Flotar(int i){
T elem=elemento[i];
int p=i/2;
while (elem< elemento[p] && i>=1)
{ elemento[i]=elemento[p];
i=p;
p=i>>1;}
elemento[i]=elem;}
![Page 46: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/46.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
46
MONTÍCULOS BINARIOS
Template<class T> void Monticulo::Hundir(int i){ Assert(i>=0) return; T elem=elemento[i]; int n; int c; j=i; c=2*i; while (c<=n) { if ( c+1<= n){ if (elemento[c+1]<elemento[c]) c=c+1;} if (elem>elemento[c]) elemento[j]=elemento[c]; j=c; c=j<<1; //2*j } elemento[j]=elem;}
![Page 47: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/47.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
47
MONTÍCULOS BINARIOS
Template<class T> void Monticulo<T>::Insertar(constT& e){
n=n+1;
if (n<=max){
elemento[n]=e;
flotar(n);}}
Template<class T> T& Monticulo<T>::EliminarMin(){
T* elem= new T(elemento[1]);
elemento[1]=elemento[n];
n--;
if (Vacio()==falso) Hundir(1);
return *elem;}
![Page 48: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/48.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
48
MONTÍCULOS BINARIOS
Template<class T> T& Monticulo<T>::EncontrarMin(){
T* elem= new T(elemento[1]);
return *elem;}
Template<class T> booleano Monticulo<T>::Vacio(){
if (n>0) return true;
return falso;
![Page 49: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/49.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
49
1
2 3 4
4 7 10 13 15 16 8 17 9
6 7 10
61
31
21
14
13
12
19
18
16
5
MONTÍCULOS -d
Montículos parecidos a los binarios, excepto que todos los nodos tienen d hijos.
![Page 50: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/50.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
50
Características •Más bajos que los montículos binarios altura logd n.• Mejora la operación de insertar• EliminarMin es más costosa O(d logd n) ¿por qué?• Se pueden implantar en arreglos• Operaciones de multiplicación y división son más costosas• Bueno cuando hay muchas inserciones y pocas eliminaciones• Bueno cuando el tamaño del montículo es muy grande.
MONTÍCULOS -d
![Page 51: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/51.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
51
Problema:
La operación de combinar dos montículos en uno (fusionar) no tiene un soporte eficiente
Estructuras para fusionar eficientemente.
•Montículos a la izquierda: es un árbol binario. Se diferencia del montículo binario porque el montículo a la izquierda no está perfectamente equilibrado (intenta ser muy desequilibrado).
•Montículos oblicuos:
MONTÍCULOS -d
![Page 52: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/52.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
52
MONTÍCULOS BINARIOS A LA IZQUIERDA
Longitud del camino nulo
•Longitud del camino nulo lcn(x): es la longitud del camino más corto entre x y un nodo hoja.•Longitud del camino nulo de un nodo hoja o rama con un hijo es 0.•lcn(nulo) = -1 (longitud del camino nulo es -1)
1
1 0
0 0
0
![Page 53: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/53.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
53
MONTÍCULOS BINARIOS A LA IZQUIERDA
Propiedad del montículo a la izquierda:
•La lcn del hijo izquierdo es al menos tan grande como la del hijo derecho
El árbol se desvia con mayor profundidad al lado izquierdo.
![Page 54: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/54.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
54
MONTÍCULOS BINARIOS A LA IZQUIERDA
Un montículo a la izquierda poseen dos propiedades:
•Propiedad estructural basada en la longitud del camino nulo•Propiedad de orden (como el montículo binario)
![Page 55: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/55.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
55
MONTÍCULOS BINARIOS A LA IZQUIERDA
1
1 0
0 0
0
1
1*
0
0 1
0 0
![Page 56: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/56.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
56
MONTÍCULOS BINARIOS A LA IZQUIERDA
1
1 0
0 0
0
1
1*
0
0 1
0 0
MONTÍCULO A LA IZQUIERDA NO
lcn de cualquier nodo es 1 más que la mínima longitud del camino nulo de sus hijos
![Page 57: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/57.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
57
MONTÍCULOS BINARIOS A LA IZQUIERDA
Teorema
Un árbol a la izquierda con d nodos en el camino derecho debe tener al menos 2d - 1 nodos
Un árbol a la izquierda de n nodos tiene un camino derecho con a lo más log(n+1) nodos
La idea es trabajarlo por el lado derecho que es más corto.
![Page 58: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/58.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
58
MONTÍCULOS BINARIOS A LA IZQUIERDA
6
12
7
18
24
33
3
10
8
21
14
23
17
26
37
18
Ejemplo para fusionar dos montículos a la izquierda (P1, P2)
P1 P2
![Page 59: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/59.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
59
MONTÍCULOS BINARIOS A LA IZQUIERDA
6
12
18
24
33
3
10
21
14
23
7
37
18
8
17
26
P1 P2
Ejemplo para fusionar dos montículos a la izquierda (P1, P2)
![Page 60: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/60.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
60
MONTÍCULOS BINARIOS A LA IZQUIERDA
6
12
18
24
33
3
10
21
14
23
7
37
18
8
17
26
P1 P2
Ejemplo para fusionar dos montículos a la izquierda (P1, P2)
![Page 61: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/61.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
61
MONTÍCULOS BINARIOS A LA IZQUIERDA
6
12
18
24
33
3
10
21
14
23
7
37
18
8
17
26
P1 P2
Ejemplo para fusionar dos montículos a la izquierda (P1, P2)
![Page 62: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/62.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
62
MONTÍCULOS BINARIOS A LA IZQUIERDA
6
12
18
24
33
3
10
21
14
23
7
37
18
8
17
26
P1 P2
NULO
Ejemplo para fusionar dos montículos a la izquierda (P1, P2)
![Page 63: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/63.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
63
MONTÍCULOS BINARIOS A LA IZQUIERDA
6
12
18
24
33
3
10
21
14
23
7
37
18
8
17
26
LCN?
Ejemplo para fusionar dos montículos a la izquierda (P1, P2)
![Page 64: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/64.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
64
MONTÍCULOS BINARIOS A LA IZQUIERDA
6
12
18
24
33
3
10
21
14
23
7
37
18
8
17
26
LCN?
Ejemplo para fusionar dos montículos a la izquierda (P1, P2)
![Page 65: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/65.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
65
MONTÍCULOS BINARIOS A LA IZQUIERDA
6
12
18
24
33
3
10
21
14
23
7
378
1817
26
LCN?
Ejemplo para fusionar dos montículos a la izquierda (P1, P2)
![Page 66: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/66.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
66
MONTÍCULOS BINARIOS A LA IZQUIERDA
6
12
18
24
33
3
10
21
14
23
7
378
LCN?
1817
26
Ejemplo para fusionar dos montículos a la izquierda (P1, P2)
![Page 67: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/67.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
67
MONTÍCULOS BINARIOS A LA IZQUIERDA
6
12
18
24
33
3
10
21
14
23
7
378
LCN?
1817
26
Ejemplo para fusionar dos montículos a la izquierda (P1, P2)
![Page 68: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/68.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
68
MONTÍCULOS BINARIOS A LA IZQUIERDA
3
10
21
14
23
6
12
18
24
33
7
378
1817
26
Ejemplo para fusionar dos montículos a la izquierda (P1, P2)
![Page 69: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/69.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
69
MONTÍCULOS BINARIOS
Template<class Type> class MontIzq{
template <class T> class ElMont {
friend class Montizq<T>;
protected: T clave; int lcn; public: // los métodos de la clase }
A LA IZQUIERDA
![Page 70: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/70.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
70
MONTÍCULOS BINARIOS
Template<class T> class MontIzq: private ABB<ElMont>{
public:
MontIzq(const T& elem);
MontIzq(const MontIzq* elem);
MontIzq(T* elem);
MontIzq();
MontIzq<T>& Fusionar(MontIzq<T>& m1, MontIzq<T>& m2);
A LA IZQUIERDA
![Page 71: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/71.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
71
MONTÍCULOS BINARIOS
void Inserta(const T& elem);
T& EncontrarMin();
T& EliminarMin();
Booleano Vacio() const;
inline void HacerVacio(); // operadores .>> <<
private:
MontIzq<T>& Fusionar1(MontIzq<T>& m1, MontIzq<T>& m2)
A LA IZQUIERDA
![Page 72: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/72.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
72
MONTÍCULOS BINARIOS A LA IZQUIERDA
Template<class T>
void MontIzq::Fusionar(MontIzq<T>& m1, MontIzq<T>& m2){if (m1.Vacio()==true) return m2;else { if (m2.Vacio ()== true) return m1;
else{ if (m1 Infor().clave() < m2 Infor().clave()) return Fusionar1(m1,m2); else return Fusionar1(m2,m1);}}}
![Page 73: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/73.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
73
MONTÍCULOS BINARIOS A LA IZQUIERDA
Template<class T>
void MontIzq::Fusionar1(MontIzq<T>& m1, MontIzq<T>& m2){MontIzq<T> aux;if (m1 Hizq() == 0) m1 Hizq(m2.raiz);else { m1 Hder(Fusionar(m1 Hder(),m2)); if (m1 Hizq() Lcn() < m1 Hder() Lcn()) intercambiar(m1 Izq(),m1 Der()) m1 Lcn(m1 Der() Lcn()+1)}return m1;}
![Page 74: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/74.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
74
MONTÍCULOS BINARIOS
Insertar
6
M1 M2
3
10
8
21
14
23
17
26
![Page 75: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/75.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
75
MONTÍCULOS BINARIOS
Insertar
6
M1 M2
3
10
8
21
14
23
17
26
Nulo
![Page 76: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/76.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
76
MONTÍCULOS BINARIOS
Insertar
6
M1 M2
3
10
8
21
14
23
17
26
![Page 77: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/77.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
77
MONTÍCULOS BINARIOS
Insertar
6
M1 M2
3
10
8
21
14
23
17
26
![Page 78: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/78.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
78
MONTÍCULOS BINARIOS
Insertar
6
M13
10
8
21
14
23
17
26
![Page 79: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/79.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
79
MONTÍCULOS BINARIOS
Template<class T> void Monticulo<T>::Insertar(constT& e){
MontIzq<T> aux = new MontIzq<T>(e); MontIzq<T> aux1 = new MontIzq<T>(this); this Fusionar( aux, aux1);
A LA IZQUIERDA
![Page 80: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/80.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
80
MONTÍCULOS BINARIOS A LA IZQUIERDA
M1
3
10
8
21
14
23
17
26
EliminarMin()
![Page 81: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/81.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
81
MONTÍCULOS BINARIOS A LA IZQUIERDA
M1
10
8
21
14
23
17
26
M2
![Page 82: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/82.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
82
MONTÍCULOS BINARIOS A LA IZQUIERDA
M1
10
8
21
14
23
17
26
M2
![Page 83: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/83.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
83
MONTÍCULOS BINARIOS A LA IZQUIERDA
M1
10
8
21
14
23
17
26
M2
NULO
![Page 84: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/84.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
84
MONTÍCULOS BINARIOS A LA IZQUIERDA
M1
10
8
21
14
23
17
26
![Page 85: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/85.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
85
MONTÍCULOS BINARIOS A LA IZQUIERDA
Template<class T> T& Monticulo<T>::EliminarMin(){
T* ele = new T(raiz->Elem()); MontIzq<T> m1; MontIzq<T> m2; m1=raiz Hizq(); m2=raiz Hder(); delete raiz; this Fusionar(m1,m2);
return *ele;}
![Page 86: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/86.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
86
MONTÍCULOS BINARIOS OBLICUOS
Un montículo oblicuo es una versión autoajustable de un montículo a la izquierda.
Es más facil de implementar debido al empleo de la heurística auto-ajustable.
En estos, el recorrido de abajo hacia arriba incondicionalmente se realiza el intercambio en todos los nodos (excepto para el nodo extremo derecho, dado que no tiene hijo no tiene sentido intercambiarlos).
No se mantiene información acerca de la longitud del camino nulo.
![Page 87: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/87.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
87
MONTÍCULOS BINARIOS OBLICUOS
El camino derecho del montículo oblicuo puede ser arbitrariamente largo en un momento dado O(n).
Para cualesquiera m operaciones consecutivas, el tiempo total en el peor de los casos es O(m log n). Así el costo amortizado por operación en un montículo oblicuo es O(log n)
![Page 88: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/88.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
88
6
12
7
18
24
33
3
10
8
21
14
23
17
26
37
18
P1 P2
MONTÍCULOS BINARIOS OBLICUOS
![Page 89: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/89.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
89
6
12
18
24
33
3
10
21
14
23
7
37
18
8
17
26
P1 P2
MONTÍCULOS BINARIOS OBLICUOS
![Page 90: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/90.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
90
6
12
18
24
33
3
10
21
14
23
7
37
18
8
17
26
P1 P2
MONTÍCULOS BINARIOS OBLICUOS
![Page 91: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/91.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
91
6
12
18
24
33
3
10
21
14
23
7
37
18
8
17
26
P1 P2
MONTÍCULOS BINARIOS OBLICUOS
![Page 92: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/92.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
92
6
12
18
24
33
3
10
21
14
23
7
37
18
8
17
26
P1 P2
NULO
MONTÍCULOS BINARIOS OBLICUOS
![Page 93: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/93.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
93
6
12
18
24
33
3
10
21
14
23
7
37
18
8
17
26
MONTÍCULOS BINARIOS OBLICUOS
![Page 94: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/94.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
94
6
12
18
24
33
3
10
21
14
23
7
37
18
8
17
26
MONTÍCULOS BINARIOS OBLICUOS
![Page 95: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/95.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
95
6
12
18
24
33
3
10
21
14
23
7
37
18
8
17
26
MONTÍCULOS BINARIOS OBLICUOS
![Page 96: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/96.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
96
6
12
18
24
33
3
10
21
14
23
7
37
18
8
17
26
MONTÍCULOS BINARIOS OBLICUOS
![Page 97: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/97.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
97
6
12
18
24
33
3
10
21
14
23
7
37
18
8
17
26
MONTÍCULOS BINARIOS OBLICUOS
![Page 98: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/98.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
98
63
10
21
14
23
7
37
18
8
17
26
12
18
24
33
MONTÍCULOS BINARIOS OBLICUOS
![Page 99: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/99.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
99
6
3
10
21
14
23
7
37
18
8
17
26
12
18
24
33
MONTÍCULOS BINARIOS OBLICUOS
![Page 100: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/100.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
100
6
3
7
37
18
8
17
26
12
18
24
33
10
21
14
23
MONTÍCULOS BINARIOS OBLICUOS
![Page 101: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/101.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
101
Template<class T> class MonO: private ABB<T>{
public:
MonO(const T& elem);
MonO(const MontIzq* elem);
MonO(T* elem);
MonO();
MontO<T>& Fusionar(MonO<T>& m1, MonO<T>& m2);
MONTÍCULOS BINARIOS OBLICUOS
![Page 102: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/102.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
102
void Inserta(const T& elem);
T& EncontrarMin();
T& EliminarMin();
Booleano Vacio() const;
inline void HacerVacio(); // operadores .>> <<
privare:
MonO<T>& Fusionar1(MonO<T>& m1, MonO<T>& m2)
MONTÍCULOS BINARIOS OBLICUOS
![Page 103: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/103.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
103
Template<class T>
void MonO::Fusionar(MonO<T>& m1, MonO<T>& m2){
if (m1.Vacio()==true) return m2;else¨{ if (m2.Vacio ()== true) return m1;
else{ if (m1 Infor() < m2 Infor()) return Fusionar1(m1,m2); else return Fusionar1(m2,m1);}}}
MONTÍCULOS BINARIOS OBLICUOS
![Page 104: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/104.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
104
Template<class T>
void MonO::Fusionar1(MonO<T>& m1, MonO<T>& m2){MonO<T> aux;
if (m1 Hizq() == 0) m1 Hizq(m2.raiz);else { m1 Hder(Fusionar(m1 Hder(),m2)); intercambiar(m1 Izq(),m1 Der());} return m1;}
MONTÍCULOS BINARIOS OBLICUOS
![Page 105: COLAS DE PRIORIDAD](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56815535550346895dc30e81/html5/thumbnails/105.jpg)
21/04/23 Dulce M. Rivero A. Estructura de datos
105
BIBLIOGRAFÍA
• Gregory L. Heilemam. “ Estructura de Datos, Algoritmos, y Programación Orientada a Objetos”. Mc Graw Hill . 1997.
•Luis Joyanes A. Ignacio Zahonero M. “ Estructura de Datos”. Mc Graw Hill . 1999.
•Mark Allen W. “ Estructura de Datos y Algoritmos”. Addison Wesley 1995.