different riders obviouslyfile numbers are used to index the array of files let us then assume that the initial file is the parameter srcand that for the sorting process files are availablefgarray of files filerwarray of runs rider the algorithm can now be sketched as followsprocedure balancedmerge (srcfiles file)files filevar ijintegerlinteger(*no of runs distributed*rruns riderbegin runs set(rsrc)(*distribute initial runs from to [ [ - ]* : : position riders on files grepeat copy one run from to [ ]inc( )inc( )if then : end until eofrepeat (*merge from riders to riders *switch files to riders rl : : (* index of output file*repeat inc( )merge one run from inputs to [ ]if then inc(jelse : end until all inputs exhausteduntil (*sorted file is with [ ]*end balancedmerge having associated rider with the source filewe now refine the statement for the initial distribution of runs using the definition of copywe replace copy one run from to [jbyrepeat runs copy(rw[ ]until eor copying run terminates when either the first item of the next run is encountered or when the end of the entire input file is reached in the actual sort algorithmthe following statements remain to be specified in more detail( position riders on files ( merge one run from inputs to [ ( switch files to riders ( all inputs exhausted firstwe must accurately identify the current input sequences notablythe number of active inputs may be less than obviouslythere can be at most as many sources as there are runsthe sort terminates as soon as there is one single sequence left this leaves open the possibility that at the initiation of the last sort pass there are fewer than runs we therefore introduce variablesay to denote the actual number of inputs used we incorporate the initialization of in the statement switch files as follows