One thing to bear in mind about the performance benchmark results, the (slower) Array#find_index method uses a linear search because the Array method cannot assume that the array is already sorted (the precondition for binary search to work). Just pointing this out since the required "sorted input" condition wasn't mentioned in your post. I'm sure it's covered in the linked video (he says "hopefully sorted" but then uses a telephone book which is definitely sorted), so worth pointing out.
Thanks for your comment 😀
Yes, the binary search algorithm can work properly only with sorted data. Array#find_index can perfectly work with sorted and unsorted data. But if you have huge array of data and the array is sorted, binary search will be highly effective.
So, my intention was to inspire people (and me) to keep on studying algorithms, maybe it's the reason why I didn't mention it 🙈
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
One thing to bear in mind about the performance benchmark results, the (slower)
Array#find_index
method uses a linear search because the Array method cannot assume that the array is already sorted (the precondition for binary search to work). Just pointing this out since the required "sorted input" condition wasn't mentioned in your post. I'm sure it's covered in the linked video (he says "hopefully sorted" but then uses a telephone book which is definitely sorted), so worth pointing out.Thanks for your comment 😀
Yes, the binary search algorithm can work properly only with sorted data.
Array#find_index
can perfectly work with sorted and unsorted data. But if you have huge array of data and the array is sorted, binary search will be highly effective.So, my intention was to inspire people (and me) to keep on studying algorithms, maybe it's the reason why I didn't mention it 🙈