Solved

insert into binary tree

Posted on 2012-04-07
4
287 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
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
ID: 37823814
I would have appreciated a reply on my questions before accepting another experts' comment as a solution ;)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Linear independence 9 32
Solving an equation 8 62
Whisker Plot 1 41
Relative Frequency Assessment 2 30
We are taking giant steps in technological advances in the field of wireless telephony. At just 10 years since the advent of smartphones, it is crucial to examine the benefits and disadvantages that have been report to us.
This article provides a brief introduction to tissue engineering, the process by which organs can be grown artificially. It covers the problems with organ transplants, the tissue engineering process, and the current successes and problems of the tec…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…
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.

895 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now