Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to calculate the middle index in the recursive binary search.
DSA Go
mid := low + ([1] - low) / 2
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using low instead of high causes incorrect middle calculation.
Using length of array instead of high index.
✗ Incorrect
The middle index is calculated as low plus half the distance between high and low.
2fill in blank
mediumComplete the code to check if the middle element is equal to the target value.
DSA Go
if arr[mid] == [1] {
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing with index instead of target value.
Using low or high instead of target.
✗ Incorrect
We compare the middle element with the target value to find a match.
3fill in blank
hardFix the error in the recursive call when the target is less than the middle element.
DSA Go
return binarySearch(arr, low, [1], target)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using mid + 1 searches the right half incorrectly.
Using low or high without adjustment causes infinite recursion.
✗ Incorrect
When target is less than middle element, search left half by setting high to mid - 1.
4fill in blank
hardFill both blanks to correctly call the recursive function when the target is greater than the middle element.
DSA Go
return binarySearch(arr, [1], [2], target)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping low and high values.
Using mid - 1 instead of mid + 1 for low.
✗ Incorrect
When target is greater, search right half by setting low to mid + 1 and keeping high same.
5fill in blank
hardFill all three blanks to complete the base case that stops recursion when the target is not found.
DSA Go
if [1] > [2] { return [3] }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning 0 instead of -1.
Checking if high > low instead of low > high.
✗ Incorrect
If low is greater than high, target is not in array, so return -1.