ulvis.paste.net

Paste Search Dynamic
Recent pastes
find the common elements
  1. <?php
  2. //program to find the common elements of the two array
  3. //here we have to array A and B from which w have to find the common element
  4. //first we sort then using merge sort and after then for traversing through
  5. //the array in one iteration we can find the comman elements the given array
  6. //this is an inspace algorithm meansno extra space is needed
  7.  
  8. //best case time complexity=O(nlogn)
  9. //O(nlogn)-> for sorting
  10. //O(n)-> for while loop to find comman element
  11.  
  12. //average case time complexity=O(nlogn)
  13. //O(nlogn)-> for sorting
  14. //O(n)-> for while loop to find comman element
  15.  
  16. //worst case time complexity =O(nlogn)
  17. //O(nlogn)-> for sorting
  18. //O(n)-> for while loop to find comman element
  19.  
  20.  
  21.  
  22. $n=100;
  23. $num=1;
  24. if($num<=$n)
  25. {
  26.   echo $num++."<br/>";
  27.   goto end;
  28. }
  29.  
  30. //print_r($commonArray);//to print the output array
  31. ?>
  32.  
  33.  
  34.  
Parsed in 0.007 seconds