Describe the operation of the insertion sort algorithm.

What will be an ideal response?


The object of the insertion sort algorithm is to arrange the elements of an array into ascending order. Initially, the first and second elements are compared. If the second element is less than the first, their values are interchanged, and as a result the first two array elements are in ascending order. The idea of the algorithm is to gradually lengthen the section of the array that is known to be in ascending order by comparing each subsequent array element to each of those already arranged, starting with the smallest and moving upward. If, at any stage, the new element is less than the one to which it is compared, the new element is inserted just below the other. When the last element is placed, the entire array is in ascending order.

Mathematics

You might also like to view...

A. C(3, 8); D(-3, 7) B. C(-4, 3); D(-3, 7) C. C(-4, 3); D(7, -3) D. C(-4, -3); D(3, -3)

Mathematics

If one angle in a parallelogram is 135°, then one of the other angles of the parallelogram is

(a) 135° (b) 45° (c) 55° (d) Both (a) and (b) are correct. (e) Both (a) and (c) are correct

Mathematics

Solve. = 6 - x

A. ±5
B. -9, -4
C. 4
D. ±

Mathematics

For the given functions f and g, find the indicated composition.f(x) = , g(x) = 2x + 8(g?f)(x)

A. 2x + 8 B. x + 16 C. x D. x - 4

Mathematics