, ,

, , , .

Eg. int a[] = { 10, 12, 14, 16, 15, 13, 11}.

      

?

.

+3




3


:

  • 2 .

  • min ( max, ) , 1 ( +1 -1

  • .

O (N). - O (N)

:

function Sort(a)
{
  startPointer = 0;
  endPointer = a.length-1;
  result = new Array of size a.length
  while (startPointer <= endPointer)
  {
    var newValue;
    if (a[startPointer] < a[endPointer])
    {
      newValue = a[startPointer];
      startPointer +1
    }
    else
    {
      newValue = a[endPointer];
      endPointer -1
    }
    result[a.length - startPointer - endPointer] = newValue;
  }

  return result;
}

      

:

usde partil .



(10 11) {10, 12, 14, 16, 15, 13, 11}

(12 11) 12 11 {10, 11, 14, 16, 15, 13, 12}

(14 12) 14 12 {10, 11, 12, 16, 15, 13, 14}// 14 13, .

{10, 11, 12} {16, 15, 13, 14} (N twicely)

: O (N) + (N/2) + O (N/4) +... O (N)

:

enter image description here

+5




, . - . .

:

a[] = { 10, 12, 14, 16, 15, 13, 11}

= > {10,12,14,16}, {15,13,11}

= > reverse (linear, in-place) = >



{16,14,12,10}, {15,13,11}

= > merge (, ) = >

{16,15,14,13,12,11,10}

EDIT: , ,

+7




.

, . , slope

, algorithm

, .

bitonic sorter, .

+2









All Articles