Solved

insert into binary tree

Posted on 2012-04-07
4
290 Views
Last Modified: 2012-06-22
if I start with an empty tree, and then insert 1,2,3, what do I get?  

if I start with an empty tree, and then insert 6,5,4, what do I get?
0
Comment
Question by:HLRosenberger
  • 2
4 Comments
 
LVL 37

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 37820167
Hi, this depends on your insert algorithm or what kind of binary tree you are building. Inserting odd to the left and even to the right, your trees would look like this:

       1
      / \
    3   2

       6
      / \
    5   4

What kind of insert algorithm are you using / what is the purpose of the tree?
0
 
LVL 32

Accepted Solution

by:
phoffric earned 500 total points
ID: 37821501
It could be:
1
 \
  2
    \
     3
(Unbalanced search tree)

or

   1
   /\
 2   3
(Balanced search tree)

- depends on the algorithm used to insert.
The balanced tree will have faster retrieval times because the depth of the tree is usually less than an unbalanced tree.
0
 
LVL 1

Author Closing Comment

by:HLRosenberger
ID: 37823723
Thanks. UNbalanced.
0
 
LVL 37

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 37823814
I would have appreciated a reply on my questions before accepting another experts' comment as a solution ;)
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to get the score in percent of an activity? 7 65
Odds of picking games correctly 4 90
Dual bridge protection 18 109
What is sqrt( (x+b/2a)^2) 35 63
A Guide to the PMT, FV, IPMT and PPMT Functions In MS Excel we have the PMT, FV, IPMT and PPMT functions, which do a fantastic job for interest rate calculations.  But what if you don't have Excel ? This article is for programmers looking to re…
How to Win a Jar of Candy Corn: A Scientific Approach! I love mathematics. If you love mathematics also, you may enjoy this tip on how to use math to win your own jar of candy corn and to impress your friends. As I said, I love math, but I gu…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question