Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 324
  • 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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