0
0
Data Structures Theoryknowledge~20 mins

Common complexity classes (O(1), O(n), O(log n), O(n²)) in Data Structures Theory - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Complexity Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding constant time complexity O(1)

Which of the following operations typically runs in constant time, O(1)?

AAccessing an element by index in an array
BSearching for an element in an unsorted list
CSorting a list of numbers
DTraversing all elements in a linked list
Attempts:
2 left
💡 Hint

Think about operations that take the same amount of time regardless of input size.

📋 Factual
intermediate
2:00remaining
Identifying linear time complexity O(n)

Which scenario best represents an algorithm with linear time complexity O(n)?

AAccessing the last element of a fixed-size array
BChecking if a number is even or odd
CCalculating the sum of the first 100 numbers
DFinding a specific value by scanning each element in a list
Attempts:
2 left
💡 Hint

Consider how the time grows as the input size increases.

🔍 Analysis
advanced
2:00remaining
Comparing logarithmic time complexity O(log n)

Which of the following algorithms typically runs in logarithmic time O(log n)?

ABinary search on a sorted array
BLinear search on an unsorted array
CCalculating the factorial of a number
DBubble sort on a list
Attempts:
2 left
💡 Hint

Think about algorithms that repeatedly divide the problem size in half.

🚀 Application
advanced
2:00remaining
Recognizing quadratic time complexity O(n²)

Which example best illustrates an algorithm with quadratic time complexity O(n²)?

AA single loop that runs n times
BA recursive function that halves the input each call
CNested loops where each loop runs n times
DAccessing elements in a hash table
Attempts:
2 left
💡 Hint

Consider how many times the inner operations run as input size grows.

Reasoning
expert
2:00remaining
Determining time complexity from code snippet

What is the time complexity of the following code snippet?

def example_function(arr):
    for i in range(len(arr)):
        j = len(arr)
        while j > 0:
            j //= 2
            print(arr[i])
AO(log n)
BO(n log n)
CO(n)
DO(n²)
Attempts:
2 left
💡 Hint

Analyze how many times the inner while loop runs for each iteration of the outer for loop.