Recursion is a very common technique used in today's programs. Although recursion is a very easy method to solve problems, it can easily introduce unwanted overhead that can quickly worsen program's performance.
The facts,
1) We created a recursive function to calculate the number of nodes in a full binary tree, given as argument the tree's height.
2) We implemented this function in Parrot, and also on interpreted and compiled languges.
3) We ran the programs several times increasing the height of the tree.
Here are the results: http://nrc.homelinux.org/parrot/bintree.png.
sources? (Score:1)
Pm
Re: (Score:1)
Re: (Score:1)
Pm
bintree.pl eq (Score:1)
Re: (Score:1)
sub n_of_nodes {
my ($x) = @_;
return $x == 0 ? 1 : 1 + n_of_nodes($x-1) + n_of_nodes($x-1);
}