answersLogoWhite

0


Best Answer

int Nodes (Tree *t)

{

int sum= 0;

if (t) {

sum+=1;

if (t->left) sum += Nodes (t->left);

if (t->right) sum += Nodes (t->right);

}

return sum;

}

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Recursive function in c to compute the number of nodes in a binary tree?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is a recursive function?

A recursive function is one that calls upon itself until a given result in the original call is met. Take a look at this example. Program Recursion; Uses crt; Var number:longint; Function Factorial(number:longint):longint; Begin if number > 0 then factorial:=number*factorial(number-1) else factorial:=1; End; Begin clrscr; readln(number); writeln(factorial(number)); readln; End. Note how the function factorial calls itself.


Write a recursive method to compute the number of digits in a positive integer?

Such a method could be: public int NumberOfDigits(int num) { num = num/10; if( num == 0) return 1; return ( 1+NumberOfDigits(num) ); }


How do you count all structurally different possible Binary Trees?

please tell me answer of this question. Suppose you are building an N node binary search tree with the values 1...N. how many structurally different binary trees is there that store those values? write a recursive function that, gives the number of distinct values, computes the number of structurally unique binary search trees that store those values. For example, countTrees(4) should return 14, since there are 14 structurally unique binary search trees that store 1,2,3 and 4. The base case us easy, and the recursion is short but dense. your code should not construct any actual trees; it's just a counting problem.


What is simulation recursion in C?

The factorial f(n) = n * (n-1) * (n-2) * .. 1. For example factorial 5 (written as 5!) = 5 x 4 x 3 x 2 x 1 = 120. The function below returns the factorial of the parameter n. int factorial( int n) { if (n==1) return 1 else return n* factorial( n-1) ; }


Write a java that computes the value of 2?

Compute means to calculate. What do you want to "compute", if you already know it is 2? If you want to show the value:System.out.println("Your number is " + 2);Compute means to calculate. What do you want to "compute", if you already know it is 2? If you want to show the value:System.out.println("Your number is " + 2);Compute means to calculate. What do you want to "compute", if you already know it is 2? If you want to show the value:System.out.println("Your number is " + 2);Compute means to calculate. What do you want to "compute", if you already know it is 2? If you want to show the value:System.out.println("Your number is " + 2);

Related questions

What is a recursive function?

A recursive function is one that calls upon itself until a given result in the original call is met. Take a look at this example. Program Recursion; Uses crt; Var number:longint; Function Factorial(number:longint):longint; Begin if number > 0 then factorial:=number*factorial(number-1) else factorial:=1; End; Begin clrscr; readln(number); writeln(factorial(number)); readln; End. Note how the function factorial calls itself.


What happens to a binary number n if you compute n mod 4?

The remainder of the division, by 4, is a number between 0 and 3. In the case of binary, this would maintain the last two bits of the original number.


What is a term for a number that goes into a function machine?

Its called "Binary Numbers"


How do you solve a binary operation?

(11110011)base 2 solve dis binary number... Answer to this question requires an understanding of binary function, truth table and gate level minimization approach. [1] A binary function is an expression consisting for binary variables, binary operators and constants (1 or 0). [1] http://fullchipdesign.com/bfttg.htm Example of binary function minimization approach can be referred from Internet resources.


Is a function that maps binary to natural numbers a bijection?

No. The set of binary numbers includes fractions which are written in binary form. For example, binary(0.1) = decimal(0.5) which is not a natural number.


Why computer use number system?

Computers cannot understand languages. They can only compute data. Because of that, we use binary code because that is pure data.


Write a Recursive function to find decimal equivalent of binary?

main(){int n;printf("\n Enter any number:");scanf("%d", &n); dec2bin(n);}dec2bin(int n){if(n == 0)return ; else{dec2bin (n/2);printf("%d", n%10);}}


Write a recursive method to compute the number of digits in a positive integer?

Such a method could be: public int NumberOfDigits(int num) { num = num/10; if( num == 0) return 1; return ( 1+NumberOfDigits(num) ); }


What is a recursive formula and what is it used for Geometric and Arithmetic?

A recursive definition is any definition that uses the thing to be defined as part of the definition. A recursive formula, or function, is a related formula or function. A recursive function uses the function itself in the definition. For example: The factorial function, written n!, is defined as the product of all the numbers, from 1 to the number (in this case "n"). For example, the factorial of 4, written 4!, is equal to 1 x 2 x 3 x 4. This can also be defined as follows: 0! = 1 For any "n" > 0, n! = n x (n-1)! For example, according to this definition, the factorial of 4 is the same as 4 times the factorial of 3. Try it out - apply the recursive formula, until you get to the base case. Note that a base case is necessary; otherwise, the recursion would never end.


How do you count all structurally different possible Binary Trees?

please tell me answer of this question. Suppose you are building an N node binary search tree with the values 1...N. how many structurally different binary trees is there that store those values? write a recursive function that, gives the number of distinct values, computes the number of structurally unique binary search trees that store those values. For example, countTrees(4) should return 14, since there are 14 structurally unique binary search trees that store 1,2,3 and 4. The base case us easy, and the recursion is short but dense. your code should not construct any actual trees; it's just a counting problem.


Write a java that computes the value of 2?

Compute means to calculate. What do you want to "compute", if you already know it is 2? If you want to show the value:System.out.println("Your number is " + 2);Compute means to calculate. What do you want to "compute", if you already know it is 2? If you want to show the value:System.out.println("Your number is " + 2);Compute means to calculate. What do you want to "compute", if you already know it is 2? If you want to show the value:System.out.println("Your number is " + 2);Compute means to calculate. What do you want to "compute", if you already know it is 2? If you want to show the value:System.out.println("Your number is " + 2);


What is simulation recursion in C?

The factorial f(n) = n * (n-1) * (n-2) * .. 1. For example factorial 5 (written as 5!) = 5 x 4 x 3 x 2 x 1 = 120. The function below returns the factorial of the parameter n. int factorial( int n) { if (n==1) return 1 else return n* factorial( n-1) ; }