binary-search Questions

2

Solved

I want to find the index of the first integer in an array of integers which is <= key. I can do it with binary search in log2(N)+1 compares. Shouldn't it be possible with only log2(N) compares? ...
Dg asked 13/8, 2015 at 18:48

6

Solved

If I have the following vector {10 10 10 20 20 20 30 30} and I want a function to return the position of the integer that = X or directly the smaller element after X , like for example if I am sear...
Titos asked 15/11, 2012 at 14:11

7

I'm just starting to learn about parallel programming, and I'm looking at binary search. This can't really be optimized by throwing more processors at it right? I know it's supposedly dividing and...
Howler asked 7/12, 2011 at 23:1

9

I wonder, can binary search be applied on a 2D array? What would the conditions on the array be? Sorted on 2D?? What would be the time complexity for it? How would the algorithm change the bounda...
Tadashi asked 12/12, 2010 at 11:55

16

Solved

I heard somebody say that since binary search halves the input required to search hence it is log(n) algorithm. Since I am not from a mathematics background I am not able to relate to it. Can someb...
Aurelie asked 18/11, 2011 at 15:50

7

I am trying to search a descending sorted array using this binary search code. However, after I sort it, and try to search, it doesn't come back with any result, just a loading icon that never goes...
Terpineol asked 9/11, 2011 at 15:52

29

Solved

I'm trying to implement a binary search algorithm in JavaScript. Things seem okay, but my return statements appear to be returning undefined. Can anybody tell me what's wrong here? Fiddle: http://j...
Unspotted asked 27/3, 2014 at 19:57

35

Solved

I need to find the kth smallest element in the binary search tree without using any static/global variable. How to achieve it efficiently? The solution that I have in my mind is doing the operation...
Treasonable asked 24/2, 2010 at 20:18

8

Suppose an array has been given and want to find element in that array , how can you search an element in that array using binary search and that given array is already sorted and size of the array...
Psychologize asked 13/5, 2013 at 0:33

4

Solved

In the binary search algorithm, we set the mid as: mid = (start + end)/2 which is same as mid = start/2 + end/2 and also equal to mid = start + (end - start)/2 but all of the three give different r...
Hebe asked 10/7, 2023 at 11:25

11

Solved

How would I implement a binary search using just an array?

7

Solved

I have a python 3.x program that is producing an error: def main(): names = ['Ava Fischer', 'Bob White', 'Chris Rich', 'Danielle Porter', 'Gordon Pike', 'Hannah Beauregard', 'Matt Hoyle', 'Ross...
Woodenware asked 13/11, 2012 at 4:59

7

Solved

For example, we have {2,2,-1}, when k = 0, return -1. when k = 3, return 3. This is even tricky because we have negative numbers and an additional variable k. k can be any value, negative, don...

15

Solved

I use standard binary search to quickly return a single object in a sorted list (with respect to a sortable property). Now I need to modify the search so that ALL matching list entries are return...
Doloresdolorimetry asked 27/8, 2012 at 15:18

3

Solved

Can someone explain me when it comes to binary search we say the running time complexity is O(log n)? I searched it in Google and got the below, "The number of times that you can halve the searc...
Gothart asked 1/6, 2011 at 5:58

3

Solved

The basic idea of binary search in an array is simple, but it might return an "approximate" index if the search fails to find the exact item. (we might sometimes get back an index for which the val...
Scooter asked 9/11, 2012 at 10:43

14

Solved

I was reading an algorithms book which had the following algorithm for binary search: public class BinSearch { static int search ( int [ ] A, int K ) { int l = 0 ; int u = A. length −1; int m;...
Escarpment asked 18/7, 2011 at 15:22

15

Solved

Most of us are familiar with the maximum sum subarray problem. I came across a variant of this problem which asks the programmer to output the maximum of all subarray sums modulo some number M. T...
Maladminister asked 29/6, 2015 at 11:1

2

Solved

Does python provide functions for performing binary search on sorted lists, analogous to the std::lower_bound and std::upper_bound algorithms of the C++ Standard Library?
Uncinus asked 17/6, 2016 at 5:43

7

Solved

I have a list of dicts, something like this: test_data = [ { 'offset':0, 'data':1500 }, { 'offset':1270, 'data':120 }, { 'offset':2117, 'data':30 }, { 'offset':4055, 'data':30000 }, ] The di...
Explicate asked 27/8, 2009 at 23:43

6

I'm having a bit of trouble with this. The input array is based on file input and the size of the array is specified by the first line in the file. The binarySearch method seems to look alright but...
Selfwill asked 27/8, 2015 at 22:27

2

A supposed optimization made the code over twice as slow. I counted how often a value x occurs in a sorted list a by finding the range where it occurs: from bisect import bisect_left, bisect_right ...
Reproachful asked 8/7, 2022 at 15:59

16

Solved

I'm tinkering with some code and I realized something I never knew. A normal binary search will return a random index in a data set for a key that occurs more than once. How can I modify this code ...
Proselytize asked 13/7, 2011 at 8:47

3

I am quite confused about the scenarios when to use the = in binary search. For example, this is what i found from wiki, in which it is using while (imin <= imax) int binary_search(int A[], int...
Agony asked 24/2, 2016 at 21:32

22

Solved

Is there a library function that performs binary search on a list/tuple and return the position of the item if found and 'False' (-1, None, etc.) if not? I found the functions bisect_left/right in...
Giorgia asked 17/10, 2008 at 14:23

© 2022 - 2024 — McMap. All rights reserved.