×

Binary Tree vs Binary Search Tree: Data Structure

Difference Between Binary Tree and Binary Search Tree

What is Binary Tree?

A tree which each node can have utmost two children called binary tree. These children are referred as the ‘left child’ and the ‘right child’ of the parent node. We can say a binary tree is a non-linear data structure. In binary tree, no order is preserved so it takes more time for performing the operations.

In binary tree, a node contains three fields with it:

  • Address of the left child: A node contains the reference of its left child.
  • Address of the right child: A node contains the reference of its right child.
  • Data item: A node also contains the value of data item.
Binary Tree vs Binay Search Tree

                                      BinaryTree

Binary Tree Representation

We can implement the binary tree using two ways:                                                                                                          

1. Using arrays:

We can use an array to store the nodes of binary tree. The nodes are stored in contiguous memory location that can be accessed sequentially.

2. Using linked list:

The binary tree can be implemented by linked list and its every element referred as nodes contains three fields i.e., left child, right child and data value of the node.

Binary Tree Terminologies: -

  • The first node of the tree is called root node of the tree.
  • A node has child nodes is called internal node.
  • A node that has no child is called leaf node.
  • The longest distance from the root node to the leaf node is called height of the tree
  • The number of edges from the node to the tree's root node is called the depth of the node.

The Time Complexity of Binary Tree

The operations of binary tree (i.e., insertion, deletions and searching) take O (n) time.

What is Binary Search Tree?

The binary search tree is a kind of binary tree data structure and it follows the conditions of binary tree. As we know, in binary tree a node has utmost two children so this same condition followed by binary search tree. In addition, a binary search tree has some other properties as follows:

  • In binary search tree, the left sub - tree of any node contains only smaller elements than the node element.
  • In binary search tree, the right sub - tree of any node contains only greater elements than the node element.
  • The left sub-tree and the right sub - tree must also be following the properties of binary search tree.
Binary Tree vs Binay Search Tree

The Time Complexity of Binary Search Tree

If we talk about operations of binary search tree take O (log n) time. The time complexity of these operations could be O(n) if the binary search tree skewed (if the input to the binary search tree comes in an ascending or descending manner).

Binary Search Tree Key Difference: -

Binary TreeBinary Search Tree
A tree is said to be a binary tree where every node of it contains utmost two children.Binary search tree is another type of binary tree. It also follows same condition of binary tree.
A binary tree doesn’t follow any order so the operations like insertion, deletion or searching takes more time to perform.Binary search tree stores the elements into sorted order so operations take less time to perform.
Some types of binary trees are Complete Binary Tree, Perfect Binary Tree, Full Binary Tree.Some another type of binary search trees such as Splay trees, AVL tree etc.

Related Topics

Deletion in Binary Search Tree

Implementation #include <iostream> using namespace std; struct _nod {   int ky;   struct _nod *Lft, *Rt; }; // Creating a node in the binary tree. struct _nod *nw_nod(int Itm) {   struct _nod *temp = (struct _nod *)malloc(sizeof(struct...

4 minutes read.

Difference between Stack and Queue

In this article, we will learn about the major differences between Stack and Queue data structures. What is a stack? Stack – A stack is an abstract data structure defined as the...

3 minutes read.

Introduction to 1D-Arrays

One Dimensional Array Technical Definitions The simplest version of an Array is a One-Dimensional Array, in which the items are stored linearly and may be accessed individually by supplying the index value...

6 minutes read.

Lowest common ancestor in a binary search tree

Suppose you have given two values of nodes in a binary search tree. You have to find out the lowest common ancestor between the nodes. Let’s take an example tree- For the...

4 minutes read.

Reverse a Linked List in groups of given size

Reverse a Linked List in groups of given size This article will explain how to reverse a linked list in groups of given size. Here we have given a linked list...

2 minutes read.

A Full Binary Tree with n Nodes

Implementation // Writing the implementation of the above approach in C++ #include <bits/stdc++.h> using namespace std; // We are creating a class that will create a node and its left and right children.  struct __nod...

12 minutes read.

Stack Using Array

Stack – A Stack is a linear abstract data type used to store elements. It is also called last in first out or first in last out data structure because...

6 minutes read.

Stack vs Heap Memory Allocation Data Structure

Difference Between Stack and Heap Memory Allocation Stack Memory Stack memory allocation is a way to use the system memory as a temporary storage of the data which is act like last-in-first-out...

3 minutes read.

Linear vs Non-Linear: Data Structure

What is Linear Data Structure? The data structure is said to be linear if the data elements are arranged linearly or we can say sequentially. In the linear data structure, the...

3 minutes read.

What is the difference between Tree and Graph

We usually use a diverse range of data structure to store our data and information. To store them in a more sequential manner and to access them easily, we use...

4 minutes read.

Find Number of Minimum Insertion to Make a String Palindrome

You have been given a string. You have to find out the number of minimum insertions to make this string palindrome. The string will contain only lower case alphabets. Note:What is...

4 minutes read.

Red Black Tree

Red Black Tree A red-black tree is referred as self-balancing binary search tree. The tree was invented by Rudolf Bayer in 1972. In red-black, each node stores an extra bit that...

8 minutes read.

Implementation of stack

Implementation of stack: The stack can be implemented in two ways: using array and using a linked list. The pop and push operations in the array are simpler than the...

3 minutes read.

Structure and Union Data Structure

The array is used for the same type of data, but if we want to store a mixed type of data in a group, then the array cannot be used. The Structure...

4 minutes read.

Inorder Successor in Binary Trees

The next node in the Inorder traversal of a binary tree is known as Inorder successor of that particular node. In a Binary Search Tree, the definition of Inorder successor can...

9 minutes read.

Delete nodes from the linked list which have a greater value on the right side

Delete nodes from the linked list which have a greater value on the right side In this problem, we have given a singly linked list, and we need to remove all...

3 minutes read.

Application of 2D array - Sparse Matrix

2D Arrays Application - Sparse Matrix A matrix is a two-dimensional data item consisting of m rows and n columns, with a total of m x n values. A sparse matrix...

7 minutes read.

Find all possible words from board

We have been given a dictionary of words and a board of characters from which we can form strings. Now, we have to check if the string is present in...

5 minutes read.

Segregate Even and Odd nodes in a Linked List

Segregate even and odd nodes in a Linked List In this problem, we have given a linked list with integer numbers. We need to modify the given linked list in such...

4 minutes read.

Breadth First Search

Breadth First Search Breadth first search is a graph traversing algorithm. In this, we start traversing from the source node or any selected node and traverse the graph layer by layer....

6 minutes read.