What is the great complexity of this recursive algorithm?

I follow the course of algorithms and data structures.

Today my professor said that the complexity of the following algorithm is 2 n .

I waited until the lesson was over, went up to him and told him that I really believed that it was an algorithm O(n), and I did the calculations to prove it, and wanted to show them that, but he kept talking about it, not letting me no convincing explanation.

The algorithm is recursive and has such complexity:

       { 1         if n=1
T(n) = {
       { 2T(n/2)   otherwise

I calculated it like O(n)this:

Let it expand T(n)

T(n) = 2 [2 * T(n/(2^2))]
     = 2^2 * T(n/(2^2))
     = 2^2 * [2 * T(n/(2^3))]
     = 2^3 * T(n/(2^3))
     = ...
     = 2^i * T(n/(2^i)).

We stop when the term inside T is 1, that is:

n / (2 i ) = 1 ==> n = 2 i ==> i = log n

After substitution we get

T(n) = 2^log n * T(1)
     = n * 1
     = O(n).

Merge Sort, , Merge Sort, , , O(n log n), 2T (n/2) + Θ (n) (, , 2T (n/2)), , , , -O. . : " , , ".

:

  • - ?
  • - ?

, .

+4
3

- 1

- 3 -,

  • a = 2;
  • b = 2; ,
  • c = -∞

, , Log b a = 1, , -∞. Θ (n 1) = Θ (n).


- 2

, n 2 n/2, 0 (.. ).

, n 1, n * O (1), ().


:. , , .

- ?

. .

?

. . 2.

+3

, , , T(n), O(n). , , , . , . , 1000 500 .

, , , . , . , n , . , n O(sqrt(n)), , O(n). , , , , RSA , , , 256- , n 2^256.

+2

. n ( ), , , 2^n.

You should probably discuss this with him and resolve any misunderstanding you may have.

+2
source

Source: https://habr.com/ru/post/1611848/


All Articles