|
| ||||||||||
| Tags: binary tree, binary tree sort, data structure, heap sort, node |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| What is the difference between binary tree sort and heap sort in data structure
|
|
#2
| |||
| |||
| 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
| ||||
| ||||
| 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 ) ;
}
} |
|
#4
| |||
| |||
| 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. |
![]() |
|
| Thread Tools | Search this Thread |
| |
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 |