Files
max015/T11/ans/main.md
2025-02-01 02:04:08 +08:00

965 B

P01:

a. true b. true c. true d. false e. false

P02:

growth rates: 1 slowest, 6 fastest

alt text

P03:

alt text + alt text

=> alt text

P04:

alt text

P05:

def myFunction(n):
  for i in range(n):              # O(n)
    for j in range(i, i * i):     # O(i^2 - i)  => O(n^2 - n) => O(n^2)
      if j % i == 0:              # O(1)              # Check if j is divisible by i
        for k in range(j):        # O(n!)
          print("*", end="")        # Print '*' to the console without newline
    print()

# Example usage
myFunction(5)

steps behind analysis

n = 5 => 5+10+15+20 => 5(1+2+3+4) ~ 5! # actual 5! - 5 n = 4 => 4+8+16 => 4(1+2+3) ~ 4! # actual 4! - 4 n = 3 => 3 => 3(1) ~ 3! # actual 3! - 3

so worse case scenario is O(n + n^2 + 1 + n!)

=> O(n!)