Insertion_sort

                            🖥Insertio n_sort🖥                         

 Definition :- it is simple sorting algorithm like insertion_sort it is sort by repeatedly taking the next item and insertion it into the final data structure in its proper order with respect to items it called insertion_sort

 Simple output screen :-

                 
            


  Insertion_sort   :-
         Logic
                                       Void insertion_sort(int a[] , int n) 
                                 {
                                     int i, j, temp ;
                                  For( i= 1 ; i<n ; i++) eee22 4p4
        Q                        {
                                   temp = a[ i ];
                           For( j = i-1; j>=0 && a[j]>temp;j--) 
                              a[ j + 1 ] = a  [ j ] ;
                            a [ j + 1] = temp;
                          }
                            }
                      

Example of  Ascending order :- to the arrangements of numbers or other items in an increasing order it nooin as ascending order. It means smallest to largest number

Insertion_sort :-

 Array unsorted list like this{  6 , 2 , 4 , 9 , 3 , 7 }
 



Sorted array list { 2 , 3 , 4 , 6 , 7 ,9}  
                

                         

Time Of  Complexity  :-
  
Example of Descending order :-  it is the series that begins with the greatest or largest & end with the least or smallest. It means largest to smaller number.

Insertion _sort  logic :-

                      
            int* insertion_Sort(int *arr, int n)

                              {
                           for (int i = 1; i < n; i++)
                      {
                     for (int j = i; j >= 1; j--)
                    {
            if (arr[j] > arr[j - 1])
                           { 
                         int temp = arr[j];
                         arr[j] = arr[j - 1];
                         arr[j - 1] = temp;
                                                       }
                                else
                               break;
                              }         

                                 }

Note :- this sign represented < ascending order

              this sign represented > descending order

Display on screen :-

               


   
   

  
 


Comments