MERGE SORT () :
A is a sorted array with M elements and B is a sorted array with N elements. C is an empty array with size S , S >= M+N
Step I : [ Initialize Counter ] Set I = J = K = 1
Step II : Repeat Step III to IX While ( I <= M ) and ( J <= N)
Step III : If ( A[I] < B[J]) ThenÂ
Step IV : [ Assign elements of array A to C ] Â Set C[K] = A[I]
Step V : Set I = I +1
Step VI :Else
Step VII : [ Assign elements of array B to C ] Set C[K] = B[J]Â
Step VIII : Set J =J + 1
 [ End of If ]
Step IX : Â Set K = K + 1
[ End of while loop ]
Step X : [ A is Empty ] If (I > M) ThenÂ
Step XI : Repeat Step XII and XIII While ( J <= N )
Step XII : Â [ Assign remaining elements of array B to C ] Set C[K] =B[J]
Step XIII : Set J = J + 1 and K = k + 1
         [ End of while loop ]
     [ End of If ] Â
Step XIV : [B is empty ] If ( J > N ) ThenÂ
Step XV : Repeat Step XVI and XVII While ( I <= M )
Step XVI :Â Â [ Assign remaining elements of array A to C ] Set C[K] =A[I]
Step XVII : Set I = I + 1 and K = K + 1
 [End of While loop ]
      [End of If ]
Step XVIII : Exit
Explained Using Figure:
You must be logged in to post a comment.