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
560 views

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
91 views

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
447 views

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
70 views

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
2k views

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
68 views

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
532 views

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
258 views

Find Single Element in a Sorted Array, from LeetCode

The problem quoted: https://leetcode.com/problems/single-element-in-a-sorted-array/ 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
48 views

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
969 views

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
571 views

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
109 views

USACO Silver "Wormhole Sort" solver

I'm struggling a bit with a USACO silver question using python, http://usaco.org/index.php?page=viewproblem2&cpid=992. The question provides an unsorted list of numbers (cows) and a number of ...
Luke's user avatar
  • 11
1 vote
0 answers
62 views

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
3k views

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
259 views

Python one-line binary search

...
jarOfCode's user avatar
-1 votes
0 answers
47 views

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