0% found this document useful (0 votes)
15 views

DS-Lec11 (Introduction To Tree Data Structures)

This document provides an introduction to tree data structures and related concepts. It defines tree data structures and their use for representing hierarchical data. It then describes key tree terminology like root, child, parent and leaf nodes. It introduces different types of binary trees like complete and extended binary trees. It also defines binary search trees and provides examples of how data can be organized in them.

Uploaded by

Talha Mumtaz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

DS-Lec11 (Introduction To Tree Data Structures)

This document provides an introduction to tree data structures and related concepts. It defines tree data structures and their use for representing hierarchical data. It then describes key tree terminology like root, child, parent and leaf nodes. It introduces different types of binary trees like complete and extended binary trees. It also defines binary search trees and provides examples of how data can be organized in them.

Uploaded by

Talha Mumtaz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

3/2/2023

Content

DATA STRUCTURES • Introduction to Tree Data Structure


• Terminologies of trees.

AND ALGORITHMS • Binary Trees and their properties


• Complete Binary Tree
• Extended Binary Tree
Tree Data Structure • Binary Search Tree

By
Zainab Malik

3 4

Tree Data Structure Example-Hierarchical Data


• There are two types of data
Federal Government
• Elementary Data:
• Cannot be further divided into sub-parts
• Group Data Finance Education Defense Telecommunication ... Railways
• Can be divided into sub-parts
• It is also known as hierarchical data

• Hierarchical Data:
Army Navy Air Force
• Data that has ancestor-descendant, superior-subordinate, whole-
part or similar relationship among its elements. Representation using Tree Data Structure

• The discussed data structures like Arrays, Stack, Queue, Linked


List are not suitable for this type of data
• A Tree is an ideal data structure for representing such kind of data. Finance Education Defense Telecomm Railways Army Navy Air Force
-unication
Representation using Array Data Structure

1
3/2/2023

5 6

Example-Hierarchical Data Example-Hierarchical Data

(a) (b)

(c)

7 8

Tree Tree Terminologies


• A tree T is a finite set of elements. One of these elements • Degree of a Node: No. of children it has
is called the root, and the remaining elements, if any, are • Degree of a Tree: maximum of its nodes’ degree
• Height/Depth of a Tree: maximum level + 1
partitioned into trees, which are called as sub trees of T • Siblings: Nodes having common parent node
• Leaf Node: Node with no child
Root Node

2
3/2/2023

9 10

Binary Trees: Binary Trees for Mathematical Expressions


• A binary tree is a tree in which each node either has 0,1
or 2 children

Example 1: Binary Tree Example 2: Binary Tree

11 12

Complete Binary Tree Binary Tree vs. Complete Binary Tree


• A binary tree T is said to be complete if all its level, except
the last, have maximum number of possible nodes, and
all the nodes at the last level appear as far as left as
possible i.e. if at the last level, a node have only one child
it will be the left one

3
3/2/2023

13 14

Complete Binary Tree Extended Binary Tree


• If we numbered nodes of a complete binary tree from top- • A binary tree T is said to be an extended binary tree if
to-bottom and left-to-right, level by level then we can find each node has either 0 or 2 children,
the children and parent of any node numbered K in the • In such tree, nodes with two children are known as
complete binary tree. internal nodes and nodes with 0 children are known as
external nodes.

• Left Child: 2𝐾
• Right Child: 2𝐾 + 1
• Parent: 𝐾/2
• Height (𝑯𝒏 )=Depth(𝑫𝒏)= log 𝑛 + 1
• = log (12) + 1 = 3.58 + 1 = 4

15 16

Binary search Tree (BST) Binary search Tree (BST) - Examples


• A Binary search tree is a tree that satisfies the following
properties
• Every element has the key (content) and no other node has the
same key i.e. keys are unique
• The keys, if any, in the left sub tree of the root are small than the
key in the root node
• The keys, if any, in the right sub tree of the root are larger than the
key in the root node
• The left and right sub tree of root are also binary search trees

(a) (b)

4
3/2/2023

17

Thank You

You might also like