Binary search · Busca binária
Binary search
The array is sorted and has n elements. Return the index of target, or -1 if it isn't present. Keep lo and hi bounds, check the middle each step, and discard the half that can't contain the target.
Busca binária
O array está ordenado e tem n elementos. Retorne o índice de target, ou -1 se não estiver presente. Mantenha lo e hi limites, verifique o meio a cada passo e descarte a metade que não pode conter o alvo.
Complete int binary_search(const int *a, int n, int target) for a sorted array of length n: return the index of target, or -1 if absent. · Complete int binary_search(const int *a, int n, int target) para um array ordenado de comprimento n: retorne o índice de target ou -1 se ausente.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.