A space–time trade-off, also known as time–memory trade-off or the algorithmic space-time continuum in
computer science
Computer science is the study of computation, information, and automation. Computer science spans Theoretical computer science, theoretical disciplines (such as algorithms, theory of computation, and information theory) to Applied science, ...
is a case where an
algorithm
In mathematics and computer science, an algorithm () is a finite sequence of Rigour#Mathematics, mathematically rigorous instructions, typically used to solve a class of specific Computational problem, problems or to perform a computation. Algo ...
or
program trades increased space usage with decreased time. Here, ''space'' refers to the
data storage
Data storage is the recording (storing) of information (data) in a storage medium. Handwriting, phonographic recording, magnetic tape, and optical discs are all examples of storage media. Biological molecules such as RNA and DNA are con ...
consumed in performing a given task (
RAM,
HDD, etc.), and ''time'' refers to the time consumed in performing a given task (
computation
A computation is any type of arithmetic or non-arithmetic calculation that is well-defined. Common examples of computation are mathematical equation solving and the execution of computer algorithms.
Mechanical or electronic devices (or, hist ...
time or
response time).
The utility of a given space–time tradeoff is affected by related
fixed and
variable costs (of, e.g.,
CPU speed, storage space), and is subject to
diminishing returns.
History
Biological usage of time–memory tradeoffs can be seen in the earlier stages of
animal behavior. Using stored knowledge or encoding stimuli reactions as "instincts" in the DNA avoids the need for "calculation" in time-critical situations. More specific to computers,
look-up tables have been implemented since the very earliest operating systems.
In 1980
Martin Hellman
Martin Edward Hellman (born October 2, 1945) is an American cryptologist and mathematician, best known for his invention of public-key cryptography in cooperation with Whitfield Diffie and Ralph Merkle. Hellman is a longtime contributor to the ...
first proposed using a time–memory tradeoff for
cryptanalysis
Cryptanalysis (from the Greek ''kryptós'', "hidden", and ''analýein'', "to analyze") refers to the process of analyzing information systems in order to understand hidden aspects of the systems. Cryptanalysis is used to breach cryptographic se ...
.
Types of tradeoff
Lookup tables vs. recalculation
A common situation is an algorithm involving a
lookup table
In computer science, a lookup table (LUT) is an array data structure, array that replaces runtime (program lifecycle phase), runtime computation of a mathematical function (mathematics), function with a simpler array indexing operation, in a proc ...
: an implementation can include the entire table, which reduces computing time, but increases the amount of memory needed, or it can compute table entries as needed, increasing computing time, but reducing memory requirements.
Database indexes vs. table scans
Database Management Systems offer the capability to create
Database index
A database index is a data structure that improves the speed of data retrieval operations on a database table at the cost of additional writes and storage space to maintain the index data structure. Indexes are used to quickly locate data withou ...
data structures. Indexes improve the speed of lookup operations at the cost of additional space. Without indexes, time-consuming
Full table scan operations are sometimes required to locate desired data.
Compressed vs. uncompressed data
A space–time trade off can be applied to the problem of data storage. If data is stored uncompressed, it takes more space but access takes less time than if the data were stored compressed (since compressing the data reduces the amount of space it takes, but it takes time to run the
decompression algorithm). Depending on the particular instance of the problem, either way is practical. There are also rare instances where it is possible to directly work with compressed data, such as in the case of compressed
bitmap indices, where it is faster to work with compression than without compression.
Re-rendering vs. stored images
Storing only the
SVG source of a
vector image and rendering it as a
bitmap image every time the page is requested would be trading time for space; more time used, but less space. Rendering the image when the page is changed and storing the rendered images would be trading space for time; more space used, but less time. This technique is more generally known as
caching.
Smaller code vs. loop unrolling
Larger code size can be traded for higher program speed when applying
loop unrolling
Loop unrolling, also known as loop unwinding, is a loop transformation technique that attempts to optimize a program's execution speed at the expense of its binary size, which is an approach known as space–time tradeoff. The transformation c ...
. This technique makes the code longer for each iteration of a loop, but saves the computation time required for jumping back to the beginning of the loop at the end of each iteration.
Other examples
Algorithms that also make use of space–time tradeoffs include:
*
Baby-step giant-step algorithm for calculating
discrete logarithm
In mathematics, for given real numbers a and b, the logarithm \log_b(a) is a number x such that b^x=a. Analogously, in any group G, powers b^k can be defined for all integers k, and the discrete logarithm \log_b(a) is an integer k such that b^k=a ...
s
*
Rainbow tables in cryptography, where the adversary is trying to do better than the exponential time required for a
brute-force attack. Rainbow tables use partially precomputed values in the hash space of a
cryptographic hash function
A cryptographic hash function (CHF) is a hash algorithm (a map (mathematics), map of an arbitrary binary string to a binary string with a fixed size of n bits) that has special properties desirable for a cryptography, cryptographic application: ...
to crack passwords in minutes instead of weeks. Decreasing the size of the rainbow table increases the time required to iterate over the hash space.
* The
meet-in-the-middle attack uses a space–time tradeoff to find the
cryptographic key
A key in cryptography is a piece of information, usually a string of numbers or letters that are stored in a file, which, when processed through a cryptographic algorithm
In mathematics and computer science, an algorithm () is a finite sequenc ...
in only
encryptions (and
space) versus the expected
encryptions (but only
space) of the naive attack.
*
Dynamic programming, where the time complexity of a problem can be reduced significantly by using more memory.
*
Time/memory/data tradeoff attack which uses the space–time tradeoff with the additional parameter of data.
See also
*
*
*
*
*
References
External links
Philippe Oechslin: Making a Faster Cryptanalytic Time-Memory Trade-Off.Once Upon a Time-Memory Tradeoff.
{{DEFAULTSORT:Space-time tradeoff
Software optimization