Mergesort, quicksort are probably the most famous nlogn sorting algorithms. Their explanation and C ++ code examples in most cases contain recursion. But as far as I understand about recursion, when there will be a large amount of data, we face a big risk. So is it wise to ignore the recursive explanation about sorting algorithms per se that cannot be used in real life?
But as far as I understand about recursion, when there will be a large amount of data, we face a big risk.
It depends on a few things:
O(2^N)
Log2(N)
, ?
, : , . , , , , , , - , .
O(n log n) , , O(log n) ( )
O(n log n)
O(log n)
quicksort , , . O(n^2) O(n).
O(n^2)
O(n)
( : DFS, , BFS - " " , )
O(n logn) log2(n).
O(n logn)
log2(n)
, log2(1,000,000,000) = 30, .
log2(1,000,000,000) = 30
, , , O(n). , .
, , (n).
"" - , , , . ,
int factorial (int k) {if (k == 1) return 1 else return k * factorial (k-1);}
n = 21, 20 , 20 - . , while ( ) . , ( ) .