Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between binary tree and binary search tree

Can anyone please explain the difference between binary tree and binary search tree with an example?

like image 960
Neel Avatar asked Jun 17 '11 00:06

Neel


People also ask

What is the difference between binary tree binary search tree and AVL tree?

In Binary Search tree, the height or depth of the tree is O(n) where n is the number of nodes in the Binary Search tree. In AVL tree, the height or depth of the tree is O(logn). It is simple to implement as we have to follow the Binary Search properties to insert the node.

Is every binary tree is a binary search tree?

Given a Binary Tree, figure out whether it's a Binary Search Tree. In a binary search tree, each node's key value is smaller than the key value of all nodes in the right subtree, and are greater than the key values of all nodes in the left subtree i.e. L < N < RL<N<R.


1 Answers

Binary tree: Tree where each node has up to two leaves

  1  / \ 2   3 

Binary search tree: Used for searching. A binary tree where the left child contains only nodes with values less than the parent node, and where the right child only contains nodes with values greater than or equal to the parent.

  2  / \ 1   3 
like image 69
user541686 Avatar answered Sep 21 '22 08:09

user541686