Vertical and Horizontal retrieval ( MRT ) on Tapes | Java 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 ; Driver Code ; store the size of records [ ] ; store the size of tapes [ ] ; sorting of an array is required to attain greedy approach of algorithm
import java . util . * ; class GFG { static void vertical_Fill ( int records [ ] , int tape [ ] , int m , int n ) { int [ ] [ ] v = new int [ m ] [ n ] ; int sum = 0 ; int Retrieval_Time = 0 ; double Mrt ; int z = 0 , j = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < m ; j ++ ) { sum = 0 ; for ( int 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 ( int i = 0 ; i < m ; i ++ ) { Retrieval_Time = 0 ; System . out . print ( " tape ▁ " + ( i + 1 ) + " ▁ : ▁ [ ▁ " ) ; for ( j = 0 ; j < n ; j ++ ) { if ( v [ i ] [ j ] != 0 ) { System . out . print ( v [ i ] [ j ] + " ▁ " ) ; } else { break ; } } System . out . print ( " ] " ) ; for ( int k = 0 ; v [ i ] [ k ] != 0 ; k ++ ) { Retrieval_Time += v [ i ] [ k ] * ( j - k ) ; } Mrt = ( double ) Retrieval_Time / j ; System . out . print ( " TABSYMBOL MRT ▁ : ▁ " + Mrt + "NEW_LINE"); } } public static void main ( String [ ] args ) { int records [ ] = { 15 , 2 , 8 , 23 , 45 , 50 , 60 , 120 } ; int tape [ ] = { 25 , 80 , 160 } ; int n = records . length ; int m = tape . length ; Arrays . sort ( records ) ; vertical_Fill ( records , tape , m , n ) ; } }