0
0
Data Structures Theoryknowledge~10 mins

Time complexity (Big O notation) in Data Structures Theory - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to represent the time complexity of a loop that runs n times.

Data Structures Theory
for i in range([1]):
    print(i)
Drag options to blanks, or click blank then click option'
A1
Blog n
Cn**2
Dn
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing 1, which means constant time, but the loop depends on n.
Choosing n**2, which is for nested loops, not a single loop.
2fill in blank
medium

Complete the code to represent the time complexity of a nested loop where both loops run n times.

Data Structures Theory
for i in range(n):
    for j in range([1]):
        print(i, j)
Drag options to blanks, or click blank then click option'
A1
Blog n
Cn
Dn**2
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing 1, which ignores the inner loop.
Choosing log n, which is unrelated to nested loops.
3fill in blank
hard

Fix the error in the time complexity expression for a binary search algorithm.

Data Structures Theory
The time complexity of binary search is O([1])
Drag options to blanks, or click blank then click option'
Alog n
Bn log n
Cn**2
Dn
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing n, which is linear time and too slow for binary search.
Choosing n log n, which is typical for sorting algorithms, not binary search.
4fill in blank
hard

Fill the blank to complete the time complexity expression for a function with a loop running n times and a nested loop running log n times.

Data Structures Theory
The time complexity is O(n [1] log n)
Drag options to blanks, or click blank then click option'
A+
B*
C-
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using plus instead of multiplication, which changes the meaning.
Using division or subtraction, which are not standard in Big O notation.
5fill in blank
hard

Fill all three blanks to complete the time complexity expression for a function with a constant time operation, a linear loop, and a quadratic nested loop.

Data Structures Theory
Total time complexity: O([1] + [2] + [3])
Drag options to blanks, or click blank then click option'
A1
B+
Cn
Dn**2
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the constant term or using multiplication instead of addition.
Confusing n and n squared terms.