Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Binary tree vs Binary Search tree

Rating
-
Sold
-
Pages
7
Uploaded on
29-10-2022
Written in
2020/2021

Binary tree vs Binary Search tree comparisons

Institution
Course

Content preview

Binary tree vs Binary Search tree

First, we will understand the binary tree and binary search tree separately, and then
we will look at the differences between a binary tree and a binary search tree.

What is a Binary tree?

A Binary tree is a non-linear data structure in which a node can have either 0,
1 or maximum 2 nodes. Each node in a binary tree is represented either as a parent
node or a child node. There can be two children of the parent node, i.e., left
child and right child.

There is only one way to reach from one node to its next node in a binary tree.

A node in a binary tree has three fields:

Competitive questions on Structures in Hindi
Keep Watching

o Pointer to the left child: It stores the reference of the left-child node.
o Pointer to the right child: It stores the reference of the right-child node.
o Data element: The data element is the value of the data which is stored by the
node.

The binary tree can be represented as:

, In the above figure, we can observe that each node contains utmost 2 children. If any
node does not contain left or right child then the value of the pointer with respect to
that child would be NULL.

Basic terminologies used in a Binary tree are:

o Root node: The root node is the first or the topmost node in a binary tree.
o Parent node: When a node is connected to another node through edges, then
that node is known as a parent node. In a binary tree, parent node can have a
maximum of 2 children.
o Child node: If a node has its predecessor, then that node is known as a child
node.
o Leaf node: The node which does not contain any child known as a leaf node.
o Internal node: The node that has atleast 2 children known as an internal node.
o Depth of a node: The distance from the root node to the given node is known
as a depth of a node. We provide labels to all the nodes like root node is labeled
with 0 as it has no depth, children of the root nodes are labeled with 1, children
of the root child are labeled with 2.
o Height: The longest distance from the root node to the leaf node is the height
of the node.

In a binary tree, there is one tree known as a perfect binary tree. It is a tree in which
all the internal nodes must contain two nodes, and all the leaf nodes must be at the
same depth. In the case of a perfect binary tree, the total number of nodes exist in a
binary tree can be calculated by using the following equation:

n = 2m+1-1

where n is the number of nodes, m is the depth of a node.

What is a Binary Search tree?

A Binary search tree is a tree that follows some order to arrange the elements, whereas
the binary tree does not follow any order. In a Binary search tree, the value of the left
node must be smaller than the parent node, and the value of the right node must be
greater than the parent node.

Let's understand the concept of a binary search tree through examples.

Written for

Institution
Course

Document information

Uploaded on
October 29, 2022
Number of pages
7
Written in
2020/2021
Type
Class notes
Professor(s)
John
Contains
All classes

Subjects

$6.89
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
KanchanaMM

Also available in package deal

Get to know the seller

Seller avatar
KanchanaMM TKMCE
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
3 year
Number of followers
0
Documents
7
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions