Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/kenri89/PROYECTO_UTP_AED_1_1/llms.txt

Use this file to discover all available pages before exploring further.

ArbolEstudiantes in estructuras.ArbolEstudiantes implements a standard unbalanced Binary Search Tree. The BST key is the carnet field of each Estudiante object, and ordering is determined by Java’s String.compareTo(), which gives lexicographic (alphabetical) ordering across all carnet strings. Every node holds a direct reference to an Estudiante model object — there is no separate key/value split.

Internal Node Structure

The node class is a private static inner class invisible to callers. It stores a reference to the Estudiante payload and left/right child pointers.
private static class Nodo {
    Estudiante estudiante;
    Nodo izquierda, derecha;

    Nodo(Estudiante estudiante) {
        this.estudiante = estudiante;
    }
}

Public API

1

insertar(Estudiante nuevo)

Recursive BST insert descending from raiz. At each node the carnet of nuevo is compared with String.compareTo() — go left if negative, go right if positive, skip if equal (duplicate carnets are silently ignored). Average complexity is O(log n); worst case with sorted inserts is O(n).
public void insertar(Estudiante nuevo) {
    raiz = insertarRec(raiz, nuevo);
}
2

buscar(String carnet)

Recursive lookup that halves the search space at every node. Returns the matching Estudiante or null if not found. Average complexity O(log n).
public Estudiante buscar(String carnet) {
    return buscarRec(raiz, carnet);
}
3

actualizar(String carnet, String nuevoNombre, String nuevaCarrera)

Delegates to buscar to locate the node, then mutates the nombre and carrera fields in-place. The carnet (BST key) is never changed. Returns true if found, false otherwise. Complexity O(log n).
public boolean actualizar(String carnet, String nuevoNombre, String nuevaCarrera) {
    Estudiante est = buscar(carnet);
    if (est != null) {
        est.setNombre(nuevoNombre);
        est.setCarrera(nuevaCarrera);
        return true;
    }
    return false;
}
4

eliminar(String carnet)

Standard BST removal with in-order successor promotion for two-child nodes. Complexity O(log n) average. See the deletion algorithm section below for details.
public void eliminar(String carnet) {
    raiz = eliminarRec(raiz, carnet);
}
5

inorden(Consumer<Estudiante> accion)

Left-root-right recursive traversal that visits every node exactly once in ascending carnet order. The caller provides a Consumer<Estudiante> lambda — typically lista::add or a table-row builder. Complexity O(n).
public void inorden(Consumer<Estudiante> accion) {
    inordenRec(raiz, accion);
}
6

limpiar()

Sets raiz = null, making the entire tree eligible for garbage collection. O(1).

Deletion Algorithm

When the node to be deleted has two children, the algorithm finds the in-order successor — the node with the smallest carnet in the right subtree — copies its Estudiante data into the current node, then recursively deletes the successor from the right subtree. This guarantees the BST property is preserved after every deletion.
private Nodo eliminarRec(Nodo actual, String carnet) {
    if (actual == null) return null;
    int cmp = carnet.compareTo(actual.estudiante.getCarnet());
    if (cmp < 0) {
        actual.izquierda = eliminarRec(actual.izquierda, carnet);
    } else if (cmp > 0) {
        actual.derecha = eliminarRec(actual.derecha, carnet);
    } else {
        // Zero or one child — promote the non-null child (or null)
        if (actual.izquierda == null) return actual.derecha;
        if (actual.derecha == null) return actual.izquierda;
        // Two children — replace with in-order successor
        actual.estudiante = encontrarMinimo(actual.derecha);
        actual.derecha = eliminarRec(actual.derecha, actual.estudiante.getCarnet());
    }
    return actual;
}

private Estudiante encontrarMinimo(Nodo actual) {
    while (actual.izquierda != null) {
        actual = actual.izquierda;
    }
    return actual.estudiante;
}

Usage Example

ArbolEstudiantes arbol = new ArbolEstudiantes();
arbol.insertar(new Estudiante("2024003", "Carlos Vega", "Redes"));
arbol.insertar(new Estudiante("2024001", "Ana Ramos", "Computación"));
arbol.insertar(new Estudiante("2024002", "Luis Fuentes", "Electrónica"));

// In-order traversal outputs sorted by carnet: 2024001, 2024002, 2024003
List<Estudiante> lista = new ArrayList<>();
arbol.inorden(lista::add);

arbol.actualizar("2024001", "Ana María Ramos", "Computación");
arbol.eliminar("2024002");
The BST is unbalanced — repeated sequential inserts (e.g., carnets in strict ascending order) cause the tree to degenerate into a linear chain, degrading all operations to O(n). For the typical use case with randomly distributed carnets this effect is negligible, and self-balancing was deliberately excluded as out-of-scope for the course unit.

Build docs developers (and LLMs) love