Binary search · Búsqueda binaria
Binary search
The array is sorted. Return the index of target, or -1 if it isn't there. Binary search halves the range each step: check the middle element, then keep looking in just the left or right half. Far faster than scanning every element.
Búsqueda binaria
El array está ordenado. Devuelve el índice de target, o -1 si no se encuentra. La búsqueda binaria reduce a la mitad el rango en cada paso: se revisa el elemento central y luego se continúa buscando solo en la mitad izquierda o derecha. Es mucho más rápida que examinar cada elemento uno por uno.
Complete binarySearch(int[] a, int target) for a sorted array a: return the index of target, or -1 if absent. Use binary search. · Completa binarySearch(int[] a, int target) para un array ordenado a: retorna el índice de target, o -1 si no está presente. Usa búsqueda binaria.
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.