Datastructures

Trees in Data structures

Posted on

USEFUL FOR FYBSC (IT), FYBCA STUDENTS  

 

Trees

 Binary Trees

The simplest form of tree is a binary tree. A binary tree consists of

  1. a node (called the root node) and
  2. left and right sub-trees.
    Both the sub-trees are themselves binary trees.

03

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,

  1. the keys of all the nodes in the left sub-tree are less than that of the root,
  2. the keys of all the nodes in the right sub-tree are greater than that of the root,
  3. the left and right sub-trees are themselves ordered binary trees.

Posted By-: Vissicomp Technology Pvt. Ltd.

Website -: http://www.vissicomp.com

Advertisements

Datastructures in C programming

Posted on

#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( ) ;

1

 

Posted By-: Vissicomp Technology Pvt. Ltd.

Website -: http://www.vissicomp.com