



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Helps in arrays and binary trees
Typology: Summaries
1 / 6
This page cannot be seen from the preview
Don't miss anything!




Data structure is a collection of different data items that are stored together as a single unit and the operations allowable on them.
A binary tree is a data structure, consisting of a root node and zero, one or two sub-tree which are organised in a hierarchical way. Each node is a parent of at most two nodes. Constructing a Binary Tree Place first item into root node For subsequent items, start from root node Repeat If (new item > this node item) Then Follow right pointer Else Endif Follow left pointer Until pointer = 0 Place item at this node Binary tree traversal Tree traversal means walking through the trees’ structure such that each node is visited once. Common traversal methods are: Pre-Order, In-order and Post-Order Traversals. Pre-Order traversal The order of traversal is:
There are two possible cases with a node (successor or predecessor)
b) The node to be deleted has two child nodes, therefore
Searching item from Binary Tree The algorithm is as follows: Enter item to search(this item) Start at root node Repeat If wanted item = this item Then Found = True Display Item Else If wanted Item >this item Then Follow right pointer EndIf Else EndIf Follow left pointer Until (Found=True or Null pointer is encountered) IMPLEMENTATION OF BINARY TREES USING ARRAYS Binary trees can be implemented using left and right pointers for each node. Each node will have the following: