Docsity

Binary Tree Data Structure: Components, Types, and Common Operations, Slides of Algorithms and Programming

Partial preview of the text

Download Binary Tree Data Structure: Components, Types, and Common Operations and more Slides Algorithms and Programming in PDF only on Docsity!

BINARY TREE DATA STRUCTURE

BINARY TREE

A binary tree is a tree-type non-linear data

structure with a maximum of two children

for each parent. Every node in a binary

tree has a left and right reference along

with the data element.

TERMINOLOGIES ASSOCIATED WITH

BINARY TREES

Node: It represents a

termination point in a tree.

Root: A tree’s topmost node.

Parent: Each node (apart

from the root) in a tree that

has at least one sub-node of its

own is called a parent node.

There are three binary tree components. Every binary tree node has

these three components associated with it. It becomes an essential

concept for programmers to understand these three binary tree

components:

Data element

Pointer to left subtree

Pointer to right subtree

Binary Tree

Components

These three binary tree components represent a node. The data

resides in the middle. The left pointer points to the child node,

forming the left sub-tree. The right pointer points to the child

node at its right, creating the right subtree.

COMPLETE BINARY TREE

The complete binary tree is a tree in

which all the nodes are completely

filled except the last level. In the last

level, all the nodes must be as left as

possible. In a complete binary tree,

the nodes should be added from the

left.

PERFECT BINARY TREE

  • A tree is a perfect binary tree if

all the internal nodes have 2

children, and all the leaf nodes

are at the same level.

BALANCED BINARY TREE

  • The balanced binary tree is a

tree in which both the left and

right trees differ by atmost

COMMON OPERATIONS

  • Insertion - Nodes can be inserted into binary trees in between two other

nodes or added after a leaf node. In binary trees, a node that is inserted is

specified as to which child it is.

  • Deletion - Deletion is the process whereby a node is removed from the tree.

Only certain nodes in a binary tree can be removed unambiguously

  • Traversal - Pre-order, in-order, and post-order traversal visit each node in a

tree by recursively visiting each node in the left and right subtrees of the root.