**The Procedure**

**Real Lab Procedure **

- Define a function merge that takes four arguments "arr", "l", "m", "r":
- Compute the length of the two subarrays: "n1 = m - l + 1" and "n2 = r - m".
- Create two empty arrays "L" and "R" of length "n1" and "n2", respectively.
- Copy the left and right subarrays from "arr" into "L" and "R".
- Initialize variables "i", "j", and "k" to 0 and "l".
- Compare the first element of "L" and "R", and copy the smaller element to "arr[k]".
- Increment "i" or "j" depending on which element is copied.
- Increment "k".
- Repeat steps 5-7 until one of the subarrays is completely copied to "arr".
- Copy any remaining elements of the left or right subarray to "arr" if necessary.

- Define a function mergeSort that takes three arguments "arr", "l", and "r":
- If "l" is less than "r":
- Compute the middle index "m".
- Recursively call "mergeSort" on the left half of the array "arr[l:m]".
- Recursively call "mergeSort" on the right half of the array "arr[m+1:r]".
- Call merge function to merge the two sorted subarrays.

- Call the "mergeSort" function with arguments "arr", "0", and "n-1".
- Output the sorted array "arr".

**Simulator Procedure**

- Select the variables from the dropdown list.
- Click on the Finish button or Start button to view the state diagram.
- If you have clicked on the Start button then use Next and Previous button to view the State diagram.
- Click on the Reset button when the State diagram is completed.