aaa
aaa

Reputation: 435

Insertion in Binary Search Tree vs Insertion in Binary Tree

What is the difference between insertion in Binary Search Tree(BST) and in Binary Tree(BT)? I know in BST, you compare the value of the new node with root, if smaller, you added to its left, if bigger you add it to the right of the root. Is it the same procedure for BT? If not, what procedure does it follow for insertion and removal?

Upvotes: 1

Views: 881

Answers (2)

angubenko
angubenko

Reputation: 274

Looks like you have misunderstanding of BT and BST defenitions. First you need to know difference between BT and BST.

  • Binary Tree is a tree, which node has at most 2 children. Storing children to the left or to the right branch doesn't depend on children value.
  • Binary Search Tree is a Binary Tree, in which childrens of each node are stored in a specific order. Children smaller than parent node usually stored on the left branch, greater or equal on the right.

Answering your question:

  • inserting in Binary Tree you need to keep track that each node has no more than 2 children. Other words, to add element to binary tree you just add it as a child to any node with less than 2 children.
  • insertng in Search Binary Tree you need to keep track that children are stored in the specific order( child smaller than parent on the left and greater or equal on the right) and parent has at most 2 children.

Upvotes: 1

sleeplessnerd
sleeplessnerd

Reputation: 22761

You are not restricted to have children <= or >= to the parent node depending on left/right.

Just put them anywhere as long as each node has at most 2 children.

Upvotes: 0

Related Questions