Binary search is an efficient algorithm for finding a key in a sorted array. It runs in O(log n) time.
3
votes
1answer
95 views
Binary Search in C++ with array
Here is an array with exactly 15 elements:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Suppose that we are doing a binary search for an element. Indicate any elements that will be found by ...
0
votes
1answer
47 views
Efficient Method to Search in an Array where the maximum difference between previous and current element is 1
Array has property that an element in array can be equal , less than 1 or greater than 1 the previous element .
e.g. 6,6,6,5,4,3,3,4,5,5.
Better than O(N) solution needed as it is asked in the ...
1
vote
4answers
67 views
Segmentation fault in recursive Binary Search Algorithm in C
This is a C program with the recursive binary search algorithm, however when I run it, the debugger says there is an access segmentation fault in the binary search function. Why is this and how do I ...
0
votes
2answers
48 views
Using Binary Search to Sort a List in Python
My question accepts a (listof plane) structure where a plane is a list [airplane_code, date, price]:
airplane_code is the plane name
date is 1-365 inclusive where all dates might not be unique for ...
0
votes
1answer
62 views
Bash Script Binary Search
Write a bash script to do a binary search. Read student names and grades from a file into an array. Prompt the user for a student name. Find the name in the array and display the grade. The data in ...
0
votes
2answers
93 views
Word Beginning with String in Array
Interesting algorithm I would like to get the communities opinion on. I am looking to loop through a Sorted ArrayList<String> for the boolean result if a String exists in the array that begins ...
2
votes
1answer
27 views
Python binary search function from OCW
I have a question regarding the Python binary search algorithm as presented in the following MIT OCW lecture:
...
2
votes
3answers
71 views
Simple number guessing game using binary search algorithm in C
This program requires me to: Write a program that plays a simple number-guessing with its user. The user thinks of a number and then answers a series of questions asked by the computer until it ...
-2
votes
2answers
26 views
Issues writing a binary search program [closed]
I am a beginning programmer who is trying to write a simple binary search program. I have messed around with this program with several days but have not had any luck getting it to run as it should. I ...
0
votes
0answers
45 views
no matching function for call to 'lower_bound' with newer gcc
I'm having some trouble compiling code that uses std::lower_bound on systems with newer versions of gcc. From my tests, 4.1 works, but 4.6 fails.
Here is the relevant code snippet:
template ...
0
votes
0answers
14 views
Array to Hash Table
I am having a problem in how to implement code for a lookup table which speed is the most important factor...let me explain
I have this array to perform a lookup
vlong lba[73000];
where lba is an ...
4
votes
3answers
91 views
Searching through a partially sorted array in O(lgn)
I'm having a hard time solving this problem.
A[1..n] is an array of real numbers which is partially sorted:
There are some p,q (1 <= p <= q <=n) so:
A[1] <= ... <= A[p]
A[p] >= ... ...
2
votes
2answers
130 views
Throwing eggs from a building
This is exercise problem 1.4.24 from Robert Sedgewick's Algorithms 4th Edition.
Suppose that you have an N-story building and plenty of eggs. Suppose also that
an egg is broken if it is thrown off ...
6
votes
6answers
299 views
Fixing Binary search bug from Bentley's book (programming pearls: writing correct programs)
Binary search can be implemented in many ways-recursive, iterative, conditionals, etc. I took this from Bentley's book "Programming pearls: Writing correct programs" which is an iterative ...
4
votes
2answers
134 views
Algorithm: Modified Binary Search
I am trying to tackle a classical interview problem which is basically performing a binary search on a list which first increases then decreases. Even though it's obvious that we can achieve O(log n) ...