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 is the difference between binary tree sort and heap sort in data structure

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 04-01-2011
Member
 
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.

Reply With Quote
  #2  
Old 04-01-2011
Member
 
Join Date: Apr 2009
Posts: 567
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.
Reply With Quote
  #3  
Old 04-01-2011
Member
 
Join Date: May 2009
Posts: 523
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.
Reply With Quote
  #4  
Old 04-01-2011
Member
 
Join Date: Apr 2009
Posts: 482
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.
Reply With Quote
Reply

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



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "What is the difference between binary tree sort and heap 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 do you mean by Merge sort in data structure fLUTE Software Development 3 04-01-2011 01:12 AM
what is Quick Sort or partition Exchanger in data structure Venugopala Software Development 3 03-01-2011 07:47 AM
How to use Bubble sort in C# to sort parallel arraylists Ground 0 Software Development 3 03-08-2009 12:12 PM


All times are GMT +5.5. The time now is 03:29 PM.