Tree

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 19

Data Structures

Lecture: Tree

By
Arvind Kumar
Asst. Professor,
Lovely Professional University, Punjab
Contents
• Introduction
• Binary Tree
• Basic Terminology
• Complete Binary Tree
• Extended Binary Tree
• Traversing Binary Tree
•Pre-order
• In-order
• Post-order
Introduction
• Trees are non-linear data structures.

• Used to represent a hierarchical relationship


between the elements.
Binary Tree
• A Binary Tree T is defined as a finite set of elements,
called nodes, such that:

(a) T is empty (called the null tree or empty tree), or


(b) T contains a distinguished node R, called the root
of T, and the remaining nodes of T form an
ordered pair of disjoint binary trees T1 and T2.

• T1 and T2 are called left sub-tree and right subtrees of R.


Binary Tree
• T1 and T2 are called left sub-tree and right subtrees of R.

• If T1 is nonempty, then its root is called the left successor


of R; similarly, if T2 is nonempty, then its root is called the
right successor of R.
Blank
Basic Terminology
• Terminal Nodes: The node with no successor is called
terminal node or leaf.

• Similar Trees: Two binary trees T1 and T2 are said to be


similar if they have the same shape or structure.

• Copy of Trees: Two binary trees T1 and T2 are said to be


copies if they are similar and if they have the same contents at
corresponding nodes.
Blank
Basic Terminology
• Parent:
• Left Child:
• Right Child:
• Siblings:
• Level:

• A line drawn from the node N to its successor is called edge.


• The sequence of consecutive edges is called Path.
• Height or Depth of a Tree is the maximum number of nodes in a
branch of T.
Height = Largest Level + 1
Blank
Complete Binary Tree
• A Binary tree T is said to be complete if all its levels,
except possibly the last, have the maximum number of
possible nodes and all the nodes at the last level appear
as far left as possible.

• The depth of a complete Binary Tree T is:


D = floor value (log2n + 1)
Blank
Extended Binary Tree
• A Binary tree T is said to be extended binary tree or 2-
Tree or Full Binary Tree if each node N has either 0 or 2
children.

• Nodes with 0 child are called external nodes.

• Nodes with 2 children are called internal nodes.


Blank
Perfect Binary Tree
• A Binary tree is Perfect Binary Tree in which all
internal nodes have two children and all leaves are at
same level.
Blank
Questions
Review Questions
• What do you mean by Non-linear Data structures?

• What is the need of trees?

• How Complete Binary Tree is different from 2-Tree?


• What is the maximum number of nodes at any level n of a
Binary Tree?

• What is the Minimum number of nodes in the last level of


Complete Binary Tree?

• What can be the maximum height of a binary tree with n nodes?


Blank

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy