Skip to main content

Complexity Quiz: Hard

Editorial

Complexity Quiz: Hard

Fifteen pieces of code: searches through subsets and orderings, remembered answers, divide and conquer past the easy cases, amortized costs, and a loop that runs log log n times. 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: Hard

1 / 15

Multiple choice

What is the time complexity of this fib?
long long fib(int n) {
    if (n <= 1) return n;
    return fib(n - 1) + fib(n - 2);
}