472,809 Members | 2,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,809 software developers and data experts.

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 3327
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: binaya | last post by:
Dear all, Will you please let me know the pseduo code/algorithmn for the making of complete binary tree ? Thanking you in advance...
3
by: Tracey | last post by:
I have an algorithm question and don't know how to do it nicely. Write a function to print nodes of binary tree, for each leaf node, print nodes from root node to leaf node. For example, the...
16
by: Joel Finkel | last post by:
Folks, I am confused as to how to implement the following solution. I have a series of processing steps, each of which contains similar features (forms, etc). Therefore, I create a base...
10
by: Aris | last post by:
Hello! This is my problem. I'm trying to make an inorder traversal algorithm for a binary tree, not a recursive one, but using a stack. Till now I got this: void traverse(tree * p) { l:...
0
by: rokuingh | last post by:
ok, so i've been working on this one for quite a while, and the code is very big so i'm just going to give the relevant parts. this is a program that builds polymers (chemical structures of repeated...
8
by: sandeep | last post by:
Our team is developing proxy server(in VC++)which can handle 5000 clients. I have to implement cache part so when ever a new request com from client I have to check the request URL content is in...
1
by: satan | last post by:
I need to write the definition of the method leavesCount that takes as a parameter a reference of the root node of a binary tree and returns the numbers of leaves in the binary tree. This what i get...
6
by: pj | last post by:
Hi, I 'm currently writing a program that performs transliteration (i.e., converts greek text written using the english alphabet to "pure" greek text using the greek alphabet) as part of my...
5
by: nehap | last post by:
I am doing project in DataMining.Can I get the source code for Binary Decision Tree algorithm in JAVA using some Dataset?
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.