id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

binarySearch


Define a function that when passed an integer array sorted in ascending order, and another integer, performs binary search to return an index, any index, at which the item exists in the array. Return -1 if the item does not exist in the array. Google "binary search" to see the algorithm.


binarySearch([10, 20, 20, 20, 20, 70, 90], 10) → 0
binarySearch([10, 20, 20, 20, 20, 70, 90], 20) → 3
binarySearch([10, 20, 20, 20, 20, 70, 90], 70) → 5

...Save, Compile, Run (ctrl-enter)

int binarySearch(int[] a, int val) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 4 Post-solution available

Copyright Nick Parlante 2017 - privacy