FAQs on the exercise Recursive Binary Search: The Recursive Steps

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply () below!

Agree with a comment or answer? Like () to up-vote the contribution!

I am not understanding how the result is calculated in the recursive code for (result + mid_idx + 1). Mid_idx is fixed at half of the sorted_list. 1 is added to the zero based index. Result should always be 1, as the last iteration of binary_search? So if Result is always 1, then a right hand value would not work, because (1 + Mid_idx + 1) < index. Unless result is being stored somehow dynamically? Thank you.

This coarse in Python is good. if anybody is wondering . What the program word Node is doing. It writes the y and x in memory. x,y, O(n)…cx, dx… registers of CPU…edon. thus Node. THANKS

Its because when you are meeting the condition of using the right half of your original list, you are taking the a slice of that list starting from the mid index of the original list plus one index. Now the right half of your list is a new list with different indeces for the same values seen in the original list. For example, you are searching for 5 in the list [0,1,2,3,4,5,6,7] which is at index 6. Going through the function you will need use recursion to slice the list and take the right half [4,5,6,7] but now your target value of 5 is at index 2. To reference the original list, you would have to take this into consideration so saving it to result and adding mid_idx+1 will give you the reference to the original list

ok thanks its starting to make sense, from the lesson, result returns 0 after recursive call on the right half, then the mid_idx is 2, so its (0 + 2 + 1) = 3, and index of 16 in original list is 3.

To anyone who still doesnt get it, first experiment returning without adding result to mid_idx + 1, you’ll see you only get 0. But thats not the index of 16 in the original list.