Solved

insert into binary tree

Posted on 2012-04-07
4
284 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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks. UNbalanced.
0
 
LVL 37

Expert Comment

by:Gerwin Jansen
Comment Utility
I would have appreciated a reply on my questions before accepting another experts' comment as a solution ;)
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Have you ever thought of installing a power system that generates solar electricity to power your house? Some may say yes, while others may tell me no. But have you noticed that people around you are now considering installing such systems in their …
Article by: Nicole
This is a research brief on the potential colonization of humans on Mars.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 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

13 Experts available now in Live!

Get 1:1 Help Now