Computer Programming

Database Programming

C Programming

# What is the C program to check whether a given binary tree is binary search tree or not?

###### Wiki User

###### 2010-09-22 05:49:28

#include <stdio.h>

void main()

{

int digi,num,i,sum=0;

printf("Enter the number of digits:");

scanf("%d",&num);

while(i>0);

{

for(i=0;i<10000;i++)

{

digi=num;

i=digi%10;

sum=sum+i;

num=digi/10;

}

printf("The sum of digits entered is %d",sum);

}

}

## Related Questions

###### Asked in Computer Programming, C Programming

### Why is binary search faster than sequential search?

In sequential search, you have to check each element in the list
one after another, with a worst case efficiency of O(n).
If you use binary search the list must be sorted), you are
essentially cutting the remaining elements you must search in half
with an efficiency of O(log n).
For example, searching for 9:
Sequential: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Binary: start at 4, 9 is higher you have 5 - 9 to the right. You
check halfway through that "list", you see that 9 is larger than 7,
so go right, repeat.

###### Asked in Computer Programming, Search Engines

### When is it not recommended to perform the operation of binary search?

In computer science, a binary search or half-interval
search algorithm finds the position of a specified value (the
input "key") in an array sorted[1][2] into order on the values of
the key. At each stage, the algorithm compares the sought key value
with the key value of the middle element of the array. If the keys
match, then a matching element has been found so its index is
returned. Otherwise, if the sought key is less than the middle
element's key, then the algorithm repeats its action on the
subarray to the left of the middle element or, if the input key is
greater, on the subarray to the right. If the array span to be
searched is reduced to zero, then the key cannot be found in the
array and a special "Not found" indication is returned.
A binary search halves the number of items to check with each
iteration, so locating the an item (or determining its absence)
takes logarithmic time. A binary search is a dichotomic divide and
conquer search algorithm.
Next Answer
A binary search method requires that the list of items being
search should be sorted in ascending (or descending) order. If the
search list is not sorted, the binary search method will not work
and other search methods will be needed.