• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 325
  • Last Modified:

insert into binary tree

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
HLRosenberger
Asked:
HLRosenberger
  • 2
1 Solution
 
Gerwin Jansen, EE MVETopic Advisor Commented:
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
 
phoffricCommented:
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
 
HLRosenbergerAuthor Commented:
Thanks. UNbalanced.
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
I would have appreciated a reply on my questions before accepting another experts' comment as a solution ;)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now