Binary tree

574 views

Published on

Published in: Education, Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
574
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
20
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Binary tree

  1. 1. Disclaimer: This presentation is prepared by trainees ofbaabtra as a part of mentoring program. This is not officialdocument of baabtra –Mentoring PartnerBaabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .Ltd
  2. 2. Binary TreesARUN KUMAR K Aarunkumar3040@gmail.comwww.facebook.com/arunkumar3040twitter.com/arunkumar3040in.linkedin.com/in/arunkumar3040+919496349799
  3. 3. Tree Terminology• A tree consists of a collection of elements ornodes, with each node linked to its successors• The node at the top of a tree is called its root• The links from a node to its successors arecalled branches• The successors of a node are called its children• The predecessor of a node is called its parent
  4. 4. Tree Terminology (continued)• Each node in a tree has exactly one parentexcept for the root node, which has no parent• Nodes that have the same parent are siblings• A node that has no children is called a leafnode
  5. 5. Binary Trees•A tree in which no node can have more thantwo children.
  6. 6. Example: Expression Trees• Leaves are operands (constants or variables)• The other nodes (internal nodes) containoperators• Will not be a binary tree if some operators arenot binary
  7. 7. Example: Expression TreesExpression tree for ( a + b * c ) + ( ( d * e + f ) * g
  8. 8. Binary Tree Traversal• Traversal is the process of visiting every nodeonce• 3 types of traversals*Inorder*Preorder*Postorder
  9. 9. Preorder traversalExpression tree for ( a + b * c ) + (( d * e + f ) * g•root, left, right•prefix expression++a*bc*+*defg
  10. 10. Inorder traversalExpression tree for ( a + b * c ) +( ( d * e + f ) * g• left, root, right•infix expressiona+b*c+d*e+f*g
  11. 11. Postorder traversalExpression tree for ( a + b * c ) + (( d * e + f ) * g• left, right, root•postfix expressionabc*+de*f+g*+
  12. 12. InsertProceed down the tree as you would find a close matchIf X is found, do nothing (or update something)Otherwise, insert X at the last spot on the path traversed
  13. 13. DeleteConsider children of deleted nodeProperty of the search tree should be maintained.Three cases:(1) the node is a leaf– Delete it immediately(2) the node has one child– Adjust a pointer from the parent to bypass that node
  14. 14. Delete(3) the node has 2 children– replace the key of that node with the minimum element at theright subtree– delete the minimum element• Has either no child or only right child because if it has a left child, thatleft child would be smaller and would have been chosen. So invokecase 1 or 2.
  15. 15. Questions…..
  16. 16. If this presentation helped you, please visit ourpage facebook.com/baabtra and like it.Thanks in advance.www.baabtra.com | www.massbaab.com |www.baabte.com
  17. 17. Contact UsEmarald Mall (Big Bazar Building)Mavoor Road, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550NC Complex, Near Bus StandMukkam, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550Start up VillageEranakulam,Kerala, India.Email: info@baabtra.com

×