binary-search

Can we use binary search with an unsorted array? [duplicate]

99封情书 提交于 2020-08-24 05:09:42
问题 This question already has answers here : Time complexity of binary search for an unsorted array (3 answers) Closed 4 years ago . I have an array that looks like 2 6 8 5 34 1 12 Can I use a binary search on some subarray? 回答1: You can use binary search on only one kind of "unsorted" array - the rotated array. It can be done in O(log n) time like a typical binary search, but uses an adjusted divide and conquer approach. You can find a discussion about it here. 回答2: No, binary search needs a

Can we use binary search with an unsorted array? [duplicate]

戏子无情 提交于 2020-08-24 05:08:45
问题 This question already has answers here : Time complexity of binary search for an unsorted array (3 answers) Closed 4 years ago . I have an array that looks like 2 6 8 5 34 1 12 Can I use a binary search on some subarray? 回答1: You can use binary search on only one kind of "unsorted" array - the rotated array. It can be done in O(log n) time like a typical binary search, but uses an adjusted divide and conquer approach. You can find a discussion about it here. 回答2: No, binary search needs a

Why Numba doesn't improve this recursive function

核能气质少年 提交于 2020-07-03 12:56:11
问题 I have an array of true/false values with a very simple structure: # the real array has hundreds of thousands of items positions = np.array([True, False, False, False, True, True, True, True, False, False, False], dtype=np.bool) I want to traverse this array and output the places where changes happen (true becomes false or the contrary). For this purpose, I've put together two different approaches: a recursive binary search (see if all values are the same, if not, split in two, then recurse)