I was tasked. Write the algorithm so that the input of 2 data lists would have at least one common.
So this is my algorithm: (I am writing code in php)
$arrayA = array('5', '6', '1', '2', '7');
$arrayB = array('9', '2', '1', '8', '3');
$arrayC = array();
foreach($arrayA as $val){
if(in_array($val, $arrayB)){
array_push($arrayC, $val);
}
}
This is my own algo, not sure if he is good. So, based on my algorithm, how to find the best case and worst case (large O) formula?
Note. Please let me know if my algorithm is incorrect. My goal is "entering two lists of data will have at least one thing in common."
source
share