Download Test Árboles

Document related concepts
no text concepts found
Transcript
1.- Dado el árbol de la figura ¿Cuál de las siguientes afirmaciones es cierta?:
A
B
D
C
E
H
a)
b)
c)
d)
F
G
J
I
El árbol es estrictamente binario.
La profundidad del árbol es 3.
El nodo A es padre de todos los demás.
El nodo H es el hijo derecho del nodo B.
2. ¿Cual es su recorrido en postorden del árbol de la pregunta anterior?
a) DHBEIJFGCA
b) DHEBJIFGCA
c) ABCDEFGHIJ
d) GIJFCHEDBA
3.- Si queremos eliminar el nodo ‘L’ del árbol binario de búsqueda de la figura
aplicando la regla de “proximidad anterior”, el árbol resultante será:
J
B
Q
L
R
K
N
P
M
a)
b)
J
B
Q
K
B
Q
R
M
N
M
c)
J
K
P
J
B
Q
R
N
N
M
P
K
R
P
4.- Dada la definición de un árbol binario, ¿cual es la operación de creación correcta?
a) Algoritmo Crear(ES TArbol a);
Inicio
Asignar(a);
a->izq=NIL;
a->der=NIL
Fin Crear
c) Algoritmo Crear(ES TArbol a);
Inicio
a=NIL;
Fin Crear
b) Algoritmo Crear(ES TArbol a);
Inicio
a=NIL
a->izq=NIL;
a->der=NIL
Fin Crear
d) Algoritmo Crear(ES TArbol a);
Inicio
Asignar(a);
a=NIL;
Fin Crear
5.- Si en un árbol binario de búsqueda inicialmente vacío insertamos en este orden los
siguientes elementos: T, H, R, O, U, G, Z, ¿cuál sería la forma final del árbol?
T
R
T
U
H
G
R
O
H
Z
G
U
O
T
H
Z
O
R
U
G
Z
6.- ¿Cuál de los siguientes códigos calcula el máximo valor en un árbol binario de naturales?
Supóngase que nunca se le pasa un árbol vacío como parámetro.
a) Algoritmo N Máximo(E ABinario a)
Inicio
SI a->dch <> NIL ENTONCES
DEVOLVER Máximo(a->dch)
EN OTRO CASO
DEVOLVER a->dato
FIN SI
Fin Máximo
b) Algoritmo N Máximo(E ABinario a)
Inicio
SI a->izq == NIL ENTONCES
SI a->der == NIL ENTONCES
DEVOLVER a->dato
EN OTRO CASO
DEVOLVER MAYOR(a->dato, a->der->dato)
FINSI
EN OTRO CASO
SI a->der == NIL ENTONCES
DEVOLVER MAYOR(a->dato, a->izq->dato)
EN OTRO CASO
DEVOLVER MAYOR(a->dato, MAYOR(a->izq->dato, a->der->dato))
FINSI
FIN SI
Fin Máximo
c) Algoritmo N Máximo(E ABina rio a)
Inicio
SI a->izq == NIL ENTONCES
SI a->der == NIL ENTONCES
DEVOLVER a->dato
EN OTRO CASO
DEVOLVER MAYOR(a->dato, Máximo(a->der))
FINSI
EN OTRO CASO
SI a->der == NIL ENTONCES
DEVOLVER MAYOR(a->dato, Máximo(a->izq))
EN OTRO CASO
DEVOLVER MAYOR(a->dato,
MAYOR(Máximo(a->izq), Máximo(a->der)))
FINSI
FIN SI
Fin Máximo