79103091

Date: 2024-10-18 17:29:25
Score: 1
Natty:
Report link

Yes, using a binary search and assuming element is in the set, log2(N) compares will suffice.

However, if your element is not in the set, it could take you log2(N) + 1, compares to realize that you have exhausted the set. The final comparison is to an empty set which let's you realize you are done.

Personally, I wondered if the comparison to an empty set counts as a comparison, but the text I'm reading counts it as a step the computer would take increasing the runtime by one step.

Reasons:
  • No code block (0.5):
  • Low reputation (0.5):
Posted by: bc1121