Binary search · Recherche binaire
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.
Recherche binaire
Le tableau est trié. Retournez l'indice de target, ou -1 s'il n'est pas là. La recherche binaire réduit la plage de moitié à chaque étape : vérifiez l'élément central, puis continuez à chercher seulement dans la moitié gauche ou droite. Bien plus rapide que de parcourir chaque élément.
Complete binarySearch(int[] a, int target) for a sorted array a: return the index of target, or -1 if absent. Use binary search. · Complétez binarySearch(int[] a, int target) pour un tableau trié a : retournez l'indice de target, ou -1 s'il est absent. Utilisez la recherche dichotomique.
Click Run to see the output here. · Cliquez sur Exécuter pour voir le résultat ici.