Results 1 to 4 of 4

Thread: What is the use of insertion sort in data structure?

  1. #1
    Join Date
    Dec 2010
    Posts
    12

    What is the use of insertion sort in data structure?

    I am not able to get the topic insertion sort in data structure. This topic is quite similar to the sorting. This is what I am finding it. I don’t know whether my observation is true or not? I want to know the method used in insertion sort in data structure. If anybody knowing anything or having the solution to this question then please let me know. I am eagerly waiting for the reply as I am very keen in knowing the solution.

  2. #2
    Join Date
    May 2009
    Posts
    529

    Re: What is the use of insertion sort in data structure?

    Insertion sort is implemented by inserting a particular element at the appropriate position. In this method the first iteration starts with comparison of 1st element with the 0th element. In the second iteration 2nd element is compared with the 0th and 1st element .In general every iteration an element is compared with all elements before it. During comparison if it is found that the element in question can be inserted at a suitable position then space is created for it by shifting the other element at the suitable position. This procedure is repeated for all elements in the array.

  3. #3
    Join Date
    May 2009
    Posts
    539

    Re: What is the use of insertion sort in data structure?

    The insertion sort is also a type of sorting where it starts the comparison of element with the 0th element. It also stores and declares the array which is also done in the other sorting methods.

    Code:
       Declare array AA
        store elements in to array AA
        set i=0 
         Repeat till i= 0 to i<=length of array-1                        // for passess
              Repeat for j=0 to j<i                    // for comparision
               check  if AA[j] >AA[i]             // for exchanging largest number
                                       int  k = AA[j]
                                           AA[j]=AA[i]
                                  set h =i
                                        Repeat till  h>j     
                                                arr[h] = arr[h - 1] ;
                         	        arr[h+ 1] = k ;
                                      decrement h by 1            
                                       end of loop
            repeat step 6 to 14
          End of loop
       increment i by 1    
       repeat step  5 to 18
      end of loop

  4. #4
    Join Date
    May 2009
    Posts
    637

    Re: What is the use of insertion sort in data structure?

    Code:
      #include <stdio.h>
    #include <conio.h>
    
    void main( )
    {
    	int arr[5] = { 25, 17, 31, 13, 2 } ;
    	int i, j, k, temp ;
    	clrscr( ) ;
    	printf ( "Insertion sort.\n" ) ;
    	printf ( "\nArray before sorting:\n") ;
    	for ( i = 0 ; i <= 4 ; i++ )
                   	printf ( "%d\t", arr[i] ) ;
    
                 for ( i = 1 ; i <= 4 ; i++ )
    	{
    
        for ( j = 0 ; j < i ; j++ )
    	     {
    	       if ( arr[j] > arr[i] )
    	        {
    		 temp = arr[j] ;
    		arr[j] = arr[i] ;
    		for ( k = i ; k > j ; k-- )
                                 	arr[k] = arr[k - 1] ;
    			arr[k + 1] = temp ;
    			}
    		}
    	}
    	printf ( "\n\nArray after sorting:\n") ;
    	for ( i = 0 ; i <= 4 ; i++ )
    		printf ( "%d\t", arr[i] ) ;
    }

Similar Threads

  1. What is bubble sort in data structure
    By punguzhali in forum Software Development
    Replies: 3
    Last Post: 04-01-2011, 03:49 AM
  2. What do you mean by Merge sort in data structure
    By fLUTE in forum Software Development
    Replies: 3
    Last Post: 04-01-2011, 02:12 AM
  3. Replies: 3
    Last Post: 04-01-2011, 01:25 AM
  4. what is Quick Sort or partition Exchanger in data structure
    By Venugopala in forum Software Development
    Replies: 3
    Last Post: 03-01-2011, 08:47 AM
  5. Insertion of clean Excel data into oracle table using html
    By Valerian in forum Software Development
    Replies: 3
    Last Post: 13-06-2009, 09:34 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,516,082.86941 seconds with 17 queries