295 11/17/2016 7:32:44 AM


:

Sequence <A1', A2', ...An'> of numbers

:

Permutation of numbers <A1',A2',...An'>

:
for (int i = 0; i < data.Length; i++)
   for (int j = 0; j < data.Length - 1; j++)
      if (data[j] > data[j + 1])
      {
         tmp = data[j];
         data[j] = data[j + 1];
         data[j + 1] = tmp;
      }
:
  • Swipe first two elements if the 1st element is greater
  • Swipe 2nd and 3rd element if 2nd element is greater
  • Repeat same until array is sorted
:

Space: O(1)

:

O(n2)