(Coding) Search for first instance of k in sorted array more efficiently than O(n).
Utilisateur anonyme
input = 1:20 k = 8 l = length(input) if(k <= input[floor(l/2)]) { start_index <- 1 end_index <- floor(l/2) } else { start_index <- floor(l/2)+1 end_index <- l } for(i in start_index:end_index) { if(input[i] == k) { print(i) } }