A
alexbarham
Hello,
I am working through Mastering Algorithms with PERL. I am reading about
binary trees and how to keep them balanced. The example code shows tree
manipulation but doesn't show how to build the tree. I would like to
try out the sample code. However, I don't quite understand how to build
a binary tree. If I wanted to build a tree with one left node having a
value of 1 and a right node with a value of 2, how would I do it? Is it
a hash of hashes as in?:
my %tree = {
{left=>0,
right=>1,
val=>1}
left=>1,
right=>0,
val=>2}
};
Is it an array of array?
my @tree = [[0,0,1],[1,0,2]];
Or is it more flexible than this. Any help would be greatly appreciated!
I am working through Mastering Algorithms with PERL. I am reading about
binary trees and how to keep them balanced. The example code shows tree
manipulation but doesn't show how to build the tree. I would like to
try out the sample code. However, I don't quite understand how to build
a binary tree. If I wanted to build a tree with one left node having a
value of 1 and a right node with a value of 2, how would I do it? Is it
a hash of hashes as in?:
my %tree = {
{left=>0,
right=>1,
val=>1}
left=>1,
right=>0,
val=>2}
};
Is it an array of array?
my @tree = [[0,0,1],[1,0,2]];
Or is it more flexible than this. Any help would be greatly appreciated!