201 views

Uploaded by aliasadsahu9304

- Red Blact Trees rbt
- 3rd Sem Data-structure
- Tree Structured Data Analysis (SPSS)
- Binary Search Trees.ppt
- Data Structures
- WBI MB Training
- VU All Books Current Papers (VU Sufi)
- WebSphere® Process Server v6.1 Business Rule Management Programming Guide
- ds
- CS301 Notes
- DS LAB MANUAL(B.E)
- Data Structures
- Analysis & Design of Algorithm July 2011
- Nuevo Documento de Microsoft Office Word
- Binary Search Tree
- hw1
- UNIT - I
- Design analysis algorithm
- 2.Tree
- Consistency in Database Systems

You are on page 1of 31

SPANNING OF TREE

Department of

Information Technology

Institute of Computing

Bahauddin Zakariya

University

Multan Pakistan

Prepared by

Mr. Ali Asad Sahu

Mr. Shuja Ahmad

Mr. Samiullah

Motivation

What ?

Why ?

How ?

Tree (Data structure)

Used to represent hierarchal relationship

between data elements.

Tree as a data structure is used to

organize our data in an specific order

and has great importance in computer

science.

Simple Tree

Tree

Nodes

Binary tree

Tree with 0–2 children per node

Terminology

Root ⇒ no parent

Leaf ⇒ no child

Interior ⇒ non-leaf

Root node

Leaf nodes

Binary Tree

A binary tree is either empty, or it consists of

a node called the root together with two binary

trees called the left sub-tree and the right sub-

tree of the root.

A node cannot have more than two sub-trees

If a new node is greater than its parent it goes

A Binary Tree Model

Memory Model of Binary

Tree

In the implementation of binary trees the

child’s of a node are pointed by two

pointers and data is stored in the object

itself.

Binary Search Trees

Key property

Value at node

Smaller values in left subtree

Larger values in right subtree

Example

X >Y X

X < Z

Y Z

Examples

5

10 10

2 45

5 30 5 45

30

2 25 45 2 25 30

10

25

Binary search Not a binary

trees search tree

Importance of Trees

Representing Algebraic formulas

Searching large and dynamic lists

Supports Very effective searching

technique using binary search.

Implemented using linked lists.

Trees are used to organize databases and

file systems.

Unix or DOS/Windows file system

Spanning of Trees

The process of inserting new data elements

in tree data structure is called spanning of

tree.

How to build & maintain binary trees?

Insertion

Deletion

Smaller values in left subtree

Larger values in right subtree

Binary Search Tree –

Insertion

Algorithm

1. Perform search for value X

2. Search will end at node Y (if X not in tree)

3. If X < Y, insert new leaf X as new left

subtree for Y

4. If X > Y, insert new leaf X as new right

subtree for Y

Example Insertion

Insert ( 20 )

10 10 < 20, right

30 > 20, left

5 30

25 > 20, left

2 25 45 Insert 20 on left

20

28,8,4,36,85,9,23,41,30 3

2

3

6

9

2 8

4

8 8

4 5

1

3

0

Binary Search Tree –

Deletion

Algorithm

1. Perform search for value X

2. If X is a leaf, delete X

3. Else

a) Replace with largest value Y on left subtree

OR smallest value Z on right

subtree

b) Delete replacement value (Y or Z) from

subtree

Example Deletion (Leaf)

Delete ( 25 )

10 10

10 < 25, right

5 30 30 > 25, left 5 30

25 = 25, delete

2 25 45 2 45

Example Deletion (Internal

Node)

Delete ( 10 ) Delete ( 5 ) Delete ( 5 )

10 5 5

5 30 5 30 2 30

2 25 45 2 25 45 2 25 45

with largest with largest

value in left value in left

subtree subtree

Binary Tree Traversal

How to reach our required node.

Standard Traversal Orders

1. Preorder NLR

2. Inorder LNR

3. Postorder LRN

Very Easy by using recursion. We have to

PreOrder Traversal

The algorithm of PreOrder traversal is

following:

Recursive Definition

Preorder

PreOrder Traversal

A A

B E B E

C D F C D F

Walking order

A B C D E F

Processing order

InOrder Traversal

The algorithm of InOrder traversal is

following:

Recursive Definition

2. Process the root R

InOrder Traversal

A A

B E B E

C D F C D F

Walking order

C B D A E F

Processing order

PostOrder Traversal

The algorithm of PostOrder traversal is following:

Recursive Definition

2. Traverse the right subtree of R in Postorder

PostOrder Traversal

A A

B E B E

C D F C D F

Walking order

C D B F E A

Processing order

Example

Whatever the mind can conceive

and believe, the mind can

achieve.

- Red Blact Trees rbtUploaded byamermer123
- 3rd Sem Data-structureUploaded bySanjeev Surad
- Tree Structured Data Analysis (SPSS)Uploaded byHimanshu Mishra
- Binary Search Trees.pptUploaded byআরব বেদুঈন
- Data StructuresUploaded bySkm Ksr
- WBI MB TrainingUploaded byketan_hirani9634
- VU All Books Current Papers (VU Sufi)Uploaded byKinza
- WebSphere® Process Server v6.1 Business Rule Management Programming GuideUploaded bymaldoreur
- dsUploaded byjssai
- CS301 NotesUploaded byRizwanIlyas
- DS LAB MANUAL(B.E)Uploaded bypitchrks19841
- Data StructuresUploaded byPurva Paschima
- Analysis & Design of Algorithm July 2011Uploaded byPrasad C M
- Nuevo Documento de Microsoft Office WordUploaded byJorge Luis Mendez
- Binary Search TreeUploaded bySaranya Thangaraj
- hw1Uploaded bysmitha_gururaj
- UNIT - IUploaded byJit Agg
- Design analysis algorithmUploaded byshruti5488
- 2.TreeUploaded byAnonymous V7P5fNQI
- Consistency in Database SystemsUploaded bychuasharmaine
- VU All Books Current Papers 2019Uploaded byM Acad
- Binary TreeUploaded byDeepakVerma
- Final Sample 2Uploaded byvivek patel
- DSTRUC Q AUploaded byJaph Dee
- spatial DMUploaded byValentina Esperanza Neira Vidal
- Edits Manual 2.1Uploaded byyashar2007
- myAIUploaded byPardeep Saini
- CSE680-11RedBlackTreesUploaded byCyrus Jia
- EEL Term PaperUploaded byAayush Goel
- B and B Plus Tree Example-TRBUploaded byUCET

- Digital Search TreeUploaded byAnonymous 6beD2TsLW
- DS Lab ManualUploaded bySharmi Devi
- TreeUploaded byAnonymous V7P5fNQI
- אלגוריתמים- הרצאה 11 | Red Black TreesUploaded byRon
- Week16 TreesUploaded byDylan Gray
- CS 4820-Lecture 6Uploaded bySean Li
- HeapSortUploaded byZaigham Abbas
- TREE ADTUploaded byAnonymous IhmXvCHj3c
- Binary Search TreesUploaded bymuucool
- Self Balancing Binary Search TreeUploaded bythe_swagmaster
- 2-3TreesUploaded byHuy Hóm Hỉnh
- Digital Search TreeUploaded byMarco M Arana
- Splay treeUploaded byPraveen Yadav
- Test QuestionsUploaded bymichaelp7897
- Data Structures 2-1 2nd Mid (1)Uploaded byBabu
- 08-splayUploaded byPavithraRam
- AVL-TreesUploaded byabhinandanpanda
- Unit III part 3.pptxUploaded byJayakumar Loganathan
- Lecture Notes for TreesUploaded bynani
- Class 21jjUploaded bykazi wahex
- Answer Homework7 Heapsort (1)Uploaded byVamshi Kolan
- Lab 2 Tree Traversal in PrologUploaded bychakravarthyashok
- austin hasemeyer final summer b 17Uploaded byapi-376386038
- 10_HeapUploaded byCristian
- Binary Search TreeUploaded byWellington Lins
- 2 3 TreesUploaded byCristina Dumitru
- Advanced Data Structures and ImplementationUploaded byLab Bhattacharjee
- BinomialHeaps NewUploaded bysonu
- Data Structures and Algorithms MCQ -3Uploaded byKuldeep Singh
- AVL TreeUploaded byMahdi Mashrur Matin