function seq_sch($array, $n, $k){
$array[$n] = $k;
for($i=0; $i<$n; $i++){
if( $array[$i]==$k){
break;
}
}
if ($i<$n){
return $i;
}else{
return -1;
}
}
Time complexity
If a violent algorithm is used to search in an ordered array, that is, one by one traversal comparison, then the time complexity is O(n); however, after using binary search, because half of the search interval can be discarded each time, so Will reduce the time complexity to O(logn).