.


:




:

































 

 

 

 


- (n log n).




. (, , : , l r , 2.6 . -):

, . . , . : , , ; .

: , , , , . :

l r, , .

m.

l , l- .

r , r- .

r = l , .

l < r l r, . , - (l r) , m r- l- , .

, .

, . , , , . .

( ) , , , .

public static void qSort(int [] A, int low, int high) {

int i = low;

int j = high;

int x = A[(low+high)/2]; // x - low high

do {

while (A[i] < x) ++i; //

while (A[j] > x) --j; //

if (i <= j){

// :

int temp = A[i];

A[i] = A[j];

A[j] = temp;

// :

i++; j--;

}

} while (i < j);

if (low < j) qSort(A, low, j);

if (i < high) qSort(A, i, high);

}

. . , , CN = 2CN/2+N, N lg N . .

. O(n log n) n . .
( , , ) , O(n lg n), , . 2CN/2 ; N , . , CN = N lg N.

. , , , . , , .
O(n ²) . , , . , n, n- . n . , , , .





:


: 2016-11-18; !; : 803 |


:

:

.
==> ...

1517 - | 1343 -


© 2015-2024 lektsii.org - -

: 0.009 .