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

 

norm.krumpe@muohio.edu > binarySearch
prev  |  next  |  chance

Implement a recursive binary search method that searches a sorted int array for a given key, returning the index of that key if the element is found, and -1 if it is not found. You should not use loops. You will need to write a helper method that has additional parameters that allow indexes to be passed to indicate which part of the array is to be searched. The two-parameter method will have just one line of code in it: a line that calls the recursive binarySearch helper method.


binarySearch([3, 5, 10, 20, 25], 3) → 0
binarySearch([3, 5, 10, 20, 25], 10) → 2
binarySearch([3, 5, 10, 20, 25], 25) → 4

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

int binarySearch(int[] nums, int key) { }

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: 200

Copyright Nick Parlante 2017 - privacy