Skip to main content
Filter by
Sorted by
Tagged with
-1 votes
0 answers
26 views

Java error: missing return statement in BinSearch [duplicate]

I am figuring out searching algorithms and when I copied the following code, I received the error "missing return statement". I would also like to know why int k (supposedly the number I'm ...
Raimund Lampert's user avatar
0 votes
1 answer
79 views

Clojure mutant – can't kill a surviving mutant in binary search

I'm writing a classic binary search function in Clojure and testing it with the mutant mutation testing library. My tests work fine in terms of correctness, but mutation testing reports one surviving ...
Raíssa Barreira's user avatar
0 votes
2 answers
79 views

Find start index of a rotated non-decreasing array

This is part of a interview question I recently came across and Im not able to find an elegant solution for this. Can someone please help. Q - We have a non-decreasing sorted array, which is rotated ...
rsundhar's user avatar
  • 127
-3 votes
3 answers
109 views

How to do binary search correctly [closed]

I am trying to solve this question on Leetcode: 74. Search a 2D Matrix You are given an m x n integer matrix matrix with the following two properties: Each row is sorted in non-decreasing order. The ...
user430243's user avatar
-3 votes
2 answers
74 views

Binarysearch with Python with recursion

def binarysearch(a,n): mid=int(len(a)/2) #taking the middle point if(n==a[mid]): return mid elif(n>a[mid]): #if greater then do binarysearch in smaller part binarysearch(a[(mid+1):],n) ...
maths and chess's user avatar
0 votes
0 answers
37 views

Finding an element in the matrix with a least amount of steps

I have a W x H matrix, random starting position x0,y0, and the target with unknown coordinates. On every step I get information of direction to the target (above-below, left-right) and then have to ...
Yung Venuz's user avatar
1 vote
2 answers
59 views

What is the idiomatic way to handle code duplication in match bindings for Result? [duplicate]

I'll give some context here. The closure foo takes in a character and inserts it into a sorted vector. foo uses binary_search_by_key to insert the character into the vector at the correct index. What ...
kesarling's user avatar
  • 2,280
0 votes
0 answers
60 views

Generic binary search Java with Comparator and Comparable [duplicate]

I'm being asked to create a binary search that can use either Comparable or Comparator depending on which constructor is being used. I made a private boolean to note whether or not to use the object's ...
Drake's user avatar
  • 19
1 vote
1 answer
56 views

When are bisect_left(arr, x) and bisect_right(arr, x-1) equal?

If you are doing this on a sorted array arr then would bisect_left(arr, x) == bisect_right(arr, x-1) under any circumstances?
srm26's user avatar
  • 11
0 votes
2 answers
115 views

How does this code manage to correctly find the peak element's array index using binary search on an unsorted array?

The below code is using binary search. Since the array is not sorted, how does it manage to correctly figure out the peak element's index? Generally it works on sorted arrays only, right? Input: arr = ...
Prasun's user avatar
  • 119
-3 votes
2 answers
102 views

What are the arguments of comp for lower_bound() in C++?

I'm trying to create a custom comparison function for the binary search method lower_bound(). I've tried reading the docs and searching, but I can't figure out how the arguments of the comp function ...
Aya Noaman's user avatar
0 votes
2 answers
31 views

Binary search 704 leetcode calling a function in python 3

class Solution: def search(self, nums: List[int], target: int) -> int: #establish a left and right limit l = 0 #this will take from the right and push more ...
trevy berton's user avatar
0 votes
0 answers
66 views

How to accurately measure memory usage for iterative and recursive binary search algorithms in Java?

I am benchmarking the performance of iterative and recursive binary search algorithms in Java, specifically measuring both execution time and memory usage for different dataset sizes. However, I am ...
Ersin Karaduman's user avatar
1 vote
0 answers
73 views

Are There More Efficient Awaiters for C++ Coroutines Than std::suspend_always?

I’m attempting to optimize a binary search workload using C++ coroutines on a 1GB sorted array of unique random integers to induce multiple memory misses. The approach involves using co_await when ...
Hod Badihi's user avatar
1 vote
1 answer
79 views

Using the compare() function with strings

I have to use a binary search to find a movie that the user inputs, however, when doing certain movies, or movies that aren't in the list, the search loops forever. I was told it was cause I can't use ...
Israel Villegas's user avatar

15 30 50 per page
1
2 3 4 5
202