Skip to main navigation menu Skip to main content Skip to site footer

THE INSERTION SORT METHOD FOR ARRAY SORTING IN PYTHON PROGRAMMING

Abstract

Insertion sort is a simple and intuitive algorithm used for sorting arrays in Python programming. It works by dividing the array into two parts: a sorted portion and an unsorted portion. At each step, the algorithm takes one element from the unsorted part and inserts it into its correct position within the sorted part. This process continues until all elements are arranged in the desired order.

In Python, insertion sort is typically implemented using loops and conditional statements. The algorithm iterates through the array starting from the second element, compares it with the previous elements, and shifts larger elements one position ahead to make space for insertion. This approach makes insertion sort efficient for small datasets or nearly sorted arrays.

The time complexity of insertion sort is O(n^2) in the worst and average cases, while in the best case (when the array is already sorted), it performs at O(n) Despite its simplicity, insertion sort is not suitable for large datasets due to its quadratic time complexity. However, its advantages include ease of implementation, stability, and low memory usage since it is an in-place sorting algorithm.

 

 

Keywords

Insertion Sort, Array Sorting, Python Programming, Sorting Algorithms, Data Structures, Algorithm Efficiency, Time Complexity, In-place Sorting, Stable Sorting, Iterative Methods

PDF

References

  1. M. Shahzad, M. Shakeel, A. U. Rehman, and M. U. Shoukat. Review on Sorting Algorithms - A Comparative Study, International Journal of Innovative Science and Modern Engineering, vol. 5, no. 1, p. 4, 2017.
  2. Ali, I., H, Nawaz, I.K., Ameen, M., Chhajro, M. and Maitlo, A. Performance Comparison between Merge and Quick Sort Algorithms in Data Structure, in International Journal Of Advanced Computer Science And Applications, 9(11), pp.192-195, 2018.
  3. J. P. Ocampo. An empirical comparison of the runtime of five sorting algorithms, p. 26.
  4. A. Alotaibi, A. Almutairi, and H. Kurdi. OneByOne (OBO): A Fast Sorting Algorithm, in Procedia Comput. Sci., vol. 175, pp. 270–277, 2020. doi: 10.1016/j.procs.2020.07.040.
  5. J. Alnihoud and R. Mansi. An Enhancement of Major Sorting Algorithms, Int. Arab J. Inf. Technol. vol. 7, no. 1, pp 55-62, 2010.
  6. N. Yadav and S. Kumari. Sorting Algorithms, in International Research Journal of Engineering and Technology, vol. 3, no. 2, pp. 528-531, 2016.
  7. F. G. Furat. A Comparative Study of Selection Sort and Insertion Sort Algorithms, in International Research Journal of Engineering and Technology (IRJET), vol. 03, no. 12, pp. 336–330, Dec. 2016.
  8. W. Min. Analysis on Bubble Sort Algorithm Optimization, in 2010 International Forum on Information Technology and Applications, Kunming, China, Jul. 2010, pp. 208–211. doi: 10.1109/IFITA.2010.9.

Downloads

Download data is not yet available.