You are on page 1of 25

UNIVERSIDAD MAYOR DE SAN ANDRES

CARRERA INFORMATICA
LAB 131
PILAS Y COLAS MULTIPLES
(GUIA NO. 7)
Paralelos: “A”y”B” Gestion 1/2010
Responsables: Lic. Victoria Hurtado Cerruto Aux. Doc.: Univ. Jonathan W. Magne Q.

ARBOLES
1. INTRODUCCIÓN

Una de las estructuras de datos más importantes y prominentes que


existen es el árbol. No es un árbol en el sentido botánico de la palabra,
sino uno de naturaleza más abstracta. Todos hemos visto usar tales
árboles para describir conexiones familiares. Los dos tipos más comunes
de árboles familiares son el árbol de antecesores, que empieza en un
individuo y va hacia atrás a través de padres, abuelos, etc., y el árbol de
descendientes, que va hacia delante a través de hijos, nietos, etc.

2. DEFINICIÓN

Un árbol es un conjunto de nodos organizados de manera jerárquica

3. REPRESENTACIÓN

Raíz
Raíz
Nivel 0

asM

Nivel 1
UNIVERSIDAD MAYOR DE SAN ANDRES
CARRERA INFORMATICA
LAB 131
PILAS Y COLAS MULTIPLES
(GUIA NO. 7)
Paralelos: “A”y”B” Gestion 1/2010
Responsables: Lic. Victoria Hurtado Cerruto Aux. Doc.: Univ. Jonathan W. Magne Q.

Nivel 2

Nivel 3

Arbol

Donde existen las siguientes características:

Grado = El grado es el número máximo de descendientes que puede


tener un nodo del árbol en el ejemplo anterior en Grado = 4 = Max {4,
3, 2, 0, 0, 3, 1, 3 … }

Nivel = Numero de descendientes que tiene el árbol en el ejemplo


anterior el Nivel =3

Nodo Raíz= Nodo principal, nodo inicial.

Nodo Hoja= Nodo hoja es todo aquel nodo que no tenga descendientes,
en el ejemplo anterior los nodos hoja son:

TIPOS DE ARBOLES

Existen dos tipos de arboles según su grado:


UNIVERSIDAD MAYOR DE SAN ANDRES
CARRERA INFORMATICA
LAB 131
PILAS Y COLAS MULTIPLES
(GUIA NO. 7)
Paralelos: “A”y”B” Gestion 1/2010
Responsables: Lic. Victoria Hurtado Cerruto Aux. Doc.: Univ. Jonathan W. Magne Q.

• Binarios.- Arboles con grado=2.

Los arboles binarios a la vez de sub dividen en:

Arboles Binarios

Se definirá el árbol que constas de dos-subárbols: subárbol izquierdo (si)


y subárbol derecho (sd).

Arboles Binarios de Búsqueda

Son arboles que nos muestran orden, es decir para un ejemplo: Para
todo nodo A del árbol:

o Todos los valores de los nodos del subárbol izquierdo de A


deben ser menores al valor del nodo A.

o Todos los valores de los nodos del subárbol derecho de A


deben ser mayores o iguales al valor del nodo A.

o Ambos subárboles son árboles binarios de búsqueda.

• N-arios.- Arboles con grado = N donde N >2.


UNIVERSIDAD MAYOR DE SAN ANDRES
CARRERA INFORMATICA
LAB 131
PILAS Y COLAS MULTIPLES
(GUIA NO. 7)
Paralelos: “A”y”B” Gestion 1/2010
Responsables: Lic. Victoria Hurtado Cerruto Aux. Doc.: Univ. Jonathan W. Magne Q.

Árbol completo de nivel n a un árbol en el que cada nodo de nivel n


es una hoja y cada nodo de nivel menor que n tiene, al menos, un
subárbol no vacío.

ESTRUCTURA DEL NODO

Como ya se dijo anteriormente un árbol es un conjunto de nodos


organizados de manera jerárquica, por lo tanto es necesario saber cómo
están conformados los nodos dentro del árbol:

• Binarios.- al ser de grado 2 constan de dos áreas de enlace

Enlace Dato(s) Enlace


Izquier
Objeto(s) Derecho
do

• N-arios.- Al ser de grado N constan de N áreas de enlace

N áreas de enlace

Dato(s)

Objeto(s) .
1 2 3 N
. . .
UNIVERSIDAD MAYOR DE SAN ANDRES
CARRERA INFORMATICA
LAB 131
PILAS Y COLAS MULTIPLES
(GUIA NO. 7)
Paralelos: “A”y”B” Gestion 1/2010
Responsables: Lic. Victoria Hurtado Cerruto Aux. Doc.: Univ. Jonathan W. Magne Q.

De aquí en adelante nos dedicaremos específicamente a los arboles binarios

RECORRIDOS.- Esta es la parte más importante porque aquí conocerás como


moverte dentro de un árbol para poder solucionar las distintas consultas.

Sea el árbol Binario A:

b c

d e f

g h

i
UNIVERSIDAD MAYOR DE SAN ANDRES
CARRERA INFORMATICA
LAB 131
PILAS Y COLAS MULTIPLES
(GUIA NO. 7)
Paralelos: “A”y”B” Gestion 1/2010
Responsables: Lic. Victoria Hurtado Cerruto Aux. Doc.: Univ. Jonathan W. Magne Q.

Recorrido por Niveles.- Su funcionamiento es simple ya que recorre al


árbol nivel tras nivel, por ejemplo si mostramos el árbol recorriendo por
niveles es resultado sería:

bc

def

gh

Pre Orden (RID).- Recorre al árbol mostrado primero la Raíz del árbol,
luego toda la Izquierda de la raíz y al final toda la Derecha de la raíz.

Para el ejemplo el recorrido (RID)= a, b, d, c, e, g, h, i, f

In Orden (IRD).- Recorre al árbol mostrado primero la Izquierda del


árbol, luego la Raíz y al final la Derecha.

Para el ejemplo el recorrido (IRD)= d, b, a, g, e, h, i, c, f

Post Orden (IDR).- Recorre al árbol mostrado primero la Izquierda del


árbol, luego la Derecha y al final la Raíz del árbol.

Para el ejemplo el recorrido (IRD)= d, b, g, i, h, e, f, c, a

ARBOLES HOMOGENEOS

SIMETRICOS

ArbolBinario
NodoA Nodo raíz

Si
4. DIAGRAMA DE CLASES Esvacia();
sd r_preorden();
Dato a) Pilas Múltiples r_Inorden();
r_Postorden()
Nodo() r_Niveles();
getdato() get_raiz();
setDato(Dato NroElem()
y) Abstract crea();
getsi(); Abstract carga(int x)
setsi(NodoA Abstract busqueda (int x)
x);
getSd();
UNIVERSIDAD MAYOR DE SAN ANDRES
CARRERA INFORMATICA
LAB 131
PILAS Y COLAS MULTIPLES
(GUIA NO. 7)
Paralelos: “A”y”B” Gestion 1/2010
Responsables: Lic. Victoria Hurtado Cerruto Aux. Doc.: Univ. Jonathan W. Magne Q.

ABBusqueda
ABNormall
Carga(iny x)
crea () Busqueda (int x)
Esvacia(); Esvacia();
r_preorden(); r_preorden();
r_Inorden(); r_Inorden();
r_Postorden() r_Postorden()
r_Niveles(); r_Niveles();
get_raiz(); get_raiz();
NroElem() NroElem()

5. APLICACIONES
UNIVERSIDAD MAYOR DE SAN ANDRES
CARRERA INFORMATICA
LAB 131
PILAS Y COLAS MULTIPLES
(GUIA NO. 7)
Paralelos: “A”y”B” Gestion 1/2010
Responsables: Lic. Victoria Hurtado Cerruto Aux. Doc.: Univ. Jonathan W. Magne Q.

Veamos algunos ejemplos donde la estructura de datos árbol puede ser


muy util :

1. Los sistemas de archivos ( file system ) de los sistemas operativos,


compuestos por jerarquías de directorios y archivos.

2. La jerarquía de clases en los lenguajes orientados a objetos.

3. La jerarquía de países, provincias, departamentos y municipios que


organiza al poder político de una república.

6. IMPLEMENTACIÓN

NODO
public class NodoA {
NodoA izq;
int dato;
NodoA der;
public NodoA ()
{
izq = null;
der = null;
}
}

ARBOL

abstract class ArbolBinario {


protected NodoA R;

ArbolBinario ()
{
R = null;
}

public boolean Esvacia ()


{
UNIVERSIDAD MAYOR DE SAN ANDRES
CARRERA INFORMATICA
LAB 131
PILAS Y COLAS MULTIPLES
(GUIA NO. 7)
Paralelos: “A”y”B” Gestion 1/2010
Responsables: Lic. Victoria Hurtado Cerruto Aux. Doc.: Univ. Jonathan W. Magne Q.

if (R == null)
return true;
else
return false;
}

public void r_preOrden ()


{
System.out.println ("\nRecorrido preorden ");
PilaN p = new PilaN ();
p.adicion (null);
NodoA x = R;
while (x != null)
{
System.out.print (x.dato + " ");
if (x.der != null)
p.adicion (x.der);
if (x.izq != null)
x = x.izq;
else
x = p.eliminacion ();
}
}

public void r_inOrden ()


{
System.out.println ("\nRecorrido inorden ");
PilaN p = new PilaN ();
p.adicion (null);
NodoA x = R;
while (p.nroElementos () != 0)
{
while (x != null)
{
p.adicion (x);
x = x.izq;
}
x = p.eliminacion ();
if (x != null)
{
System.out.print (x.dato + " ");
x = x.der;
}
}
}

public void r_postOrden ()


{
System.out.println ("\nRecorrido postorden ");
PilaN p = new PilaN ();

NodoA x = R;
UNIVERSIDAD MAYOR DE SAN ANDRES
CARRERA INFORMATICA
LAB 131
PILAS Y COLAS MULTIPLES
(GUIA NO. 7)
Paralelos: “A”y”B” Gestion 1/2010
Responsables: Lic. Victoria Hurtado Cerruto Aux. Doc.: Univ. Jonathan W. Magne Q.

p.adicion (null);
while (p.nroElementos () != 0)
{
while (x != null)
{
p.adicion (x);
if (x.der != null)
{
p.adicion (x.der);
p.adicion (null);
}
x = x.izq;
}
x = p.eliminacion ();
while (x != null)
{
System.out.print (x.dato + " ");
x = p.eliminacion ();
}
if (p.nroElementos () != 0)
{
x = p.eliminacion ();
}
}

public void r_Niveles ()


{
PilaN nivel = new PilaN ();
PilaN desc = new PilaN ();

NodoA x;
nivel.adicion (R);
int i = 0;
while (!nivel.esVacia ())
{
System.out.print ("Nivel : " + i);
while (!nivel.esVacia ())
{
x = nivel.eliminacion ();
System.out.print (" " + x.dato);
if (x.izq != null)
desc.adicion (x.izq);

if (x.der != null)
desc.adicion (x.der);
}
nivel.vaciar (desc);
System.out.println (" ");
UNIVERSIDAD MAYOR DE SAN ANDRES
CARRERA INFORMATICA
LAB 131
PILAS Y COLAS MULTIPLES
(GUIA NO. 7)
Paralelos: “A”y”B” Gestion 1/2010
Responsables: Lic. Victoria Hurtado Cerruto Aux. Doc.: Univ. Jonathan W. Magne Q.

i = i + 1;
}
}

public NodoA getRaiz()


{
return R;
}

int nroelem ()
{
NodoA x;
PilaN nivel = new PilaN ();
PilaN desc = new PilaN();
int ne = 0;
if (Esvacia())
return ne;
else
{
nivel.adicion (R);
while (!nivel.esVacia ())
{
while (!nivel.esVacia ())
{
x = nivel.eliminacion ();
ne++;
if (x.izq != null)
desc.adicion (x.izq);
if (x.der != null)
desc.adicion (x.der);
}
System.out.println ();
while (!desc.esVacia ())

nivel.adicion (desc.eliminacion ());


}
return (ne);
}
}

public abstract void crea();


public abstract void carga (int e);
public abstract void busqueda (int x);

ARBOL BINARIO NORMAL

class ABNormal extends ArbolBinario


{
ABNormal ()
{
UNIVERSIDAD MAYOR DE SAN ANDRES
CARRERA INFORMATICA
LAB 131
PILAS Y COLAS MULTIPLES
(GUIA NO. 7)
Paralelos: “A”y”B” Gestion 1/2010
Responsables: Lic. Victoria Hurtado Cerruto Aux. Doc.: Univ. Jonathan W. Magne Q.

super ();
}

public void crea ()


{
PilaN nivel = new PilaN ();
PilaN desc = new PilaN ();
String resp;
NodoA y;
NodoA x = new NodoA ();
System.out.print ("Nodo Raiz : ");
x.dato = Leer.datoInt ();
R = x;
nivel.adicion (R);

while (!nivel.esVacia ())


{
while (!nivel.esVacia ())
{
y = nivel.eliminacion ();
System.out.print ("Nodo : " + y.dato + " Tendra Izq
S/N?");
resp = Leer.dato ();
if (resp.compareTo ("s") == 0)
{
NodoA w = new NodoA ();
System.out.print("Dato Izq :");
w.dato = Leer.datoInt ();
y.izq = w;
desc.adicion (w);
}
System.out.print (" Nodo : " + y.dato + "Tendra Der
S/N?");
resp = Leer.dato ();
if (resp.compareTo ("s") == 0)
{
NodoA z = new NodoA ();
System.out.print("Dato Der :");
z.dato = Leer.datoInt ();
y.der = z;
desc.adicion (z);
}
}
nivel.vaciar (desc);
}
}
}

ARBOL BINARIO DE BUSQUEDA

class ABBusqueda extends ArbolBinario


{
ABBusqueda ()
UNIVERSIDAD MAYOR DE SAN ANDRES
CARRERA INFORMATICA
LAB 131
PILAS Y COLAS MULTIPLES
(GUIA NO. 7)
Paralelos: “A”y”B” Gestion 1/2010
Responsables: Lic. Victoria Hurtado Cerruto Aux. Doc.: Univ. Jonathan W. Magne Q.

{
super ();
}

public void carga (int e)


{
NodoA x = new NodoA ();
NodoA y;
x.dato = e;
if (Esvacia ())
R = x;
else
{
int sw = 0;
y = R;
while (sw == 0)
{
if (e > y.dato)
{
if (y.der != null)
y = y.der;
else
{
y.der = x;
sw = 1;
}
}
else
{
if (y.izq != null)
y = y.izq;
else
{
y.izq = x;
sw = 1;
}
}
}

public void busqueda (int x)


{
NodoA y;
y = R;
while (y != null)
{
if (x < y.dato)
{
UNIVERSIDAD MAYOR DE SAN ANDRES
CARRERA INFORMATICA
LAB 131
PILAS Y COLAS MULTIPLES
(GUIA NO. 7)
Paralelos: “A”y”B” Gestion 1/2010
Responsables: Lic. Victoria Hurtado Cerruto Aux. Doc.: Univ. Jonathan W. Magne Q.

if (y.izq == null)
System.out.print ("No se encuentra");

y = y.izq;
}
else
{
if (x > y.dato)
{
if (y.der == null)
System.out.print ("No se encuentra");

y = y.der;

}
else
{
System.out.print ("El dato se encuentra en el
arbol");
y = null;
}
}
}
}
}

7. EJERCICIOS RESUELTOS

7.1. MOSTRAR LOS NODOS HOJAS DE UN ARBOL BINARIO

EN ARBOL BINARIO (ArbolBinario)

public void hojas ()


{
NodoA x;
int niv = 0;
PilaN nivel = new PilaN ();
PilaN desc = new PilaN ();

nivel.adicion (R);
while (!nivel.esVacia ())
{
System.out.println ("\n Nivel :" + niv);
while (!nivel.esVacia ())
{
x = nivel.eliminacion ();
if (x.izq == null && x.der == null)
System.out.print (x.dato + " ");

if (x.izq != null)
desc.adicion (x.izq);
if (x.der != null)
UNIVERSIDAD MAYOR DE SAN ANDRES
CARRERA INFORMATICA
LAB 131
PILAS Y COLAS MULTIPLES
(GUIA NO. 7)
Paralelos: “A”y”B” Gestion 1/2010
Responsables: Lic. Victoria Hurtado Cerruto Aux. Doc.: Univ. Jonathan W. Magne Q.

desc.adicion (x.der);
}
System.out.println ();
while (!desc.esVacia ())
nivel.adicion (desc.eliminacion ());
niv++;
}}

public class manejo {

public static void main(String[]iorek)

{
ABNormal a=new ABNormal();
System.out.println("CREAR ARBOL");
a.crea();
System.out.println("MOSTRAR ARBOL");
a.r_Niveles();
System.out.println("HOJAS DE UN ARBOL");
a.hojas();
}}
UNIVERSIDAD MAYOR DE SAN ANDRES
CARRERA INFORMATICA
LAB 131
PILAS Y COLAS MULTIPLES
(GUIA NO. 7)
Paralelos: “A”y”B” Gestion 1/2010
Responsables: Lic. Victoria Hurtado Cerruto Aux. Doc.: Univ. Jonathan W. Magne Q.

5
0
2 7
7 0

1 3 6 7
0 0 0 5

2 6
1
8 5
UNIVERSIDAD MAYOR DE SAN ANDRES
CARRERA INFORMATICA
LAB 131
PILAS Y COLAS MULTIPLES
(GUIA NO. 7)
Paralelos: “A”y”B” Gestion 1/2010
Responsables: Lic. Victoria Hurtado Cerruto Aux. Doc.: Univ. Jonathan W. Magne Q.

7.2. SEA UN ARBOL QUE ALMACENA RECTANGULOS (BASE,


ALTURA)
a) MOSTRAR CUANTOS CUADRADOS ESTAN DENTRO DEL
ARBOL
b) CUANTOS NODOS TIENEN DOS NODOS HOJAS

CLASS RECTANGULO

public class rectang


{

private int base;


private int altura;
rectang ()
{
base = altura = 0;
}

rectang (int a, int b)


{
base = a;
altura = b;
}

public void mostrar()


{
System.out.print ("(" + base + "," + altura + ")");
}

public void leer()


{
base = Leer.datoInt ();
altura = Leer.datoInt ();
}

public int obbase ()


{
return base;
}

public int obaltura ()


{
return altura;
}
UNIVERSIDAD MAYOR DE SAN ANDRES
CARRERA INFORMATICA
LAB 131
PILAS Y COLAS MULTIPLES
(GUIA NO. 7)
Paralelos: “A”y”B” Gestion 1/2010
Responsables: Lic. Victoria Hurtado Cerruto Aux. Doc.: Univ. Jonathan W. Magne Q.

public boolean verif()


{
if(base==altura)
return true;
return false;
}
}

CLASS ARBOL

abstract class ArbolBinario {


protected NodoA R;

ArbolBinario ()
{
R = null;
}

public boolean Esvacia ()


{
if (R == null)
return true;
else
return false;
}

public void r_Niveles ()


{
PilaN nivel = new PilaN ();
PilaN desc = new PilaN ();

NodoA x;
nivel.adicion (R);
int i = 0;
while (!nivel.esVacia ())
{
System.out.print ("Nivel : " + i);
while (!nivel.esVacia ())
{
x = nivel.eliminacion ();
x.dato.mostrar();
System.out.print(" ");
if (x.izq != null)
desc.adicion (x.izq);

if (x.der != null)
desc.adicion (x.der);
}
nivel.vaciar (desc);
System.out.println (" ");
i = i + 1;
UNIVERSIDAD MAYOR DE SAN ANDRES
CARRERA INFORMATICA
LAB 131
PILAS Y COLAS MULTIPLES
(GUIA NO. 7)
Paralelos: “A”y”B” Gestion 1/2010
Responsables: Lic. Victoria Hurtado Cerruto Aux. Doc.: Univ. Jonathan W. Magne Q.

}
}
}

CLASS NODOA
public class NodoA {
NodoA izq;
rectang dato=new rectang();
NodoA der;
public NodoA ()
{
izq = null;
der = null;
}
}

CLASS ABNORMAL

class ABNormal extends ArbolBinario


{
ABNormal ()
{
super ();
}

public void hojas ()


{

NodoA x;
int niv = 0;
PilaN nivel = new PilaN ();
PilaN desc = new PilaN ();

nivel.adicion (R);
while (!nivel.esVacia ())
{
System.out.println ("\n Nivel :" + niv);
while (!nivel.esVacia ())
{
x = nivel.eliminacion ();
if (x.izq == null && x.der == null)
System.out.print (x.dato + " ");

if (x.izq != null)
desc.adicion (x.izq);
if (x.der != null)
desc.adicion (x.der);
}
System.out.println ();
while (!desc.esVacia ())
nivel.adicion (desc.eliminacion ());
niv++;
UNIVERSIDAD MAYOR DE SAN ANDRES
CARRERA INFORMATICA
LAB 131
PILAS Y COLAS MULTIPLES
(GUIA NO. 7)
Paralelos: “A”y”B” Gestion 1/2010
Responsables: Lic. Victoria Hurtado Cerruto Aux. Doc.: Univ. Jonathan W. Magne Q.

}
}

public void crea()


{
String resp;
PilaN nivel = new PilaN ();
PilaN desc = new PilaN ();
NodoA x = new NodoA ();
System.out.print("Punto Raiz-->");
x.dato.leer();
R = x;
nivel.adicion (R);
while (!nivel.esVacia ())
{
while (!nivel.esVacia ())
{
x = nivel.eliminacion ();
x.dato.mostrar();
System.out.print ( " Tendra Izquierda ? S/N");
resp = Leer.dato ();
if (resp.compareTo ("s") == 0)
{
NodoA y = new NodoA ();
System.out.print("Punto-->");
y.dato.leer ();
x.izq = y;
desc.adicion (y);
}
else
x.izq = null;
x.dato.mostrar();
System.out.print (" Tendra Derecha ? S/N");
resp = Leer.dato ();
if (resp.compareTo ("s") == 0)
{
NodoA y = new NodoA ();
System.out.print("Punto-->");
y.dato.leer();
x.der = y;
desc.adicion (y);
}
else
x.der = null;
}
while (!desc.esVacia ())

nivel.adicion (desc.eliminacion ());


}
}
UNIVERSIDAD MAYOR DE SAN ANDRES
CARRERA INFORMATICA
LAB 131
PILAS Y COLAS MULTIPLES
(GUIA NO. 7)
Paralelos: “A”y”B” Gestion 1/2010
Responsables: Lic. Victoria Hurtado Cerruto Aux. Doc.: Univ. Jonathan W. Magne Q.

boolean eshoja(NodoA x)
{
if(x.der==null && x.izq==null)
return (true);
else
return(false);
}

public void busqueda(int x) {


// TODO Auto-generated method stub

public void carga(int e) {


// TODO Auto-generated method stub

CLASS MANEJO

class manejo
{
public static void contar(ABNormal a)
{
int c=0;
NodoA x;
PilaN nivel= new PilaN();
PilaN desc=new PilaN();
nivel.adicion(a.R);
while(!nivel.esVacia())
{
while(!nivel.esVacia())
{
x=nivel.eliminacion();
if(x.dato.verif())
c=c+1;
if(x.izq!=null)
desc.adicion(x.izq);
if(x.der!=null)
desc.adicion(x.der);
}
nivel.vaciar(desc);
}
System.out.print(c);
}

public static int cont(ABNormal a)


{
PilaN aux = new PilaN ();
NodoA x;
UNIVERSIDAD MAYOR DE SAN ANDRES
CARRERA INFORMATICA
LAB 131
PILAS Y COLAS MULTIPLES
(GUIA NO. 7)
Paralelos: “A”y”B” Gestion 1/2010
Responsables: Lic. Victoria Hurtado Cerruto Aux. Doc.: Univ. Jonathan W. Magne Q.

int c=0;
aux.adicion (null);
x = a.R;
while (x != null)
{
if(x.der!=null && x.izq!=null)
if(a.eshoja(x.der)&& a.eshoja(x.izq))

c=c+1;

if (x.der != null)
aux.adicion (x.der);
if (x.izq != null)
x = x.izq;
else
x = aux.eliminacion ();

}
return(c);
}

public static void main (String[]iorek)


{
ABNormal a=new ABNormal();
a.crea();

a.r_Niveles();
System.out.println("LOS CUADRADOS DENTRO DEL ARBOL SON:");
contar(a);
System.out.println(" ");
System.out.println("EL ARBOL TIENE "+ cont(a)+ " Nodos con 2
nodos hojas");
}
}
UNIVERSIDAD MAYOR DE SAN ANDRES
CARRERA INFORMATICA
LAB 131
PILAS Y COLAS MULTIPLES
(GUIA NO. 7)
Paralelos: “A”y”B” Gestion 1/2010
Responsables: Lic. Victoria Hurtado Cerruto Aux. Doc.: Univ. Jonathan W. Magne Q.

8. EJERCICIOS PROPUESTOS

1. Rotar los valores de los nodos hojas de un árbol binario normal

5 5

1 1 1 1
2 4 2 4

1 1 2 5 1 1 2 5
6 9 2 1 6 1 2 1

1 2 2 1
6 6
1 0 0 9
UNIVERSIDAD MAYOR DE SAN ANDRES
CARRERA INFORMATICA
LAB 131
PILAS Y COLAS MULTIPLES
(GUIA NO. 7)
Paralelos: “A”y”B” Gestion 1/2010
Responsables: Lic. Victoria Hurtado Cerruto Aux. Doc.: Univ. Jonathan W. Magne Q.

2. Sea un árbol binario de búsqueda que contiene a los clientes de


un banco

a) Listar a los clientes por orden alfabético

b) Cual(s) son el (los) cliente(s) con mayor deuda

c) Suponer que el cliente x paga su deuda, eliminarlo del árbol

d) Cuál es el total que adeudan los clientes del subárbol


derecho

NodoA
Si
sd ArbolBinario
nombre Nodo raíz
deuda
ABBusque
Esvacia(); da
NodoA( …
)
….

UNIVERSIDAD MAYOR DE SAN ANDRES
CARRERA INFORMATICA
LAB 131
PILAS Y COLAS MULTIPLES
(GUIA NO. 7)
Paralelos: “A”y”B” Gestion 1/2010
Responsables: Lic. Victoria Hurtado Cerruto Aux. Doc.: Univ. Jonathan W. Magne Q.

3. Dado un árbol binario normal de caracteres

a) Indicar en qué nivel se encuentran las vocales

b) Cuantos nodos hojas son consonantes

c) Verificar si el árbol es completo

d) Verificar si el árbol es simétrico

9. BIBLIOGRAFIA

[1]Cairo Osvaldo&Guardati Silva “Estructura de Datos”


[2]Ceballos,Javier “Java 2 Curso de Programacion”
[3] http://s3.amazonaws.com/ppt-download/arboles-090701161520- phpapp02.pdf?
Signature=e74v6C3P04W9c7jikArMTigE6HM
%3D&Expires=1275452141&AWSAccessKeyId=AKIAJLJT267DEGKZDHEQ

You might also like