2

Let f be the function with one argument - positive integer n

function f(n)
  j = 1 
  for i=1 to n:
    j = 2*j
    k = j
    while k > 0:
      k--
      print *

My approach:

  • let n = 6
  • breakdown the for cycle
  • breakdown the while cycle -> when i == 1, we print two *, when i == 2, we print four *, etc.


So I've assumed that it can be $\sum_{i=1}^n 2^i$ what gives me $\Theta(2^n)$.
Am I right or did I something wrong?

Raphael
  • 73,212
  • 30
  • 182
  • 400
glion14
  • 21
  • 2

0 Answers0