Questions tagged [binary-search]

Use this tag for code that implements a binary search.

16 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
7 votes
0 answers

Red-black tree appears to be slower than std::multimap

I've written a red-black tree in C as an exercise. The tree works and it is not bad, but it is about 10% slower than std::multimap from libstdc++ which I'm ...
Gaslight Deceive Subvert's user avatar
6 votes
0 answers

Subtracting elements of datasets of an HDF5 file

I am trying to solve the following problem: Input: Input is two arrays (Nx4, sorted in column-2) stored in datasets-1 and 2 in HDF5 file (input.h5). N is huge (...
nuki's user avatar
  • 61
5 votes
0 answers

Persistent segment tree

I'm trying to solve this problem. Given a sequence \$B=B_0,B_1,\ldots,B_{N−1}\$ for each query \$(P,K)\$, find the minimum \$S\$ s.t. there are at least \$K\$ entries in \$B\$ that satisfies ...
johnchen902's user avatar
4 votes
0 answers

Array Search Algorithm

Recently, I've been experimenting with an array searching algorithm that I'm not sure I've seen anywhere (minor references here). I'm still not fully-learned on how to state the efficiency of what I'...
Lapys's user avatar
  • 141
3 votes
0 answers

AVL Tree with delete method in Python 3

Just a general code review. I'm looking for my first developer job so anything constructive is awesome. Please, and thank you very much. I've written this implementation as an exercise and to add to ...
Paul K's user avatar
  • 373
3 votes
0 answers

Basic Binary Tree in Go

As an exercise I have written a basic binary tree implementation in Go. Tree struct: ...
miku's user avatar
  • 213
3 votes
0 answers

BST remove implementation

As practise, I implemented a BST and also the remove() method, but I figured I always have to check if the node being deleted is coming from the left child or the ...
sealife's user avatar
  • 31
2 votes
0 answers

Find Single Element in a Sorted Array, from LeetCode

The problem quoted: Given a sorted array consisting of only integers where every element appears exactly twice except for one element ...
nonopolarity's user avatar
2 votes
0 answers

Find target in sorted array pivoted at some unknown point in O(log n)

You are given an array sorted in ascending order which is rotated at some pivot unknown to you beforehand. Find your target in \$O(log n)\$ which means it should be a binary search. If the value ...
Rick's user avatar
  • 586
2 votes
0 answers

Three sum using binary search

Given an array and a value, find all the triplets in the array whose sum is equal to the given value. For example, if the given array is {12, 3, 4, 1, 6, 9} and the ...
Exploring's user avatar
  • 345
2 votes
0 answers

Computing the square root of a number using binary search

This is implemented in MIPS assembly. I've hard-coded the initial guess, as I haven't figured out how to allow the user to input a negative or non-negative integer to then display the result back to ...
bayou's user avatar
  • 21
1 vote
0 answers

USACO Silver "Wormhole Sort" solver

I'm struggling a bit with a USACO silver question using python, The question provides an unsorted list of numbers (cows) and a number of ...
Luke's user avatar
  • 11
1 vote
0 answers

BST range search

I'd like some input on my implementation of bst-range, which follows below. Before we can get to bst-range, we first need some setup code to build the BST. (You ...
mwal's user avatar
  • 493
1 vote
0 answers

Binary Search Implementation using template

This post is follow up of this, suggested by @loki-astari which can be found here. Any further improvement is welcome. Binary_Search.h ...
Abhisek's user avatar
  • 337
0 votes
0 answers

Python one-line binary search

jarOfCode's user avatar
-1 votes
0 answers

Finding the pivot point in a rotated array which has been shifted from kth element

I'm trying to solve the following problem: Joker has a deck of n cards, each with a value written on it. The cards are arranged in ascending order from top to bottom. Joker's master performs a hidden ...
driver's user avatar
  • 210