Upcoming SlideShare
×

# computer notes - Binary tree

734 views

Published on

If every non-leaf node in a binary tree has non-empty left and right subtrees, the tree is termed a strictly binary tree. There are a number of operations that can be defined for a binary tree.

Published in: Education, Technology, Business
1 Like
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
Your message goes here
• Be the first to comment

Views
Total views
734
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
15
0
Likes
1
Embeds 0
No embeds

No notes for slide

### computer notes - Binary tree

1. 1. ecomputernotes.com Data Structures Lecture No. 12 ___________________________________________________________________ Page 1 of 13 Data Structures Lecture No. 12 Operations on Binary Tree In the last lecture, we talked about the uses of binary tree, which is an abstract data type. We discussed about the functions to find the information inside a node, the parent, the siblings(brothers), the left and right children of a node. In this lecture, we will talk about the algorithms and implementation of those functions. When we discuss about an abstract data type, firstly we focus what it can do for us and don t bother about the how part. The how part or implementation is thought out later. While implementing these abstract data types, the implementation is hidden in a class so it is abstract to the user. The user only needs to be aware of the interface. But there can be situations when the users may like to know about the implementation detail, for example, when a data type is performing quite slower than promised. For now, we start our discussion from the methods of tree data type. Consider a tree has been formed already, following methods will be used to perform different operations on a node of this tree: Operation Description left(p) Returns a pointer to the left sub-tree right(p) Returns a pointer to the right sub-tree parent(p) Returns the father node of p brother(p) Returns the brother node of p info(p) Returns the contents of node p These methods have already been discussed at the end of the previous lecture, however, few more methods are required to construct a binary tree: Operation Description setLeft(p, x) Creates the left child node of p and set the value x into it. setRight(p, x) Creates the right child node of p, the child node contains the info x. All these methods are required to build and to retrieve values from a tree.