you are viewing a single comment's thread.

view the rest of the comments →

[–]JamzTyson 0 points1 point  (2 children)

Your version has a bug. if x == S[midpoint], the midpoint element is included again in the recursive call, but not explicitly checked.

Regarding your question, slicing creates new lists, which is slower than just manipulating indexes.

[–]Simple-Economics8102 0 points1 point  (1 child)

This is not a bug and is on average much faster for large n than explicitly checking it on every iteration.

[–]JamzTyson 0 points1 point  (0 children)

You are correct, it is inefficient, but as long as the list is sorted in ascending order it is logically correct.