Code Explainers
Code explainers tagged #binary-search
java
public final class PrefixSearch { private final String[] words;
Prefix search with binary search bounds
binary-search
sorting
range-query
Intermediate
9 steps
rust
use rand::Rng; #[derive(Debug)] pub struct WeightedChoice<T> {
Weighted random sampling in Rust
weighted-sampling
generics
binary-search
Intermediate
7 steps
javascript
class LyricsSync { constructor(audio, container, lines) { this.audio = audio; this.container = container;
Building a synced lyrics highlighter
binary-search
dom-manipulation
event-handling
Intermediate
9 steps
go
package hashring import ( "hash/crc32"
How consistent hashing works in Go
consistent-hashing
load-balancing
concurrency
Intermediate
8 steps
python
from difflib import SequenceMatcher from bisect import bisect_left, bisect_right
Building a fuzzy autocomplete matcher
fuzzy-matching
binary-search
ranking
Intermediate
9 steps
rust
use std::cmp::Ordering; pub struct PrefixIndex { entries: Vec<String>,
Prefix search with binary partitioning in Rust
binary-search
sorting
case-insensitive
Intermediate
7 steps
python
import bisect from typing import Sequence
Computing latency percentiles in Python
percentiles
interpolation
binary-search
Intermediate
8 steps
ruby
class WeightedSampler def initialize(weights) @entries = weights.to_a @total = @entries.sum { |_, w| w }
Weighted random sampling with binary search
weighted-sampling
binary-search
cumulative-sum
Intermediate
7 steps
ruby
# Binary search using Ruby's built-in Array#bsearch. # # There are two modes: # 1. find-minimum mode -> block returns true/false (monotonic)
Binary search patterns with Ruby's bsearch
binary-search
algorithms
ranges
Intermediate
7 steps