Skip to content

Instantly share code, notes, and snippets.

View alyamovsky's full-sized avatar
👾

Andrew Alyamovsky alyamovsky

👾
View GitHub Profile
@CMCDragonkai
CMCDragonkai / bisecting_binary_search.php
Last active April 2, 2023 01:57
PHP: Bisect Left & Bisect Right using Binary Search (similar to Python's bisect_left & bisect_right). Binary search only works on sorted arrays. Arrays must be first sorted with quick sort. Bisect right finds the index of a value where all the elements from left to right up to the index is less or equal to the value: Array: [1, 1, 2, 2, 3, 4] Va…
<?php
// sorted array must be a 0 indexed
// left most index, right most index all inclusive
// finds all of the elements coming from the left to the right that is less or equal to the key
function bisect_right($sorted_array, $key, $left = null, $right = null){
if(is_null($left)){
reset($sorted_array);
$left = key($sorted_array);
@magnetikonline
magnetikonline / README.md
Last active June 6, 2024 06:16
Setting Nginx FastCGI response buffer sizes.