Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
5 views

Module 04 Trees

Uploaded by

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

Module 04 Trees

Uploaded by

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

Module 4

TREES(Cont..): Binary Search trees, Selection Trees, Forests,


Representation of Disjoint sets, Counting Binary Trees,
GRAPHS: The Graph Abstract Data Types, Elementary Graph Operations

Text Book: Chapter-5: 5.7 to 5.11 Chapter-6: 6.1, 6.2

TREES
Insert 65

65
BST - Insertion
40, 30, 20, 50, 60, 70, 10, 80
BST-Insertion
50, 30, 10, 60, 80, 20, 70, 55, 35, 5
BST - Insertion
10, 5, 15, 2, 8, 13, 19, 6
Deletion in BST
1. Deleting a node with no child

2. Deleting a node having one child

3. Deleting a node having two child


1. Deleting a node with no child
Simply delete a node in the tree
Ex: 8, 3, 10, 1, 6, 14, 4, 7, 13

Leaf nodes – 1, 4, 7, 13
Deleting a node having one child
- Child will replace the position of parent

Single child nodes – 10, 14


Cont..
Deleting – 10
Cont..
Deleting – 14
Deleting a node having two child
- Replace parent with child

Child -> minimum element of Right Sub tree

Child -> Maximum element of Left Sub tree


Cont..

Nodes with two childs – 8, 3, 6


Delete a node - 6
Delete - 3
Delete – 8
Selection Tree
cont
Winner Tree
Min Winner Tree
Cont..
Loser Tree
Selection tree
• The Selection tree is a complete binary tree with n
external nodes and n – 1 internal nodes.
• The external nodes represent the players, and the
internal nodes are representing the winner of the match
between the two players.
• This tree is also known as Tournament tree.
Properties
• This tree is rooted. So the link in the tree and directed path from
parent to children, and there is a unique element with no parents.
• The parent value is less or equal to that node to general any
comparison operators, can be used as long as the relative value of the
parent and children are invariant throughout the tree.
• Trees with a number of nodes not a power of 2, contain holes. Holes
can be present at any place in the tree.
• This tree is a proper generalization of binary heaps.
• The root will represent overall winner of the tournament.
• Two types Example − Suppose there are some keys,
3, 5, 6, 7, 20, 8, 2, 9
• Winner Tree:-Winner tree is a
complete binary tree, in which
each node is representing the
smaller or greater of its two
children, is called winner tree
• Min winner
• Max winner
• Looser Tree: The looser is an
alternative representation, that
stores the looser of a match at the
corresponding node.
Looser Tree
• Example − To form a looser tree, we have to create winner tree at first.
• Suppose there are some keys, 10, 2, 7, 6, 5, 9, 12, 1.
• So we will create minimum winner tree at first.
DISJOINT SETS
Cont..
Operations on Disjoint sets
✓Union
✓Find
union
Equivalent tree & Array representation
Equivalent tree & Array representation
Find
Find(i) i is a node.
Cont..
Array representation
To find(8)

You might also like