Tag: BINARY-SEARCH-TREE
¿Cuál es la diferencia entre: return(checkBst(root->left, minvalue, root) && checkBst(root->right, root, maxvalue)); y return(checkBst(root->left, minvalue, root)); return(checkBst(root->right, root, maxvalue)); Mi programa completo se ve así: bool checkBst(node *root, node * minvalue, node * maxvalue){ if(root == NULL){ return true; } if((minvalue && root->data <= minvalue->data) || (maxvalue && root->data >= . . . Read more
Aquí está mi función constructora y mi método ‘add’… function BinarySearchTree(value) { this.value = value; this.right = null; this.left = null; } BinarySearchTree.prototype.add = function(value) { if (value < this.value) { if (this.left) this.left.add(value); else this.left = new BinarySearchTree(value); } if (value > this.value) { if (this.right) this.right.add(value); else this.right . . . Read more
import java.util.*; public class Practice { static ArrayList<integer> populateList(Scanner sc , ArrayList<integer> al){ String l = sc.nextLine(); String arr[] = l.trim().split(“\\s++”); for(int i = 0; i<arr.length; i++){=”” al.add(integer.parseint(arr[i]));=”” }=”” return=”” al;=”” }=”” static=”” void=”” displaylist(string=”” s=”” ,=””></arr.length;><integer> al){ System.out.print(s+ “: “); for(int i = 0; i<al.size(); i++){=”” system.out.print(al.get(i)+=”” );=”” }=”” . . . Read more
Estaba tratando de ejecutar el programa Binary Search en Python. Seguí los pasos del algoritmo, pero me da este error. Aquí está mi código: def binarySearch(a, k, l, r): if l > r: return -1 else: mid = (l + (r – l)) // 2 if(a[mid] > k): return binarySearch(a, . . . Read more
Estoy tratando de implementar la función de eliminación en un árbol de búsqueda binaria. Sé que los tres pasos son: Identificar el nodo a eliminar y el nodo más profundo. Reemplazar sus datos con los datos del nodo más profundo. Eliminar el nodo más profundo. Intenté implementarlo así, pero la . . . Read more