Investigation of Insertion Sort

1530 Words4 Pages

[SORTING ALGORITHMS]

In this assignment, insertion sort will be investigated to understand how it works and what performance can be expected of it. The information found in this assignment will answer questions people have about the sort. A controlled test was done and the results were quite surprising.

Introduction

Ever wondered which types of sorts work more efficiently than others under certain conditions? In this report, light will be shed on the types of insertion sorts that exist and their efficiency. Different list sizes will be used to test this. The types of insertion sorts are namely basic insertion sort, double insertion sort and recursive insertions sort. There will also be shed light on how the Merge Sort works and how efficient it actually is. Sorts are used namely for sorting a list which makes things easier to find.

Insertion Sort

Description

The second element of an array is compared with the elements that appear before it. In this case it would be the first element in the list because the sort just started sorting. If the list should be sorted in ascending order, the second element will be switched with the first element if the second element is smaller than first element. After this step, the first two elements of an array will be sorted.

The third element is then compared with the elements that appear before it. If the third element is less than first element, it is placed in the position of first element. If the third element is larger than first element, but less than the second, it is inserted in the location of second element. If third element is larger than both the elements, it is kept in the position as it is. The first three elements in the list are now sorted.

Similarly, the fourth e...

... middle of paper ...

...e insertion sort works best with small lists and was found that when the list size exceeds 2500, the time taken takes a big jump.

List of sources

2014. Insertion Sort Algorithm in Programming [WWW Document], n.d. URL http://www.programiz.com/article/insertion-sort-algorithm-programming (accessed 5.17.14).

Bender, M.A., Farach-Colton, M., Mosteiro, M.A., 2006. Insertion Sort is O(n log n)

Bulka, D., Mayhew, D., 2000. Efficient C++: Performance Programming Techniques.

Cormen, T.H., 2001. Introduction To Algorithms.

Cutter, P. and Schultz, K. 2004. Assignments to Use Next Week: Tutorial Presentation. J. of Computing Sciences in Colleges 20(1), Oct. 2004, p. 114.

Habibi, M., Fritz, M., Cutler, R., 2004. Cracking the AP Computer Science

Lorentz, R., 1994. Recursive Algorithms.

Wang, W., 2011. Beginning Programming All-In-One Desk Reference For Dummies.

Open Document