Skip to main content
The 2024 Developer Survey results are live! See the results

Questions tagged [binary-search]

Binary search is an efficient algorithm for finding an element in a sorted array. The basic idea is to cut the search space in half in each step. The complexity of the algorithm is O(log(n)).

binary-search
0 votes
0 answers
16 views

Latest revyos TH1520 Linux kernel doesn't work on LicheePI 4a

Heyaw, We have a LicheePi4a board. We are using a linux kernel version that is around 8 months old (when we started the project more or less) which currently works. Now we tried to update the linux ...
Guillem Senabre's user avatar
2 votes
2 answers
82 views

Finding the subarray with the least median given a size K and an array of length N

I have been struggling the past month with this problem that was given to us on our course while I was upsolving it. The task is to find the window of size K with the least median in an array of ...
Lesserrafim's user avatar
4 votes
2 answers
66 views

Find if any number appears more than n/4 times in a sorted array

I was asked the following in an interview: Given a sorted array with n numbers (where n is a multiple of 4), return whether any number appears more than n/4 times. My initial thought was to iterate ...
Nab's user avatar
  • 43
0 votes
0 answers
40 views

Finding a $ ( non-numberic) in an array of numbers whose N is not known

Recently I got the above question. Here, $ (a non-numeric) data is to be find out in an array whose N (Length) is not known. One simplest approach is linear search by going one by one and comparing ...
Jaykumar's user avatar
  • 363
-1 votes
1 answer
41 views

Array Index Out Of Bound Error for Finding an element in an infinite array by Kunal Kushwaha video

My Code public class InfiniteElement{ public static void main(String[] args) { int[] arr = {1, 2, 4, 6, 8, 9, 10 , 13, 16, 19, 20 ,23, 27, 40, 42, 44}; int target = 44; ...
UDAYA KRISHNAN.M's user avatar
2 votes
3 answers
139 views

how to use index when searched column is not indexed but has the same ordering as the indexed primary key

I have a huge table (kind of audit log) with these columns: ID, TS, DATA ID is the primary key, and it is a number from a sequence. TS is a timestamp and it is the current timestamp of the insert. ...
riskop's user avatar
  • 1,757
2 votes
1 answer
149 views

Trying to understand how to search a BST with a given input

I am trying to figure out how to search a BST via a given input. The nodes in the tree have a randomly generated number as the key, and the value of the node is an object with various attributes. ...
rgs's user avatar
  • 23
0 votes
1 answer
55 views

LeetCode Python Interpreter giving a different answer from local interpreter [closed]

I was practicing some of the binary search based questions on LeetCode. I was working on the question 1283 (Find The Smallest Divisor). My python code was giving the wrong answer every time. I decided ...
Gokulkrishna V's user avatar
-1 votes
1 answer
33 views

Floor of a number in a sorted array with duplicates

Okay, so floor of a number in an array is defined as the largest number in the array that is lower than the provided number. If we find it in the array, we return its index, otherwise -1. For example, ...
BallsLikeWalnut's user avatar
0 votes
0 answers
40 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 ...
Denn's user avatar
  • 11
0 votes
1 answer
74 views

Number of comparison in best, avg and worst case in Binary Search [closed]

So I basically want to know what will be the Best, Avg and Worst case no of comparisons taken by Binary Search on a Sorted Array of N elements. Consider Both cases where the element is present and not ...
Arpit Jha's user avatar
0 votes
1 answer
64 views

Lower Bound in a sorted array not working as intended

pub fn find_floor(arr: &[i32], target: i32) -> Option<usize> { let (mut left, mut right) = (0, arr.len()); while left < right { let mid = (left + right) / 2; ...
KillerFC's user avatar
2 votes
4 answers
75 views

Optimized on-disk data structure for search with minimal random accesses

I have a huge file (~16TB) that contains a list of 8-byte keys mapped to 8-byte values. (2^40 pairs, 16 bytes each). I would now like to optimize the file so that I can search it efficiently. I have ...
Frederik's user avatar
0 votes
0 answers
20 views

Weakly increasing array, find lowest index of each value quickly

Suppose I have a weakly increasing integer array of the form A=[0,0,1,1,1,2,3,3,3]. I want to find the lowest index of each value, getting an array of the form r=[0,2,5,6]. Also, it is possible that ...
Xiutecuhtli's user avatar
-1 votes
1 answer
40 views

why doesn't my binary search method return -1 when it the target number doesn't appear in the array? It goes into a loop

public static int binarySearch(int[] x, int target) { int left = 0; int right = x.length - 1; int mid = (right + left ) / 2; while ( left <= right) { ...
jz9348's user avatar
  • 1

15 30 50 per page
1
2 3 4 5
202