0

I have an array of 5 elements. On that i want to apply bubble sort with min complexity

Currently what i am doing is

function bubbleSort(array $arr)
{
    $n = sizeof($arr);
    for ($i = 1; $i < $n; $i++) {
        for ($j = $n - 1; $j >= $i; $j--) { 
       //some fuzzy logic here
        }
      }
}

Any help ?

Devon Bessemer
  • 34,461
  • 9
  • 69
  • 95
  • 1
    https://stackoverflow.com/questions/9001294/bubble-sort-implementation-in-php – Gilly Aug 22 '18 at 14:06
  • 2
    Possible duplicate of [Bubble Sort in PHP and Python](https://stackoverflow.com/questions/39790316/bubble-sort-in-php-and-python) – dipmala Aug 22 '18 at 14:06
  • 1
    If you MUST use bubble sort (which is o(n^2)) but still improve complexity you can follow the idea in https://stackoverflow.com/questions/51614342/bubble-sort-adaptive-java/51614865#51614865 – dWinder Aug 22 '18 at 14:08

0 Answers0