Results 1 to 4 of 4

Thread: What is the difference between binary tree sort and heap sort in data structure

  1. #1
    Join Date
    Dec 2010
    Posts
    16

    What is the difference between binary tree sort and heap sort in data structure

    Hey friends, I am a student of BCA where in I am having a subject as data structure in which I am having problem in binary tree sort and heap sort. I don’t understand this as I have tried more than a number of times. Is there any term known as node? If there than is it n binary tree sort or heap sort. I confused with both this term. I also wanted to know what are the difference between binary tree sort and heap sort.

  2. #2
    Join Date
    Apr 2009
    Posts
    569

    Re: What is the difference between binary tree sort and heap sort in data structure

    Binary tree search uses a binary search tree. In this method each element is scanned from input list and placed in its proper position in a binary tree. In binary tree each element is known as node. To place an element in its proper position the element is compared with the node element, and then it is placed in the left branch if the element is greater than or equal to the node then it is placed in the right branch. Now if we access the element according to in order traversal we would get the elements in ascending order.

  3. #3
    Join Date
    May 2009
    Posts
    527

    Re: What is the difference between binary tree sort and heap sort in data structure

    Code:
    #include <stdio.h>
    #include <conio.h>
    #include <alloc.h>
    
    struct btreenode
    {
    	struct btreenode *leftchild ;
    	int data ;
    	struct btreenode *rightchild ;
    } ;
    
    void insert ( struct btreenode **, int ) ;
    void inorder ( struct btreenode * ) ;
    
    void main( )
    {
    	struct btreenode *bt ;
    	int arr[10] = { 11, 2, 9, 13, 57, 25, 17, 1, 
                                                                         90, 3 } ;
    	int i ;
    
    	bt = NULL ;
    
    	clrscr( ) ;
    
    	printf ( "Binary tree sort.\n" ) ;
    
    	printf ( "\nArray:\n" ) ;
    	for ( i = 0 ; i <= 9 ; i++ )
    		printf ( "%d\t", arr[i] ) ;
    
    	for ( i = 0 ; i <= 9 ; i++ )
    		insert ( &bt, arr[i] ) ;
    
    	printf ( "\nIn-order traversal of binary 
                                                            tree:\n" ) ;
    	inorder ( bt ) ;
    
    	getch( ) ;
    }
    void insert ( struct btreenode **sr, int num )
    {
    	if ( *sr == NULL )
    	{
    	*sr = malloc ( sizeof ( struct btreenode ) ) ;
    
    		( *sr ) -> leftchild = NULL ;
    		( *sr ) -> data = num ;
    		( *sr ) -> rightchild = NULL ;
    	}
    	else
    	{
    	if ( num < ( *sr ) -> data )
    	insert ( &( ( *sr ) -> leftchild ), num ) ;
    	else
    	insert ( &( ( *sr ) -> rightchild ), num ) ;
    	}
    }
    
    void inorder ( struct btreenode *sr )
    {
    	if ( sr != NULL )
    	{
    		inorder ( sr -> leftchild ) ;
    		printf ( "%d\t", sr -> data ) ;
    		inorder ( sr -> rightchild ) ;
    	}
    }
    This is an example of binary search sort in C language where you will find how stack is been used in this sorting. If you observe carefully you will find the concept of binary tree and node also. If you execute this program you will come to know the process of binary tree sorting.

  4. #4
    Join Date
    Apr 2009
    Posts
    488

    Re: What is the difference between binary tree sort and heap sort in data structure

    In this method, a tree structure called heap is used .A heap is type of binary tree. An ordered balanced binary tree is called min heap where the value at the root of any sub tree is less than or equal to the value of either of its children. An ordered balanced binary tree is called max heap when the value at the root of any sub tree is more than or equal to the value of either of its children. It is not necessary that the two children must be in some order. Sometime the value in the left child may be more than the value at right child and some other times it may be the other way round.

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 is the use of insertion sort in data structure?
    By Venugopala in forum Software Development
    Replies: 3
    Last Post: 04-01-2011, 02:41 AM
  3. 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
  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. How to use Bubble sort in C# to sort parallel arraylists
    By Ground 0 in forum Software Development
    Replies: 3
    Last Post: 03-08-2009, 12:12 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,711,630,100.89853 seconds with 17 queries