Algorithm I

This is the first post in Algorithms.From this post I am looking forward to write about sorting algorithms.

Sorting Algorithms

What are Sorting Algorithms

A sorting algorithm is an algorithm that puts elements of a list in a certain order.

The most-used orders are numerical order and lexicographical order. Efficient sorting is important for optimizing the use of other algorithms which require input data to be in sorted lists.

Some main sorting algorithms are :
  • Insertion Sort.
  • Selection Sort.
  • Bubble Sort
  • Merge Sort.
  • Counting Sort.
  • Quick Sort.
  • Radix Sort.
 Let's see about the first sorting with more details.

Insertion Sort

Insertion sort is a simple sorting algorithm that is relatively efficient for small lists and mostly sorted lists, and often is used as part of more sophisticated algorithms. It works by taking elements from the list one by one and inserting them in their correct position into a new sorted list. In arrays, the new list and the remaining elements can share the array's space, but insertion is expensive, requiring shifting all following elements over by one.

Algorithm of the Insertion Sort
 
mark first element as sorted

for each unsorted element
    'element' the element

for i = lastSortedIndex to 0
    if currentSortedElement > extractedElement
        move sorted element to the right by 1
    else : insert extracted element

Implementation of Insertion sort in python



















Insertion Sort : Example 1 ( Watch the video - full screen )





 Insertion Sort : Example 2 ( Watch the video - full screen )




Now I think you got clear understand about the insertion sort.

Read more about insertion sort and get more knowledge about it.

See you soon.
Thank you.


Comments

Popular posts from this blog

love java programming

Loops