- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Rooted and Binary Tree

## Rooted Tree

A rooted tree ** G** is a connected acyclic graph with a special node that is called the root of the tree and every edge directly or indirectly originates from the root. An ordered rooted tree is a rooted tree where the children of each internal vertex are ordered. If every internal vertex of a rooted tree has not more than m children, it is called an m-ary tree. If every internal vertex of a rooted tree has exactly m children, it is called a full m-ary tree. If

**, the rooted tree is called a binary tree.**

*m = 2*## Binary Search Tree

The binary Search tree is a binary tree which satisfies the following property −

- X in left sub-tree of vertex V, Value(X) ≤ Value (V)
- Y in right sub-tree of vertex V, Value(Y) ≥ Value (V)

So, the value of all the vertices of the left sub-tree of an internal node ** V** are less than or equal to

**and the value of all the vertices of the right sub-tree of the internal node**

*V***are greater than or equal to**

*V***. The number of links from the root node to the deepest node is the height of the Binary Search Tree.**

*V*## Example

## Algorithm to search for a key in BST

BST_Search(x, k) if ( x = NIL or k = Value[x] ) return x; if ( k < Value[x]) return BST_Search (left[x], k); else return BST_Search (right[x], k)

## Complexity of Binary search tree

Average Case | Worst case | |
---|---|---|

Space Complexity | O(n) | O(n) |

Search Complexity | O(log n) | O(n) |

Insertion Complexity | O(log n) | O(n) |

Deletion Complexity | O(log n) | O(n) |

- Related Questions & Answers
- Difference Between B-tree and Binary tree
- Binary Tree to Binary Search Tree Conversion in C++
- Serialize and Deserialize Binary Tree in C++
- Binary Tree to Binary Search Tree Conversion using STL set C++?
- Binary Tree in Javascript
- Optimal Binary Search Tree
- Binary Indexed Tree or Fenwick Tree in C++?
- Check if a binary tree is subtree of another binary tree in C++
- Binary Search Tree in Javascript
- Invert Binary Tree in Python
- Maximum Binary Tree in C++
- Binary Tree Pruning in C++
- Print Binary Tree in C++
- Binary Tree Cameras in C++
- Binary Tree Tilt in C++