logo

Crowdly

What is the worst-case time complexity of this function? Try to find the ti...

✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.

What is the worst-case time complexity of this function?

  • Try to find the tightest upper bound you can.
  • Try to simplify as much as you can.
  • Even if your answer isn't the tightest upper bound/the most simplified, still write your attempt - there are partial marks.
  • Provide some reasoning for your answer (no explanation, no marks), and don't forget to define the variables you use.

def func(n):

    counter = 0

    i = 1

    while i <= n:

        for j in range(i):

            counter += 1

        i *= 2

    

    return counter

More questions like this

Want instant access to all verified answers on learning.monash.edu?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!