Learn
We now have a base case for when we do not find the value in our sorted list, but we need a base case for when we DO find the value.
At this step, we have three options:
- BASE CASE:
mid_val
matches ourtarget
- RECURSIVE STEP:
mid_val
is less than our target - RECURSIVE STEP:
mid_val
is more than our target
We’ll tackle the alternate base case first.
Instructions
1.
Let’s complete the base case for when we have found the value.
After the declarations for mid_val
and mid_idx
, write a conditional that checks if mid_val
is our target
.
If it is, return mid_idx
.
Sign up to start coding
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.