Skip to main content

Complexity Quiz: Easy

Editorial

Complexity Quiz: Easy

Fifteen pieces of code: single loops, nested loops, halving and doubling, two inputs, memory and a library sort. For each, pick its growth. Every answer was checked by running the code on our judge in C++, Python, Java and JavaScript at three sizes of n, 1,000, 2,000 and 4,000 unless the answer names others: the four counted the same steps, and the growth in the answer fitted those counts best. Where the cost hides inside a library call, every language's times were checked instead.

Complexity Quiz: Easy

1 / 15

Multiple choice

What is the time complexity of this loop?
long long count = 0;
for (int i = 0; i < n; i++)
    count++;