Vertical and Horizontal retrieval ( MRT ) on Tapes | Javascript program to print Vertical filling ; 2D matrix for vertical insertion on tapes ; It is used for checking whether tape is full or not ; It is used for calculating total retrieval time ; It is used for calculating mean retrieval time ; It is used for calculating mean retrieval time ; vertical insertion on tape ; initialize variables to 0 for each iteration ; Used for getting ' sum ' sizes of records in tape to determine whether tape is full or not ; if tape is not full ; check for ability of tapes to hold value ; initialize variables to 0 for each iteration ; display elements of tape ; calculating total retrieval time ; MRT formula ; calculating mean retrieval time using formula ; v . size ( ) is function of vector is used to get size of vector ; store the size of records [ ] ; store the size of tapes [ ] ; sorting of an array is required to attain greedy approach of algorithm
function vertical_Fill ( records , tape , m , n ) { let v = new Array ( m ) ; for ( let i = 0 ; i < m ; i ++ ) { v [ i ] = new Array ( n ) ; for ( let j = 0 ; j < n ; j ++ ) { v [ i ] [ j ] = 0 ; } } let sum = 0 ; let Retrieval_Time = 0 ; let Mrt ; let z = 0 , j = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < m ; j ++ ) { sum = 0 ; for ( let k = 0 ; k < i ; k ++ ) { sum += v [ j ] [ k ] ; } if ( sum + records [ z ] <= tape [ j ] ) { v [ j ] [ i ] = records [ z ] ; z ++ ; } } if ( v [ 2 ] [ i ] == 0 ) { break ; } } for ( let i = 0 ; i < m ; i ++ ) { Retrieval_Time = 0 ; document . write ( " " + ( i + 1 ) + " " ) ; for ( j = 0 ; j < n ; j ++ ) { if ( v [ i ] [ j ] != 0 ) { document . write ( v [ i ] [ j ] + " " ) ; } else { break ; } } document . write ( " " ) ; for ( let k = 0 ; v [ i ] [ k ] != 0 ; k ++ ) { Retrieval_Time += v [ i ] [ k ] * ( j - k ) ; } Mrt = Retrieval_Time / j ; if ( i != m - 1 ) { document . write ( " " + Mrt + " " ) ; } else { document . write ( " " + Mrt . toFixed ( 4 ) + " " ) ; } } } let records = [ 15 , 2 , 8 , 23 , 45 , 50 , 60 , 120 ] ; let tape = [ 25 , 80 , 160 ] ; let n = records . length ; let m = tape . length ; records . sort ( function ( a , b ) { return a - b } ) ; vertical_Fill ( records , tape , m , n ) ;