Monday, December 12, 2022

Write down an algorithm for Optimal Storage on Tapes using Greedy Strategy. Explain the algorithm for following problem: Given program lengths L = {12, 34, 56, 73, 24, 11, 34, 56, 78, 91, 34, 91, 45}. Store them on three taps and minimize Mean Retrieval Time.

 One possible algorithm for solving this problem using a greedy strategy is as follows:

  1. Sort the program lengths in descending order. This will ensure that the longest programs are stored on the first tape, where they will have the smallest retrieval time.

  2. Initialize three empty tapes, and a variable total_length to keep track of the total length of programs stored on each tape.

  3. Iterate over the sorted program lengths, and for each length l:

  • If the total length of the first tape is less than the total length of the second and third tapes combined, store the program on the first tape.

  • Otherwise, if the total length of the second tape is less than the total length of the first and third tapes combined, store the program on the second tape.

  • Otherwise, store the program on the third tape.

  1. Return the tapes with the stored programs.

This algorithm will produce an optimal solution because it always stores the longest programs on the first tape, which minimizes the mean retrieval time. Additionally, it uses a greedy approach by always choosing the tape with the smallest total length to store the current program, which ensures that the tapes are filled as evenly as possible.


No comments:

Software scope

 In software engineering, the software scope refers to the boundaries and limitations of a software project. It defines what the software wi...

Popular Posts