

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 7
click for more info
Not enough gems
Cost: 6 gems
1: Polynomial vs. Exponential
incomplete
2: Polynomial Time = P
incomplete
3: Reduction to P
incomplete
4: Order K^N – Exponential
incomplete
5: Big O Categories Review
incomplete
6: Complexity Quiz - Example 1
incomplete
7: Complexity Quiz - Example 2
incomplete
8: Complexity Quiz - Example 3
incomplete
9: Exponential Growth Sequences
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Consider the following function for two questions:
# halvedSections returns a list of lists.
# For example, n=12 results in:
# [
# [0 1 2 3 4 5 6 7 8 9 10 11 12]
# [0 1 2 3 4 5 6]
# [0 1 2 3]
# [0 1]
# ]
def halved_sections(n: int) -> list[list[int]]:
rows = []
i = n
while i > 0:
col = []
for j in range(i + 1):
col.append(j)
rows.append(col)
i //= 2
return rows
It has a specific time complexity of:
T(n) = O(n + n/2 + n/4 + ... 1)
This is a tricky one. You need to take into account the shrinking size of each successive list.