Shuffle (Sorted)

Objective

The objective of this experiment is to discover the properties of "result" array when "merging”, two sorted arrays to make a larger array.

Experiment Setup

You are provided with two sorted arrays "left" and "right" and your goal is to merge these two arrays to form the merged "result" array using the "Left" and "Right" buttons provided.

The "Left" button picks the first element from the "left" array and places it at the end of the "result" array. Similarly, the "Right" button picks the first element from the "right" array and places it at the end of the "result" array.

At any point during the experiment, the arrays can be one of the two states: sorted or unsorted. The sorted arrays will be shown in green color whereas the unsorted arrays will be shown in red color.

Merge Operation

The Merge operation takes two list and returns a single combined list. At each step of merge operation, smaller of the first elements from Left/Right input lists is taken and added to the result list.

Procedure

  1. Compare the first elements of the "left" and "right" arrays.
  2. If the first element of the "left" array is smaller then add this element to the "result" array by clicking on the "Left" button. Similarly if the first element on the "left" array is larger then you will pick the element from the "right" array.
  3. Continue until both left and right arrays are empty.
  4. Observe whether the "result" array is sorted or not.