Chapter 4 · SimulationSorting Algorithm Visualizer? ← Chapter 4 Algorithm Selection sort Bubble sort Insertion sort Merge sort Size 10 Order Random Sorted Reversed Nearly sorted New array being compared swap / write minIdx in its final place ⏮ Start ◀ Back Step ▶ Play Speed Predict TrueFalse CloseSorting visualizerGoal: Watch which items the sorting algorithms from the slides compare at each step and how they move; compare the numbers of comparisons and swaps across algorithms and starting orders.How to use itChoose the algorithm, the array size (5–40) and the starting order; New array generates new random values.Step ▶ advances one step, ◀ Back goes back one step, Play runs automatically to the end. In the pseudocode on the right the line running in that step is highlighted.While Predict is ticked, the run stops at every comparison: predict whether the condition will be True or False; your score is kept at the bottom right.What to look forAlgorithmComparisonsHintSelectionalways n(n−1)/2at most n−1 swapsBubblen−1 on a sorted arraystops after a pass with no swapsInsertionn−1 on a sorted arrayworst case on a reversed arrayMerge≈ n log₂ nhelper array: extra memory O(n)In insertion sort the second counter shows the number of shifts (arr[j+1] = arr[j]); in merge sort it shows the number of writes from the temporary array back into the array.Related slides: Chapter 4.1 · Algorithms.