How to determine the best case and worst case of an program(algorithm)?

Posted by college_stud on Stack Overflow See other posts from Stack Overflow or by college_stud
Published on 2010-04-19T13:20:22Z Indexed on 2010/04/19 13:23 UTC
Read the original article Hit count: 211

Suppose I have this program, I want to compare 2 input lists. Assume array A and array B. How do I determine the best case and worst case of the function?

Here is my code in [php]:

foreach($array_1 as $k){
    if(!in_array($k, $array_2)){
        array_push($array_2, $k);
    }
}   

What is the best case and worst case of the for loop? Please include some explaination, thank you :)

© Stack Overflow or respective owner

Related posts about worst-case

Related posts about function