0
0
DSA Goprogramming~10 mins

Binary Search Recursive Approach in DSA Go - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Ahigh
Blen(arr)
Cmid
Dlow
Attempts:
3 left
💡 Hint
Common Mistakes
Using low instead of high causes incorrect middle calculation.
Using length of array instead of high index.
2fill in blank
medium

Complete 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'
Amid
Blow
Chigh
Dtarget
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing with index instead of target value.
Using low or high instead of target.
3fill in blank
hard

Fix 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'
Ahigh
Bmid + 1
Cmid - 1
Dlow
Attempts:
3 left
💡 Hint
Common Mistakes
Using mid + 1 searches the right half incorrectly.
Using low or high without adjustment causes infinite recursion.
4fill in blank
hard

Fill 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'
Amid + 1
Bmid - 1
Chigh
Dlow
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping low and high values.
Using mid - 1 instead of mid + 1 for low.
5fill in blank
hard

Fill 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'
Alow
Bhigh
C-1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Returning 0 instead of -1.
Checking if high > low instead of low > high.