Solved

insert into binary tree

Posted on 2012-04-07
4
299 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 38

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 38

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Odd Behavior 5 78
Geomentry-Fundamental concepts-Angles 3 93
Lock or digital lock that are lockable from both inside plus outside 12 106
Smoothing a rectified sine wave DDS 32 155
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 …
When we purchase storage, we typically are advertised storage of 500GB, 1TB, 2TB and so on. However, when you actually install it into your computer, your 500GB HDD will actually show up as 465GB. Why? It has to do with the way people and computers…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

738 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