Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



What do you mean by Merge sort in data structure

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 04-01-2011
Member
 
Join Date: Dec 2010
Posts: 20
What do you mean by Merge sort in data structure
  

Hello Guys, I am having a problem in the merge sort in data structure. I tried it practically but I am not able to execute the code as it is having lots of bugs in the program. I tried to correct the code I find a new bug in it. I have neither understood the concept nor practically. If anyone having any information or knowledge about this query then please let me know soon as possible.

Reply With Quote
  #2  
Old 04-01-2011
Member
 
Join Date: May 2009
Posts: 617
Re: What do you mean by Merge sort in data structure

Merging means combining two sorted list. For this the elements from both the sorted list are compared. The smaller of both the elements is then stored in the third array. The sorting is complete when all the elements from both the lists are placed in the third list. You must not make a mistake by comparing it only from one side. It must be compared from both the sides. After this you have to compare both the list again and re arrange it. Merging sort is easy to use to when there are big list of elements then it becomes bit tough.
Reply With Quote
  #3  
Old 04-01-2011
Member
 
Join Date: Apr 2009
Posts: 483
Re: What do you mean by Merge sort in data structure

Code:
      Declare array AA , BB and CC
   store elements in to array AA and BB
    set i=j=k=0 // i for AA   j for BB   and k for CC
   Repeat till i<=length of array CC-1   
                         check  if AA[i] <=BB[j]   
                                       CC[k]= AA[i]
                                        ++k;++i;
                                           else
                                       CC[k]= BB[j]
                                           ++k;++j;
          repeat step 6 to 10
        End of loop

for ( i = j = k = 0 ; i <= 9 ; )
	{
		if ( a[j] <=  b[k] )
			c[i++] = a[j++] ;
		else
			c[i++] = b[k++] ;

		if ( j == 5 || k == 5 )
			break ;
	}
	for ( ; j <= 4 ; )
		c[i++] = a[j++] ;

	for ( ; k <= 4 ; )
		c[i++] = b[k++] ;

This is an algorithm of merge sort which is used in sorting operation. The sorting process in this type is not that difficult as compare to other sorting but it gets bit difficult when there is a large amount of elements in the list and it becomes more tougher when you are not aware of the concept.
Reply With Quote
  #4  
Old 04-01-2011
Member
 
Join Date: May 2009
Posts: 503
Re: What do you mean by Merge sort in data structure

Code:
 
#include <stdio.h>
#include <conio.h>

void main( )
{
	int a[5] = { 11, 2, 9, 13, 57 } ;
	int b[5] = { 25, 17, 1, 90, 3 } ;
	int c[10] ;
	int i, j, k, temp ;

	clrscr( ) ;

	printf ( "Merge sort.\n" ) ;

	printf ( "\nFirst array:\n" ) ;
	for ( i = 0 ; i <= 4 ; i++ )
		printf ( "%d\t", a[i] ) ;

	printf ( "\n\nSecond array:\n" ) ;
	for ( i = 0 ; i <= 4 ; i++ )
		printf ( "%d\t", b[i] ) ;

	for ( i = 0 ; i <= 3 ; i++ )
	{
		for ( j = i + 1 ; j <= 4 ; j++ )
		{
			if ( a[i] > a[j] )
			{
				temp = a[i] ;
				a[i] = a[j] ;
				a[j] = temp ;
			}
			if ( b[i] > b[j] )
			{
				temp = b[i] ;
				b[i] = b[j] ;
				b[j] = temp ;
			}
		}
	}
This is the program where in it shows the execution of merge sort. It is explained step wise so that it becomes quite easy for you to understand. If you look at the program then you will come to know that how the arrays are declared and then how it is stored and the further process. Well, you must execute it and see it which will be more easy to understand.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "What do you mean by Merge sort in data structure"
Thread Thread Starter Forum Replies Last Post
What is bubble sort in data structure punguzhali Software Development 3 04-01-2011 02:49 AM
What is the use of insertion sort in data structure? Venugopala Software Development 3 04-01-2011 01:41 AM
What is the difference between binary tree sort and heap sort in data structure sRIPRIYA Software Development 3 04-01-2011 12:25 AM
what is Quick Sort or partition Exchanger in data structure Venugopala Software Development 3 03-01-2011 07:47 AM
Choice of data structure Hashim Software Development 5 02-11-2009 06:27 PM


All times are GMT +5.5. The time now is 07:25 PM.