Algorithm efficiency: reasonable vs unreasonable time & heuristics

Computer Science · Algorithms

Question 1 of 10

0

    On a graph of running time against input size, a straight line that rises at a steady rate from the origin shows which growth rate?

    Stuck? Read the explanation

    Unlocks at a streak of 5 correct answers in a row.

    Print a free worksheet (PDF)

    Embed this practice on your site or class page

    Paste this HTML into your page. Students practise right there; it is free and needs no account.

    Algorithm efficiency: reasonable vs unreasonable time & heuristics explained

    Algorithm efficiency describes how the number of steps an algorithm needs grows as the size of its input grows. Computer scientists describe this growth with Big O notation, which ignores constant factors and focuses on the dominant term. A problem is said to be solvable in reasonable time if an algorithm for it runs in polynomial time, meaning the step count grows like n raised to a fixed power, such as n squared. These algorithms stay practical for large inputs, because doubling the input only increases the work by a fixed factor.

    Some algorithms are unreasonable. Exponential time algorithms, whose step count doubles with each extra input item, become impossible for quite small inputs. Brute force methods that try every possible arrangement are a common example. For problems of this kind, a heuristic is used instead. A heuristic is a practical rule of thumb, such as always choosing the nearest unvisited city, that finds a good answer quickly without guaranteeing the best one.

    Worked example

    A brute force search checks every subset of n items, which means about 2 to the power n checks. Suppose a computer performs one billion checks per second.

    • For n = 20, the number of checks is 220=1 048 5762^{20} = 1\,048\,576, which takes about 0.001 seconds.
    • For n = 60, the number of checks is 260≈1.15×10182^{60} \approx 1.15 \times 10^{18}, which takes about 1.15×1091.15 \times 10^{9} seconds, or roughly 36.5 years.

    Increasing the input from 20 to 60 items makes the work about a trillion times larger, which is why brute force is unreasonable here.

    What you will practise

    84 multiple-choice questions (Easy, Medium, Hard). Each answer is followed by an explanation.

    Example questions

    • Which description best matches an algorithm that runs in reasonable time?
    • What is a heuristic?
    • Which growth rate is generally regarded as unreasonable for large inputs?
    • What does a brute-force algorithm do?
    • Binary search on a sorted list of n items needs roughly how many comparisons in the worst case?
    • Which situation is most suited to using a heuristic?
    • Which statement about polynomial-time algorithms is correct?
    • What does it mean to call a problem intractable?

    …and 76 more.