Operations on Binary Tree - Data Stuctures - Lecture Slides, Slides of Data Structures and Algorithms

Operations on Binary Tree, Applications of Binary Trees, Searching for Duplicates, C Implementation, Trace of insert, New tree node, Root node, Number of comparisons are key points of this lecture. and you can learn some other data structure terms.

Typology: Slides

2011/2012

Uploaded on 11/03/2012

ekna
ekna 🇮🇳

4.2

(5)

75 documents

1 / 46

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Operations on Binary Tree
There are a number of operations that can
be defined for a binary tree.
If p is pointing to a node in an existing tree
then
left(p) returns pointer to the left subtree
right(p) returns pointer to right subtree
parent(p) returns the father of p
brother(p) returns brother of p.
info(p) returns content of the node.
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e

Partial preview of the text

Download Operations on Binary Tree - Data Stuctures - Lecture Slides and more Slides Data Structures and Algorithms in PDF only on Docsity!

Operations on Binary Tree

 There are a number of operations that can be defined for a binary tree.

 If p is pointing to a node in an existing tree then  left( p ) returns pointer to the left subtree  right( p ) returns pointer to right subtree  parent( p ) returns the father of p  brother( p ) returns brother of p.  info(p) returns content of the node.

Operations on Binary Tree

 In order to construct a binary tree, the following can be useful:

 setLeft(p,x) creates the left child node of p. The child node contains the info ‘x’.

 setRight(p,x) creates the right child node of p. The child node contains the info ‘x’.

Applications of Binary Trees

 One way of finding duplicates is to compare each number with all those that precede it.

14, 15, 4, 9, 7, 18, 3, 5, 16, 4, 20, 17, 9, 14, 5

14, 15, 4, 9, 7, 18, 3, 5, 16, 4, 20, 17, 9, 14, 5

 If the list of numbers is large and is growing, this procedure involves a large number of comparisons.

 A linked list could handle the growth but the comparisons would still be large.

 The number of comparisons can be drastically reduced by using a binary tree.

 The tree grows dynamically like the linked list.

 Otherwise, we create a new tree node and put the new number in it.

 The new node is made the left child of the root node if the second number is less than the one in the root.

 The new node is made the right child if the number is greater than the one in the root.

14, 15, 4, 9, 7, 18, 3, 5, 16, 4, 20, 17, 9, 14, 5

14

15, 4, 9, 7, 18, 3, 5, 16, 4, 20, 17, 9, 14, 5

14

15

4, 9, 7, 18, 3, 5, 16, 4, 20, 17, 9, 14, 5

14

15

4

9, 7, 18, 3, 5, 16, 4, 20, 17, 9, 14, 5

14

4 15

9

9, 7, 18, 3, 5, 16, 4, 20, 17, 9, 14, 5

14

4 15

9

7, 18, 3, 5, 16, 4, 20, 17, 9, 14, 5

14

4 15

9 7

18, 3, 5, 16, 4, 20, 17, 9, 14, 5

14

4 15

9 7

18

3, 5, 16, 4, 20, 17, 9, 14, 5

14

4 15

9 7

18

3

3, 5, 16, 4, 20, 17, 9, 14, 5

14

4 15

9 7

3 18