Efficiency of Algorithms Flashcards
All 4 cards in this deck
True or false? Each problem can only be solved by one algorithm.
False. More than one algorithm can be used to solve the same problem, e.g. a linear search and a binary search can both find an item in a sorted list.
What makes one algorithm more time-efficient than another algorithm that solves the same problem?
It completes the task in less time, because it carries out fewer steps (e.g. fewer comparisons, calculations or loop repetitions) for the same input.
Why is a single calculation usually more time-efficient than a loop that produces the same result?
The calculation takes the same number of steps whatever the input, but the number of steps the loop carries out grows as the input gets bigger.
Why does "it has fewer lines of code" not show that an algorithm is more time-efficient?
The time taken depends on how many steps are executed when it runs, not how many lines are written: a few lines inside a loop may be executed thousands of times.