chap file processing and external sorting input runs output buffer figure illustration of multiway merge the first value in each input run is examined and the smallest sent to the output this value is removed from the input and the process repeated in this examplevalues and are compared first value is removed from the first run and sent to the output values and will be compared next after the first five values have been outputthe "currentvalue of each block is the one underlined the initial runs should each contain many records)we would like to reduce still further the number of passes required to merge the runs together note that twoway merging does not make good use of available memory because merging is sequential process on the two runsonly one block of records per run need be in memory at time keeping more than one block of run in memory at any time will not reduce the disk / required by the merge process thusmost of the space just used by the heap for replacement selection (typically many blocks in lengthis not being used by the merge process we can make better use of this space and at the same time greatly reduce the number of passes needed to merge the runs if we merge several runs at time multiway merging is similar to two-way merging if we have runs to mergewith block from each run available in memorythen the -way merge algorithm simply looks at values (the front-most value for each input runand selects the smallest one to output this value is removed from its runand the process is repeated when the current block for any run is exhaustedthe next block from that run is read from disk figure illustrates multiway merge conceptuallymultiway merge assumes that each run is stored in separate file howeverthis is not necessary in practice we only need to know the position of each run within single fileand use seek to move to the appropriate block whenever we need new data from particular run naturallythis approach destroys the ability to do sequential processing on the input file howeverif all runs were stored on single disk drivethen processing would not be truly sequential anyway because the / head would be alternating between the runs thusmultiway merging