Questions tagged [binary-search]
Use this tag for code that implements a binary search.
303
questions
2
votes
3
answers
160
views
Creating a search function
Write an efficient function in the Python language called SmartSearch. This function will receive a sorted arr array of integers of size \$n\$ containing at the ...
5
votes
1
answer
188
views
Testing binary search module, based on bisect
The bisect module can only find the index to insert an element. I created a simple class based on the bisect module for precise searching and covered all the edge cases that came to mind with tests.
...
3
votes
1
answer
130
views
Incremental upper bound in sorted range
Since initial question Increasing binary search for mismatch in sorted range contained defects in code and can confuse the readers, here is the updated version of the question.
Is the code below ...
3
votes
2
answers
202
views
Counting duplicate elements in two sorted arrays
I've been working on an assignment that involves optimizing a duplicate finding algorithm for sorted arrays, and I'd like to get your thoughts on the implementation. Here's the code I've come up with:
...
4
votes
1
answer
306
views
K&R exercise 3-1
...
9
votes
3
answers
2k
views
Optimizing the Egg Drop Problem implemented with Python
I've implemented the Egg Drop Problem using Python. As described in the code, I'm trying to find the highest floor of a 102-story building from which I could drop an egg without it breaking.
The ...
4
votes
3
answers
1k
views
C++ Binary Search
Could you advise on this binary search implementation?
...
-2
votes
2
answers
141
views
1
vote
1
answer
106
views
Binary search of 2D matrix
I have written code as below:
...
1
vote
0
answers
112
views
USACO Silver "Wormhole Sort" solver
I'm struggling a bit with a USACO silver question using python, http://usaco.org/index.php?page=viewproblem2&cpid=992.
The question provides an unsorted list of numbers (cows) and a number of ...
3
votes
1
answer
2k
views
Find closest value in a big list
There are solutions e.g.
list.OrderBy(item => Math.Abs(number - item)).First()
or
...
3
votes
2
answers
392
views
Implementation of a market that matches bids to offers
This is my task:
Each line in the file can be one of the following:
Updates to the limit order book in the following format:
...
3
votes
2
answers
1k
views
Non recursive binary search in C
I wrote a non recursive binary search implementation in C, for this time I think there are no bugs.
Here's the code:
...
4
votes
3
answers
269
views
Increase efficiency of stick cutting algorithm
I have this typical code interview type problem.
Suppose you have a stick of length n. You make X cuts in the stick at places x1, x2, x3 and so on. For every cut in X cuts you need to print the length ...
0
votes
1
answer
37
views
Improving time complexity for codechef Que [closed]
Question Link.
Binary Search and Two Pointers related question.
For the above-mentioned question, In other people's solutions, people get AC with a binary search solution. However, I get TLE with ...