Does a binary search work for odd number of elements ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JUNAYED HOSSAIN
    New Member
    • Nov 2017
    • 1

    Does a binary search work for odd number of elements ?

    Is binary search work for odd number OF element ?
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Yes. But you must always be sure to set your range correctly. Your end marker must point to one past the end element and not at the element itself or you will lose the end element in the search.

    Comment

    • donbock
      Recognized Expert Top Contributor
      • Mar 2008
      • 2427

      #3
      Are you using the stdlib bsearch() function or are you writing your own binary search function?

      Comment

      Working...