Attribution Non-Commercial (BY-NC)

3 views

Attribution Non-Commercial (BY-NC)

- Basic of Trees
- RTUtil User's Guide Release 9_V013
- Optimal Binary Search Tree
- Unfolded Insert
- Using Decision Tree for Automatic Identification of Bengali Noun-Noun Compounds
- Question for Gate
- AI_Lab-3
- binary tree 2
- Ds Objective
- Self Adjusting
- Oracle PAC
- Optimal Binary Search Tree
- LDML - Application public release
- DS set 3
- AVL tree
- binary java1.docx
- Data Warehousing and Mining - Exam Solutions
- C quiz
- AP16_06
- Class

You are on page 1of 18

Chapter 6

By now you realize that the title to this slide is true When we are talking about searching or representing data structures that need a hierarchical structures. We need a better structure So we get binary trees

Tree definition

1. 2.

3.

Here is a (recursive, of course) definition for a tree: An empty structure is an empty tree If t1,,tk are disjointed trees, then the structure whose root has as its children the roots of t1,,tk is also a tree Only structures generate by rules 1 and 2 are trees.

More terminology

Each node has to be reachable from the roots through a unique sequence of arcs called a path. The number of arcs in a path is called the length of the path. The level of a node is the length of the path from the root to the node plus 1. The height of a non-empty tree is the maximum level of a node in the tree.

Special Trees

An empty tree has a height of zero. A single node tree is a tree of height 1.

This is the only case where a node is both a root and a leaf.

Binary Trees

According to the definition of trees, a node can have any number of children. A binary tree is restricted to only having 0, 1, or 2 children. A complete binary tree is one where all the levels are full with exception to the last level and it is filled from left to right. A full binary tree is one where if a node has a child, then it has two children.

For all the nonempty binary trees whose nonterminal node have exactly two nonempty children, the number of leaves m is greater than the number of nonterminal node k and m = k + 1.

A binary search tree (BST) is a binary tree that has the following property: For each node n of the tree, all values stored in its left subtree are less than value v stored in n, and all values stored in the right subtree are greater than v. This definition excludes the case of duplicates. They can be include and would be put in the right subtree.

A traversal is where each node in a tree is visited and visited once For a tree of n nodes there are n! traversals Of course most of those are hard to program There are two very common traversals

Breadth First

In a breadth first traversal all of the nodes on a given level are visited and then all of the nodes on the next level are visited. Usually in a left to right fashion This is implemented with a queue

Depth First

In a depth first traversal all the nodes on a branch are visited before any others are visited There are three common depth first traversals

Insertion

In order to build a tree you must be able to insert into the tree In order to do this you need to know where the nodes goes Typically the tree is searched looking for a null pointer to hang the new element from There are two common ways to do this Use a look ahead or check for null as the first line in the code

More insertion

I prefer to check for null as the first thing I do in my code It simplifies some of the tests And makes for a really easy to check for base case

Code

InsertionHelper( Node *n, T data ) { if ( node == 0 ) return new Node( data ); if ( n->getData() < data ) setLeft( InsertionHelper( n->getLeft(), data); else setRight( InsertionHelper( n->getRight(), data); }

Deletion

Deletion poses a bigger problem When we delete we normally have two choices Deletion by merging Deletion by copying

Deletion by Merging

Deletion by merging takes two subtrees and merges them together into one tree The idea is you have a node n to delete N can have two children So you find the smallest element in ns left subtree You then take ns right subtree and merge it to the bottom of the left subtree The root of the left subtree replaces n

Deletion by copying

This will simply swap values and reduce a difficult case to an easier one If the node n to be deleted has no children,

easy blow it away Easy simply pass ns child pointer up, make ns parent point to ns child and blow n away Now we have deletion by copying

Details

We find the smallest value in ns right subtree We will take the value from that node and put it in place of the value in n We will then blow away the node that had the smallest value in it

- Basic of TreesUploaded byRAJENDRAN
- RTUtil User's Guide Release 9_V013Uploaded byMinh Dương
- Optimal Binary Search TreeUploaded byCá Chép Nhỏ
- Unfolded InsertUploaded bydignor.sign3941
- Using Decision Tree for Automatic Identification of Bengali Noun-Noun CompoundsUploaded byidescitation
- Question for GateUploaded byrajveerchoudharymca
- AI_Lab-3Uploaded byDil Prasad Kunwar
- binary tree 2Uploaded bySiu Chung Mok
- Ds ObjectiveUploaded byAnamika Chauhan Verma
- Self AdjustingUploaded byNarendra Dev
- Oracle PACUploaded byRamesh Foru
- Optimal Binary Search TreeUploaded byঅনীক সাহা জন
- LDML - Application public releaseUploaded bySean DerSchaf Con
- DS set 3Uploaded bySudhanshu Singh
- AVL treeUploaded byVishnu Prasad Goranthala
- binary java1.docxUploaded byKaran Khanchandani
- Data Warehousing and Mining - Exam SolutionsUploaded byuserscrybd
- C quizUploaded bySubasi66
- AP16_06Uploaded byParmesh
- ClassUploaded bytrung
- Indoor Outdoor Integration User GuideUploaded byRadiah Hamdah
- 65zxzxUploaded byShubham Dubey
- manual.pdfUploaded byDylan Kreiser
- Binary Search Tree AlgorithmUploaded byMalathi Sankar
- TreeUploaded bysumit
- 131612-2130702-DS dec 2016Uploaded byDhruval Shah
- ParamicsV4-ProcessorUserManualUploaded byFarhan
- Cs2201 Ds Question Bank-ActUploaded byactvenkatesan
- Chap10 TreesUploaded byAiman Afzam
- AVLTreeExample.pdfUploaded bysudhan

- ZedBoard GSwEL GuideUploaded byvaibhawamishra32
- VENKAT DB BANK PROJECT.pdfUploaded byJavvaji Venkat
- GDC Tech Bulletin Hard Drive Diagnostics v2Uploaded byguerrero
- LectureUploaded bygyadav_26
- 11.2.4.7 Lab - Examining Telnet and SSH in Wireshark - ILMUploaded byKevin Kim
- HowTo Backup Restore WCM Server3.0-3.2Uploaded byApri Budi
- Tableau Desktop 10.1Uploaded byShinny123
- Ha400 Epm Hana View s1Uploaded byreddy
- Java BasicsUploaded bysunny sammy
- Slim Framework DocumentationUploaded byferb_01
- 12 Informatics Practices Sample Papers 2010 2Uploaded byVr Magesh
- a96571Uploaded byhiiam6c
- Hitachi Universal Replicator - HUR Step-By-step ConfigUploaded bySahatma Siallagan
- Getting a Loan ApprovalUploaded byRiSHI KeSH GawaI
- 8096 Microcontrollers Notes safUploaded byRakesh Kumar D
- Sunbird Ppt 19AprilUploaded byJean Bonaparte
- QGIS-Splitter.pdfUploaded bySyafruddin Rauf
- Upgradation to oracle 9.2.0.7/9.2.0.8Uploaded byRahul Gupta
- acnUploaded bySandeep Reddy Dasani
- Atos-nt Rev 5-6-10Uploaded byalessandro
- Prabha AbstractUploaded byBazith
- Oracle Data PumpUploaded bydbareddy
- Basic of ComputerUploaded byChadaram Hemchand
- TSM for LINUX Installation Guide V6.1Uploaded byMaestroo89
- Luxand FaceSDK DocumentationUploaded byFrancisco Raúl Delgado
- Itd102 Final ProjectUploaded byjocansino4496
- Boot Ubuntu From UsbUploaded bynotche
- OracleUploaded bykhan
- Integrate AD with OIDUploaded byrepakulakishore
- Startup_sUploaded byAbhay Tomar