How to find the formula of best case and worst case of my algorithm?

Posted by rachel7660 on Stack Overflow See other posts from Stack Overflow or by rachel7660
Published on 2010-04-19T17:20:05Z Indexed on 2010/04/19 17:23 UTC
Read the original article Hit count: 202

Filed under:
|
|

I was given a task. Write an algorithm so that, the input of 2 lists of data, will have at least one in common.

So, this is my algorithm: (I write the 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);
    }
}

Thats my own algo, not sure if its a good one. So, based on my algorithm, how to find the formula of best case and worst case (big O)?

Note: Please do let me know, if my algorithm is wrong. My goal is " input of 2 lists of data, will have at least one in common."

© Stack Overflow or respective owner

Related posts about mathematics

Related posts about functions