Datastructures
Trees in Data structures
USEFUL FOR FYBSC (IT), FYBCA STUDENTS
Trees |
Binary Trees
The simplest form of tree is a binary tree. A binary tree consists of
- a node (called the root node) and
- left and right sub-trees.
Both the sub-trees are themselves binary trees.
A binary tree
The nodes at the lowest levels of the tree (the ones with no sub-trees) are called leaves.
In an ordered binary tree,
- the keys of all the nodes in the left sub-tree are less than that of the root,
- the keys of all the nodes in the right sub-tree are greater than that of the root,
- the left and right sub-trees are themselves ordered binary trees.
Posted By-: Vissicomp Technology Pvt. Ltd.
Website -: http://www.vissicomp.com
Datastructures in C programming
#include
#include
void main( )
{
int arr[10] = { 1, 2, 3, 9, 11, 13, 17, 25, 57, 90 } ;
int mid, lower = 0 , upper = 9, num, flag = 1 ;
clrscr( ) ;
printf ( “Enter number to search: ” ) ;
scanf ( “%d”, &num ) ;
for ( mid = ( lower + upper ) / 2 ; lower <= upper ; mid = ( lower + upper ) / 2 ) { if ( arr[mid] == num ) { printf ( “The number is at position %d in the array.”, mid ) ; flag = 0 ; break ; } if ( arr[mid] > num )
upper = mid – 1 ;
else
lower = mid + 1 ;
}
if ( flag )
printf ( “Element is not present in the array.” ) ;
getch( ) ;
Posted By-: Vissicomp Technology Pvt. Ltd.
Website -: http://www.vissicomp.com
You must be logged in to post a comment.