0

This function runs a number series known as the Collatz conjecture. What is its time/space complexity?

def run(n):
    i = 0
    while n > 1:
        if n % 2 == 0:
            n /= 2
        else:
            n = n * 3 + 1
        i += 1
    return i
Ben Alan
  • 1,399
  • 1
  • 11
  • 27
  • Cross-site dupe: https://cs.stackexchange.com/questions/54266/how-long-does-the-collatz-recursion-run – SuperStormer Feb 28 '21 at 00:48
  • 3
    Considering it is only a *conjecture* that it *will* reach n <= 1, we don't know the time complexity. That's what conjecture means. The space complexity is simply the space needed for the values of `n` and `i`. – Mark Feb 28 '21 at 00:50

0 Answers0