0
0
Data Structures Theoryknowledge~20 mins

Time complexity (Big O notation) in Data Structures Theory - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
πŸŽ–οΈ
Big O Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Big O for Nested Loops

Consider a function that has two nested loops, each running from 1 to n. What is the time complexity of this function in Big O notation?

Data Structures Theory
for i in range(n):
    for j in range(n):
        do_something()
AO(n^2)
BO(log n)
CO(n)
DO(n log n)
Attempts:
2 left
πŸ’‘ Hint

Think about how many times the inner loop runs in total compared to the outer loop.

πŸ“‹ Factual
intermediate
2:00remaining
Time Complexity of Binary Search

What is the time complexity of the binary search algorithm on a sorted list of size n?

Data Structures Theory
def binary_search(arr, target):
    low, high = 0, len(arr) - 1
    while low <= high:
        mid = (low + high) // 2
        if arr[mid] == target:
            return mid
        elif arr[mid] < target:
            low = mid + 1
        else:
            high = mid - 1
    return -1
AO(n)
BO(log n)
CO(n log n)
DO(1)
Attempts:
2 left
πŸ’‘ Hint

Each step halves the search space.

πŸ” Analysis
advanced
2:00remaining
Analyzing Time Complexity of a Recursive Function

Given the recursive function below, what is its time complexity in Big O notation?

Data Structures Theory
def recursive_function(n):
    if n <= 1:
        return 1
    return recursive_function(n-1) + recursive_function(n-1)
AO(n^2)
BO(n)
CO(2^n)
DO(log n)
Attempts:
2 left
πŸ’‘ Hint

Consider how many calls are made at each level of recursion.

❓ Comparison
advanced
2:00remaining
Comparing Time Complexities of Sorting Algorithms

Which of the following sorting algorithms has the best average-case time complexity?

ABubble Sort - O(n^2)
BSelection Sort - O(n^2)
CInsertion Sort - O(n^2)
DMerge Sort - O(n log n)
Attempts:
2 left
πŸ’‘ Hint

Consider which algorithm uses divide and conquer.

❓ Reasoning
expert
2:00remaining
Determining Time Complexity from Code Output

What is the time complexity of the following code snippet?

Data Structures Theory
def mystery_function(n):
    i = 1
    count = 0
    while i < n:
        j = 0
        while j < i:
            count += 1
            j += 1
        i *= 2
    return count
AO(n)
BO(n log n)
CO(log n)
DO(n^2)
Attempts:
2 left
πŸ’‘ Hint

Analyze how many times the inner loop runs as i grows exponentially.