All Questions
Tagged with binary-search linear-search
63 questions
0
votes
0
answers
43
views
Linear Search performs better than HashMap+binary search to retrieve an object satisfying a condition [duplicate]
I was trying out this problem link.
So we have a list of (key,timestamp,value), where a single key can have multiple (timestamp,value) pairs , and we have to find the greatest timestamp <= a given ...
0
votes
1
answer
99
views
Why incorrect answer for the Painter's partition problem when input is very large?
I am solving GeeksforGeeks problem The Painter's Partition Problem-II
:
Dilpreet wants to paint his dog's home that has n boards with different lengths. The length of ith board is given by arr[i] ...
0
votes
3
answers
211
views
avr-gcc: Binary search vs. linear search
I am searching in a few arrays of struct stored in program memory with lengths of about 30-200 with a linear search like this:
Glyph getGlyph(Font font, uint16_t code) {
for (size_t i = 0; i < ...
1
vote
1
answer
49
views
Can anyone reduce time complexity of this code
You are given three integers A, B, and C. You are allowed to perform the following operation any number of times (possibly zero).
• Choose any integer X such that X ≤ max (A,B, C), and replace A with
...
0
votes
0
answers
39
views
BinarySearch not working for reversed array
I am working on a project for school that tests Binary Search vs. Linear Search. My LinearSearch method seems to work fine when the array is in either increasing order or reversed. However, the ...
-1
votes
2
answers
177
views
Try catch for ArrayIndexOutOfBoundsException [duplicate]
I am running a test for Binary search method for a value which is not found in an object array by using the try catch block, but the error ArrayIndexOutOfBoundsException is still being thrown.
Please ...
-2
votes
2
answers
698
views
Linear and Binary search in an array of objects in java
I'm creating an array of objects where the search should be by Linear method and Binary method.
The issue is how to traverse the array with the appropriate data type and compare.
public class FoodMain ...
-1
votes
2
answers
85
views
Can't understand why algorithm work so fast
I’ve been trying to use parametrised decorators and time function for becnhmark binary search vs linear algorithms running time and I don't understand, why with list size == 100m binary search runs 0....
0
votes
1
answer
493
views
Sorting Arrays Before binary search will Take big O (n)?
When i was learning about Big O Notations , while getting to know the binary search algorithm as it requires sorting the array before searching . I had a question that isn't sorting going to take the ...
1
vote
4
answers
2k
views
Binary search taking more time than linear search
I was recently studying about binary and linear search, and decided to check for real what is the difference in the actual time taken by both of these searching algorithms. Here is my code:
#include &...
1
vote
3
answers
617
views
Binary search vs linear search
I have the following implementation of binary search:
import time
numbers_one_to_hundred=[]
for num in range(1,100001,2): #25 66 35 64 (38,101) (1,101)
numbers_one_to_hundred.append(num)
print('...
1
vote
1
answer
78
views
I was implementing binary search in C and I'm facing this problem which is that its not printing the index number of the element
Function For Binary Search
#include <stdio.h>
int binarySearch(int arr[], int size, int element, int low, int high)
{
int mid;
while (low <= high)
{
if (arr[mid] == ...
0
votes
2
answers
1k
views
How to Develop algorithms for linear search and binary search using Pseudo code.?
Searching on an array/list is to find a given element on the array and return whether it is found or not and return its position if found. Linear search and binary search are two popular searching ...
1
vote
2
answers
385
views
Linear search vs binary search real time performance in C++
Getting totally unexpected results while comparing binary search vs linear search's real time performance in C++ using the code below -
typedef std::chrono::microseconds us;
int linear_search(...
-1
votes
2
answers
692
views
Combining binary search and linear search or any other algorithm
I want to ask, I'm still learning about time complexity.
I got a problem, the question asked me to calculate the time complexity of a binary search,
The time complexity of a binary search is O(log m).
...