Ruby#index Method VS Binary Search

后端 未结 1 1659
轮回少年
轮回少年 2021-01-18 18:59

Given an element and an array, the Ruby#index method returns the position of the element in the array. I implemented my own index method using binary search expecting mine w

1条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-18 19:14

    The built-in #index is not a binary search, it's just a simple iterative search. However, it is implemented in C rather than Ruby, so naturally it can be several orders of magnitude faster.

    0 讨论(0)
提交回复
热议问题