develooper Front page | perl.fwp | Postings from September 2001

binary trees in arrays

Thread Next
From:
David L. Nicol
Date:
September 6, 2001 04:03
Subject:
binary trees in arrays
Message ID:
3B975681.50E1626@kasey.umkc.edu


I have just been hipped to the elegant method of storing binary
trees in arrays, which I never knew before.  Here is the kernel
of it:


	The root of the tree is always at position 0

	The parent of any node $N is at position int($N >> 1)

	The children of any node are at ($N << 1) and (($N << 1) +1)

	( aka $N*2 and $N*2+1 )


	Are there any CPAN modules that use this technique to create
hash-like containers in the form of trees of [$key,$value] objects?




-- 
                                           David Nicol 816.235.1187
Refuse to take new work - finish existing work - shut down.

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About