Optimal Storage on Tapes | This functions outputs the required order and Minimum Retrieval Time ; Here length of i 'th program is L[i] ; Lengths of programs sorted according to increasing lengths . This is the order in which the programs have to be stored on tape for minimum MRT ; MRT - Minimum Retrieval Time ; driver code
function findOrderMRT ( L , n ) { L . sort ( ) ; document . write ( " " + " " ) ; for ( let i = 0 ; i < n ; i ++ ) document . write ( L [ i ] + " " ) ; document . write ( " " ) ; let MRT = 0 ; for ( let i = 0 ; i < n ; i ++ ) { let sum = 0 ; for ( let j = 0 ; j <= i ; j ++ ) sum += L [ j ] ; MRT += sum ; } MRT /= n ; document . write ( " " + " " + MRT ) ; } let L = [ 2 , 5 , 4 ] ; let n = L . length ; findOrderMRT ( L , n ) ;