algo_051
Problem Statement
Problem Statement
Write an algorithm to count the number of leaf nodes in a binary tree.
Algorithm
procedure countLeaf(T)
begin
if (T = NULL) then
return 0;
else if (LC(T) = NULL and RC(T) = NULL) then
return 1;
else
return countLeaf(LC(T)) + countLeaf(RC(T));
endif
end procedure1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10