P2-2 Exercise: Time Complexity Identification Practice

Problem 1

Rank the speed of the following time complexities, from fastest to slowest.

O(n^2)
,
O(1)
,
O(log n)
,
O(n)
,
O(2^n)
,
O(n^3)

Problem 2

What is the time complexity of the following code?

A. Calculating the sum between 1 to n

B.

C.

D.

E.

F.

G.