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

 

james.shockey@austinisd.org > binarySearch
prev  |  next  |  chance

Binary Search - Your task is to create a method that searches through a primitive array (int[]). The method should return an array of size 2: the first element is the value at the midpoint where the search converged, and the second element is the value at the previous midpoint checked before the last comparison. If the target value is not found, the method should still return the last midpoint value and the previous value examined. These values will help you trace how the binary search narrows down the search space and finds (or fails to find) the target efficiently.


binarySearch([1, 2, 3, 4, 5, 6, 7], 7) → [7, 6]
binarySearch([5, 6, 7, 8, 9, 10], 8) → [8, 9]
binarySearch([1, 9, 19, 22, 30, 33, 44, 60, 65, 82, 89, 94, 99], 22) → [22, 30]

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

public int[] binarySearch(int[] array, int target) { }

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

Copyright Nick Parlante 2017 - privacy