This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function JumpSearch($list, $find) | |
{ | |
$len = count($list) ; | |
$slice = floor(sqrt($len)); | |
$prev = 0; | |
while ($list[min($slice, $len)] < $find || $prev >= $len) { | |
$prev = $slice; | |
$slice += floor(sqrt($len)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function binarySearchIterative($list, $find) | |
{ | |
$left = key($list); | |
$right = count($list) -1; | |
while ($left <= $right) { | |
$mid = floor(($left + $right) / 2); | |
if ($find == $list[$mid]) { | |
return $mid; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function interpolationSearch($list, $find) | |
{ | |
$low = 0; | |
$high = count($list) - 1; | |
while ($low <= $high && $find >= $list[$low] && $find <= $list[$high]) { | |
$pos = floor($low + (($high-$low) / | |
($list[$high]-$list[$low])) * ($find - $list[$low])); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function binarySearchRecursion($array, $find, $left, $right) | |
{ | |
if ($left > $right) { | |
return -1; | |
} | |
$middle = floor( ($left + $right) / 2 ); | |
OlderNewer