Status: Started
Objective
Write a recursive function that searches for an item in an array using binary search and returns `Found!` if the item is found, otherwise it returns `-1`. Assume the array is already sorted
Example: Find `4` in `[0, 1, 2, 4, 8]`
Inputs: `binarySearch([0,
- scratchpad.js
- Unit Test
Font Size
14
Parentheses autocomplete
Wrap lines
Editor
Theme
Code with blocks by default
Auto-Format
Console Font Size
12
Console Theme
Show File Tab Bar
Code Running Environment
Use the newest vesion of the JavaScript library.
Binary Search
Unit Test
1
2
function binarySearch(arr, num) {
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Output
Grading
Docs
Exercise
More
History
Video
Download
About
Test Cases
x/x
Pass | Test | Message | |
---|---|---|---|
- | Test results will show here. | - |
Errors:
This student is viewing this assignment in English. View this page in English?
8 points
Write a recursive function that searches for an item in an array using binary search and returns Found!
if the item is found, otherwise it returns -1
. Assume the array is already sorted
Example: Find 4
in [0, 1, 2, 4, 8]
Inputs: binarySearch([0, 1, 2, 4, 8], 4)
Expected Output: Found!
If you cannot find the value, return -1
Reset Code
Upload an image
Upload from your computer
Or paste a link here
Slides and Notes
No slides available for this video
About
JavaScript (function)