DSA SheetLesson · no judge

CODE DRILL 2 · RUN ONLY

Write it, run it, read the output

This is a scratch drill — your code runs, nothing is graded or recorded. No test cases, no expected output, no verdict.

TASK

Implement insertion sort for [5, 2, 4, 6, 2, 3]. Save each key and shift only larger values, then print the sorted array and report 12 value comparisons and 8 shifts. Count one value comparison each time you evaluate whether a[j] > key, including the comparison that stops a pass, and do not count j >= 0 as a value comparison.

Java
Loading editor…

OUTPUT

Sample
2 2 3 4 5 6 
comparisons: 12
shifts: 8

What a finished answer prints, from the lesson. Nothing has run yet — press Run and this is replaced by your program’s own output.