Is recursion in sorting algorithms always bad?

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?

+5
source share
4 answers

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). 40 , - , .

, ?

, : , . , , , , , , - , .

+10

O(n log n) , , O(log n) ( )

quicksort , , . O(n^2) O(n).

( : DFS, , BFS - " " , )

+7

O(n logn) log2(n).

, log2(1,000,000,000) = 30, .

, , , O(n). , .

+3

, , (n).

"" - , , , . ,

int factorial (int k) {if (k == 1) return 1 else return k * factorial (k-1);}

n = 21, 20 , 20 - . , while ( ) . , ( ) .

0

All Articles