Lably
Skip to content

Algorithmic efficiency

Property of an algorithm

  • 13 min read
  • 3 chapters

Related on Lably

Through Computer science, Algorithm and Productivity

For maximum efficiency it is desirable to minimize resource usage. However, different resources such as time and space complexity cannot be compared directly, so which of two algorithms is considered to be more efficient often depends on which measure of efficiency is considered most important.

For example, cycle sort and Timsort are both algorithms to sort a list of items from smallest to largest. Cycle sort organizes the list in time proportional to the number of elements squared (O(n2), see big O notation), but minimizes the writes to the original array and only requires a small amount of extra memory which is constant with respect to the length of the list (O(1)). Timsort sorts the list in time linearithmic (proportional to a quantity times its logarithm) in the list's length (O(nlog⁡n)), but has a space requirement linear in the length of the list (O(n)). If large lists must be sorted at high speed for a given application, timsort is a better choice; however, if minimizing the program/erase cycles and memory footprint of the sorting is more important, cycle sort is a better choice.

Background

The importance of efficiency with respect to time was emphasized by Ada Lovelace in 1843 as applied to Charles Babbage's mechanical analytical engine:

"In almost every computation a great variety of arrangements for the succession of the processes is possible, and various considerations must influence the selections amongst them for the purposes of a calculating engine. One essential object is to choose that arrangement which shall tend to reduce to a minimum the time necessary for completing the calculation"

Early electronic computers had both limited speed and limited random-access memory. Therefore, a space–time trade-off occurred. A task could use a fast algorithm using a lot of memory, or it could use a slow algorithm using little memory. The engineering trade-off was therefore to use the fastest algorithm that could fit in the available memory.

Modern computers are significantly faster than early computers and have a much larger amount of memory available (gigabytes instead of kilobytes). Nevertheless, Donald Knuth emphasized that efficiency is still an important consideration:

"In established engineering disciplines a 12% improvement, easily obtained, is never considered marginal and I believe the same viewpoint should prevail in software engineering"

In the era of AI, while LLMs can generate code that works, these often fall short of the performance standards required in resource-constrained or time-sensitive applications, making code efficiency a critical bottleneck for real-world deployment.

Sign in to keep reading

2 more chapters are free with a Lably account.

More in Computing and communication