Last answered:

24 Feb 2022

Posted on:

23 Feb 2022


Why not binary search has sort inside the function?

Hi !
Why the list is not sorted in the function?
As Giles mentioned we have sorted list (during description), so that comparing values respective to midpoint will be logically true.
I see no sort happening in the function but sorting the list which is argument.
Isn't the base of binary search algorithm depends on sorted list?

1 answers ( 0 marked as helpful)
Posted on:

24 Feb 2022



Thank you for your question!

You can definitely add one more line in the body of the function which sorts my_list. The way Giles has decided to do it, however, is to assume that the list is already sorted before feeding it into the algorithm. Either way works :)

Kind regards,
365 Hristina

Submit an answer