468,290 Members | 2,078 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,290 developers. It's quick & easy.

Need an algorithm for creating an complete binary tree.

Yeah, for some reason I can seem to find an algorithm that will simple but
items into the tree in fashion such that a new leaf can't be added to a new
level till all the leafs at the previous level are used. This would seem
like an easy solution but I couldn't find one and I only could get it
parsley working. Any body of a solution?
Thanks
Jul 22 '05 #1
2 3128
"C-man" <ia********@shaw.ca> wrote in message
news:pgv1c.39622$n17.16894@clgrps13...
Yeah, for some reason I can seem to find an algorithm that will simple but
items into the tree in fashion such that a new leaf can't be added to a new level till all the leafs at the previous level are used. This would seem
like an easy solution but I couldn't find one and I only could get it
parsley working. Any body of a solution?


Algorithms aren't topical here. Just the ISO standard C++ language.
See: http://www.slack.net/~shiva/welcome.txt

However:
http://www.google.com/search?hl=en&i...ry+tree%22+alg
orithm+%22C%2B%2B%22&btnG=Google+Search
(that'll probably wrap, just paste it back together)

Over 7,000 hits.

You might want to try asking about this in an algorithms group
or mailing list.

-Mike
Jul 22 '05 #2
"C-man" <ia********@shaw.ca> wrote:
Yeah, for some reason I can seem to find an algorithm that will simple but
items into the tree in fashion such that a new leaf can't be added to a new
level till all the leafs at the previous level are used. This would seem
like an easy solution but I couldn't find one and I only could get it
parsley working. Any body of a solution?


What is your actual goal? Typically, for something like a search tree it is
sufficient that the tree is reasonably balanced. For example, if the
maximum height in each (sub)tree is at most twice the minimum height, you
will get logarithmic access to all operations. And the corresponding
condition is relatively easy to maintain using AVL- or Red-Black-Trees.

The simplest approach to a fully balanced binary tree is probably using an
array in the first place! You would use 'std::lower_bound()' to locate a
position - be it for insertion or lookup. The container is, in this case,
of course not node bound.
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
Phaidros eaSE - Easy Software Engineering: <http://www.phaidros.com/>
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by binaya | last post: by
3 posts views Thread by Tracey | last post: by
16 posts views Thread by Joel Finkel | last post: by
10 posts views Thread by Aris | last post: by
8 posts views Thread by sandeep | last post: by
1 post views Thread by satan | last post: by
5 posts views Thread by nehap | last post: by
reply views Thread by NPC403 | last post: by
2 posts views Thread by MrBee | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.