1

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
  • 72,336
  • 29
  • 179
  • 389
glion14
  • 11
  • 2
  • 1
    We discourage "please check whether my answer is correct" questions, as only "yes/no" answers are possible, which won't help you or future visitors. See here and here. Can you edit your post to ask about a specific conceptual issue you're uncertain about? As a rule of thumb, a good conceptual question should be useful even to someone who isn't looking at the problem you happen to be working on. If you just need someone to check your work, you might seek out a friend, classmate, or teacher. – David Richerby Dec 03 '16 at 19:26
  • 1
    Why $n=6$? You want somsething asymptotic. – Raphael Dec 03 '16 at 19:39

0 Answers0