binary-search Questions
3
Solved
I have a vector of class objects sorted by its integer indices. But the index of an object is generated by the member function of the class - so no int id is stored as a member variable.
class bou...
Scabies asked 1/3, 2017 at 6:8
2
Solved
I noticed that as of Ruby 2.0.0 the array class has a bsearch method that I was testing and I'm not getting the behavior I'd expect. Why does it return a value for 2 and 5 but nil for -1, 1, and 4?...
Lodestar asked 22/4, 2014 at 14:8
16
Solved
We want to search for a given element in a circular sorted array in complexity not greater than O(log n).
Example: Search for 13 in {5,9,13,1,3}.
My idea was to convert the circular array into a ...
Gustin asked 14/5, 2010 at 13:57
3
Solved
I am stuck up with two time complexities. To do a binary search with sorted array is O(logN). So to search an unsorted array we have to sort it first so that becomes O(NlogN). So then we can perfor...
Imprison asked 9/4, 2013 at 20:33
3
I know how binary search works but I wanted to know practical uses for binary search...
I searched through the internet and I found that the main use is data base indexing, but I couldn't understan...
Lodovico asked 24/2, 2012 at 18:56
11
Solved
Simple question - given an IList<T> how do you perform a binary search without writing the method yourself and without copying the data to a type with build-in binary search support. My curre...
Child asked 8/6, 2009 at 21:9
7
Solved
Given an array of integers, find the local minima. An element A[i] is defined as a local minimum if A[i-1] > A[i] and A[i] < A[i+1] where i = 1...n-2. In case of boundary elements, the number ha...
Repand asked 2/9, 2012 at 17:37
1
Solved
I am trying to find and replace binary values in strings:
$str = '('.chr(0x00).chr(0x91).')' ;
$str = preg_replace("/\x00\x09/",'-',$str) ;
But I am getting "Warning: preg_replace(): Null byte i...
Fief asked 20/9, 2016 at 19:59
4
Solved
Here are two implementation of "forgetful" binary search, since they don't check for the exact match until they're finished.
1)
int bsearch1(int A[], int n, int target)
{
int low = 0, high = n -...
Lavinia asked 22/6, 2014 at 6:10
2
Solved
As per Java doc for Arrays.binarySearch(int[] a, int key)
Returns:
index of the search key, if it is contained in the array;
otherwise, (-(insertion point) - 1). The insertion point is defined as
...
Mercantilism asked 6/8, 2016 at 16:53
2
I am studying iterators and have been stuck for 3 days on figuring out why do we use:
auto mid = text.begin() + (end - beg) / 2;
Code:
int main()
{
vector<int> text{ 10,9,8,7,6,5,...
Binoculars asked 25/7, 2016 at 5:53
3
I want to modify the famous binary search algorithm to return the index of the next bigger item instead of the key being searched.
So we have 4 cases:
the key is smaller than all items, return 0...
Interlocutress asked 25/4, 2013 at 16:25
2
Solved
The generic List<T> in .NET has a BinarySearch() method. BinarySearch() is an efficient algorithm for searching large datasets. I think I read that if everyone in the world was listed in a ph...
Crossfertilization asked 16/6, 2016 at 19:35
3
Solved
This earlier question talks about doing binary search over a doubly-linked list in O(n) time. The algorithm in that answer work as follows:
Go to the middle of the list to do the first comparison...
Maas asked 24/10, 2013 at 0:11
3
Solved
I am trying to look for the position of vector elements into another vector. Here i am interested to use an implementation as fast as binary search. I have different vectors of length 1 million or ...
Christoperchristoph asked 12/5, 2016 at 10:44
5
Solved
If I had an array of integers with 1000 elements, what would be the fastest way to find a specific element's index? Would it be best to first QuickSort it and then use BinarySearch or just to use p...
Selfhypnosis asked 7/5, 2016 at 14:13
2
Solved
Given a list of dates in descending order, this code will find the largest date where the date is <= searchDate.
List<CurrencyHistoricExchangeRate> history = GetOrderedHistory();
foreach...
Oblivion asked 3/3, 2016 at 13:27
5
Solved
I appeared in an interview. I stuck in one question. I am asking the same.
Question: There is circular road is given. That road contains number
of petrol pumps. Each petrol pump have given amou...
Rosewater asked 6/11, 2012 at 19:38
2
Solved
I need to insert an element into sorted range, but I also need to know its index (number of elements in range that are less then the element). I want to do this in O(logN) time. Can I do this with ...
Grandiloquence asked 25/2, 2016 at 21:17
5
Solved
What is the simplest way to do a binary search on an (already) sorted NSArray?
Some potential ways I have spotted so far include:
The use of CFArrayBSearchValues (mentioned here) - would this work...
Illyricum asked 25/6, 2012 at 23:33
2
Solved
What is the difference between
int x = (right + left) / 2;
and
int x = left + (right - left) / 2;
just I got time limit exception in first case and got accepted in second case when doing bina...
Photooffset asked 25/12, 2015 at 20:25
1
Solved
It seems like there are eight variants of binary search (given a sorted list in ascending order):
Largest number less than target (but leftmost of duplicates)
Largest number less than target (but...
Pesek asked 4/12, 2015 at 15:33
6
Solved
The binary search is highly efficient for uniform distributions. Each member of your list has equal 'hit' probability. That's why you try the center each time.
Is there an efficient algorithm for ...
Davit asked 1/6, 2013 at 12:22
5
Solved
So, I was trying to implement the binary search algorithm (as generic as possible which can adapt to different cases). I searched for this on the internet, and some use, while (low != high) and som...
Searchlight asked 31/10, 2015 at 18:51
22
Every programmer is taught that binary search is a good, fast way to search an ordered list of data. There are many toy textbook examples of using binary search, but what about in real programming:...
Dalrymple asked 12/2, 2009 at 5:28
© 2022 - 2024 — McMap. All rights reserved.