Find the order of execution of given N processes in Round Robin Scheduling | Function to sort the array order [ ] on the basis of the array freq [ ] ; If order [ i ] th is less than order [ temp ] th process ; Otherwise ; Add the left half to tempOrder [ ] ; Add right half to tempOrder [ ] ; Copy the tempOrder [ ] array to order [ ] array ; Utility function to sort the array order [ ] on the basis of freq [ ] ; Base Case ; Divide array into 2 parts ; Sort the left array ; Sort the right array ; Merge the sorted arrays ; Function to find the order of processes in which execution occurs ; Store the frequency ; Find elements in array freq [ ] ; Store the order of completion of processes ; Initialize order [ i ] as i ; Function Call to find the order of execution ; Print order of completion of processes ; Burst Time of the processes ; Quantum Time ; Function Call
function merge ( order , freq , i , mid , j ) { var tempOrder = Array ( j - i + 1 ) ; var temp = mid + 1 , index = - 1 ; while ( i <= mid && temp <= j ) { if ( freq [ order [ i ] ] <= freq [ order [ temp ] ] ) { tempOrder [ ++ index ] = order [ i ++ ] ; } else { tempOrder [ ++ index ] = order [ temp ++ ] ; } } while ( i <= mid ) { tempOrder [ ++ index ] = order [ i ++ ] ; } while ( temp <= j ) { tempOrder [ ++ index ] = order [ temp ++ ] ; } for ( index ; index >= 0 ; index -- ) { order [ j -- ] = tempOrder [ index ] ; } } function divide ( order , freq , i , j ) { if ( i >= j ) return ; var mid = parseInt ( i / 2 ) + parseInt ( j / 2 ) ; divide ( order , freq , i , mid ) ; divide ( order , freq , mid + 1 , j ) ; merge ( order , freq , i , mid , j ) ; } function orderProcesses ( A , N , q ) { var i = 0 ; var freq = Array ( N ) ; for ( i = 0 ; i < N ; i ++ ) { freq [ i ] = ( A [ i ] / q ) + ( A [ i ] % q > 0 ) ; } var order = Array ( 4 ) ; for ( i = 0 ; i < N ; i ++ ) { order [ i ] = i ; } divide ( order , freq , 0 , N - 1 ) ; for ( i = 0 ; i < N ; i ++ ) { document . write ( order [ i ] + " " ) ; } } var arr = [ 3 , 7 , 4 ] ; var Q = 3 ; var N = arr . length ; orderProcesses ( arr , N , Q ) ;