Time Space Trade-Off of Algorithms

In this tutorial, we are going to study about what is time space trade-off? What is need of time space trade-off? How to calculate time space trade-off? How time space trade-off helps to calculate the efficiency of algorithm? By Amit Shukla Last updated : August 12, 2023

Time Space Trade-Off of Algorithms

The best algorithm, hence best program to solve a given problem is one that requires less space in memory and takes less time to execute its instruction or to generate output. But in practice, it is not always possible to achieve both of these objectives. As said earlier, there may be more than one approaches to solve a same problem. One such approach may require more space but takes less time to complete its execution. Thus we may have to sacrifice one at the cost of the other. That is what we can say that there exists a time space trade off among algorithms.

Therefore, if space is our constraints then we have to choose a program that requires less space at the cost of more execution time. Other than that, if time is our constraint, then we have to choose a program that takes less time to complete its execution of statements at the cost of more space.

In the analysis of algorithms, we are interested in the average case, the amount of time a program might be expected to take on typical input data and in the worst case the total time required by the program or the algorithm would take on the worst possible inputs of that algorithm.

Types of Trade-Off of Algorithms

The following are the different types of trade-off of Algorithms

  1. Lookup tables Vs Recalculation
    An algorithm involving a lookup table is 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.
  2. Compressed Vs Un compressed data
    Problem of data storage can also be handling by using space and time tradeoff of algorithms. If data is stored is not compressed, 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). It is depending upon 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.
  3. Re Rendering Vs Stored images
    In this case 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.
  4. Smaller code Vs loop unrolling
    This technique is commonly used to makes the code longer for each iteration of a loop, but it saves the computation time required for jumping back to the beginning of the loop at the end of each iteration.Larger code size can be traded for higher program speed when applying loop unrolling.


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.