Embercode
✕
SortingQuick quiz

Nearly sorted and shell

7 questions. Covers Shell sort in Python.

Questions 1 to 5 of 7

  1. 1. Insertion sort runs on the reversed list [1000, 999, ..., 1] of 1000 numbers, and every shift is counted. How many shifts does it make?

    Type a number.

  2. 2. Insertion sort runs on a list where every value is at most k places from its final position. What is its running time?
  3. 3. What does this program print? ``python def gapped_insertion(a, gap): for i in range(gap, len(a)): value = a[i] j = i while j >= gap and a[j - gap] > value: a[j] = a[j - gap] j -= gap a[j] = value a = [7, 2, 9, 4, 1, 8, 3, 6] gapped_insertion(a, 4) print(a) ``
  4. 4. What does this program print? ``python moves = 0 def gapped_insertion(a, gap): global moves for i in range(gap, len(a)): value = a[i] j = i while j >= gap and a[j - gap] > value: a[j] = a[j - gap] moves += 1 j -= gap a[j] = value a = [5, 4, 3, 2, 1, 6] gapped_insertion(a, 2) gapped_insertion(a, 1) print(a, "moves=" + str(moves)) ``
  5. 5. For a list of length 20, Knuth's rule gives which gap list?

5 question(s) left on this page.

Typed answers ignore extra spaces and, for most questions, capital letters.