4 views

Uploaded by catarac19

Data

- • Family Tree • Parse Trees
- Data Structure Mcq 1
- NVivo Manual Resumen
- README-1
- Datastructure Questions
- Binary.trees
- New Text Document
- Data Structure
- CS234F13TextSlidesCh14.1
- ds notes.docx
- L02-4up
- slides17-modular.pdf
- DS Assignment (2)
- Assignment 3
- Sample Question Paper Asstt Manager IT E05
- Short Online Q&A for DataStructure
- Java BasicADTs
- end_term_11-12
- Org Charts
- back-matter

You are on page 1of 24

Trees

Hierarchical data structure Each position in the tree is called a node The top of the tree is called the root The nodes immediately below a node are called its children; nodes with no children are called leaves (or terminal nodes), or terminal nodes, and the node above a given node is its parent (or father) A node x is ancestor of node y if x is father of y or father of some ancestor of y. y is called descendent of x. Ancestor of a node is its parent, grand parent or grand-grand parent or so on.

Nodes with the same parent are siblings A node plus the collection of nodes beneath it is called a subtree The number of nodes in the longest path from the root to a leaf is the depth (or height) of the tree

is the depth 2 or 3? depends on the author

Node H

Node I

Node J

Node K Node L

Nodes H and I are siblings C is Hs parent, H and I are children of C What is the depth of this tree?

Binary Trees

A commonly used type of tree is a binary tree Each node has at most two children The tree is a conceptual structure The data can be stored either in a dynamic linked tree structure, or in contiguous memory cells (array) according to a set pattern; in other words, implementation can be pointer-based or array-based

Binary trees

A tree is called strictly binary tree if every non leaf node has exactly two children. A strictly binary tree having n leaves always contain 2n-1 nodes Text book definition of depth of a tree

Depth of binary tree is maximum level of any leaf in the tree. Root of tree is at level 0, and level of any other node in the tree is one more than the level of its father

Binary Trees

A complete binary tree of level d is the strictly binary tree all of whose leaves are at level d A complete binary tree of level d has 2l nodes at each level l where 0<=l<=d Total number of nodes (tn) in a complete binary tree of depth d will be:

tn 2 2 2 2 2 j 2 d 1 1

0 1 2 d j 0 d

Binary Trees

For a complete binary tree if number of nodes (tn) are known, then we may find depth of the binary tree

tn 2 2

d 1

d 1

tn 1

A binary tree with nodes n has height O(log2n)

Linked List based implementation Array based implementation

Each node in the tree consists of:

The data, or value contained in the element A left child pointer (pointer to first child) A right child pointer (pointer to second child)

A root pointer points to the root node

Follow pointers to find every other element in the tree

Add and remove nodes by manipulating pointers Leaf nodes have child pointers set to null

class CBinTree { struct Node { int value; Node *LeftChild,*RightChild; }*Root; /***Operations*********/ /************************/ };

ROOT

Value in root node stored first, followed by left child, then right child Each successive level in the tree stored left to right; unused nodes in tree represented by a bit pattern to indicate nothing stored there Children of any given node n is stored in cells 2n and 2n + 1 (If array index starts at 1) Can calculate position for any given node Storage allocated as for full tree, even if many nodes empty For a tree of depth h we need array of 2h+1-1 cells

Binary Trees

Full binary tree of height (depth) h: all nodes at a height less than h have exactly two children Balanced binary tree: for each node, the difference in depth of the right and left subtrees is no more than one Completely balanced tree: left and right subtrees of every node have the same height

Primitive Operations

Left(node): Gives index/pointer of left child Right(node): Gives index/pointer of right child Parent(node): Returns index/pointer of parent Brother(node): Returns index/pointer of brother Root: Gives index/pointer of root node Info(Node): Data/Info stored at node IsLeft(node): Is node left child? Yes/No IsRight(node): Is node right child? Yes/No

Common Operations

Tree traversal Node addition Node deletion Destroy

Pass through all nodes of tree Inorder (symmetric traversal) Preorder (depth first traversal) Postorder

Trees Traversal

Inorder

(Left) Root (Right)

Root

Preorder

Root (Left) (Right)

Left

Right

Postorder

(Left) (Right) Root

Inorder Traversal

Left Root Right manner

* + +

(A*B)+(C*D+E)

Preorder Traversal

Root Left Right manner + Left Right + [*Left Right] [+Left Right] +(*AB) [+ *Left Right E] +*AB + *C D E

+ * +

Postorder Traversal

Left Right Root manner

* + +

Left Right + [Left Right *] [Left Right+] + (AB*) [Left Right * E + ]+ (AB*) [C D * E + ]+ AB* C D * E + +

Elements are sorted: For any node n in a binary search tree:

The value at n is greater than the values of any of the nodes in its left subtree The value at n is less than the values of any of the nodes in its right subtree Its left and right subtrees are binary search trees

Need to define greater than and less than for the specific data

- • Family Tree • Parse TreesUploaded byjnkumar
- Data Structure Mcq 1Uploaded byAnser Pasha
- NVivo Manual ResumenUploaded byEric Tornini Gonzalez
- README-1Uploaded bydrackner
- Datastructure QuestionsUploaded by7killers4u
- Binary.treesUploaded byAsafAhmad
- New Text DocumentUploaded byKrishna Kumar Chandravanshi
- Data StructureUploaded bymohit1485
- CS234F13TextSlidesCh14.1Uploaded byvzorleet
- ds notes.docxUploaded byuma s
- L02-4upUploaded byPopa Flavius
- slides17-modular.pdfUploaded by252966576
- DS Assignment (2)Uploaded byvithya
- Assignment 3Uploaded byjeremy
- Sample Question Paper Asstt Manager IT E05Uploaded byJay Prakash Patel
- Short Online Q&A for DataStructureUploaded byRavi Varma
- Java BasicADTsUploaded byOla
- end_term_11-12Uploaded byhisuin
- Org ChartsUploaded byReema Shah
- back-matterUploaded bysonara28
- Cs301 Exam QuestionsUploaded byPrince Islamabad
- 10.1.1.13.6228Uploaded byKhairul Annas
- DescriptionddUploaded byJacobKrupski
- Oracle Forms Developer Build Internet Applications 1-Volume 2 Instructor GuideUploaded bykaleonardo
- A2Uploaded byPrateek Sharma
- Algoritham QuestionsUploaded bysurendramdv
- acml09Uploaded byKevin Mondragon
- pdf_main.psUploaded byIsaiah Garcia
- DS CSLI AlmostFinalUploaded byeleni13121975
- ep portal ccmsUploaded bymoinuddin_5061573

- Contour LinesUploaded byAkshay D Nicator
- EustasyGuidishLercheKendallOBrian84.pdfUploaded bycatarac19
- EaES455txt.pptUploaded bycatarac19
- EaES455-7.pptUploaded bycatarac19
- EaES455-4.pptUploaded bycatarac19
- EaES455-12.pptUploaded bycatarac19
- Rafavich-Kendall-1984.pdfUploaded bycatarac19
- BasinEvaluationBurial.pdfUploaded bycatarac19
- The geology of stratigraphic sequences.pdfUploaded bycatarac19
- Earthquake SizeUploaded bycatarac19
- Channel sandstones.pdfUploaded bycatarac19
- Ancient Example of Beach SandstoneUploaded bycatarac19
- OutOfOurDepthBurtonKendallLerche87.pdfUploaded bycatarac19
- EaES455-6.pptUploaded bycatarac19
- Global Basin Classification-Kingston,Dishroon,WiiliamsUploaded byEugene Théõpháñy Ôthñîél Ûróró
- l09_zonation (5 days).pptUploaded bycatarac19
- L12_Log-Upscaling (5 Days)Uploaded bycatarac19
- L05_FaultModeling (5 days).pptUploaded bycatarac19
- Basin & Ranges.pptUploaded bycatarac19
- Lat-Long-To-XY-(WAA)Uploaded bycatarac19
- WGS_Stratigraphic Trap Classification.pdfUploaded bycatarac19
- l11_geometrical modeling (5 days).pptUploaded bycatarac19
- L10_Layering (5 Days)Uploaded bycatarac19
- SequStratCatuneanu02.pptUploaded bycatarac19
- L03_utilities_for-edit-of-input (5 days).pptUploaded bycatarac19
- L03_utilities_for-edit-of-input (5 days).pptUploaded bycatarac19
- L03_utilities_for-edit-of-input (5 days).pptUploaded bycatarac19
- L03_utilities_for-edit-of-input (5 days).pptUploaded bycatarac19
- ISSC Report on Sequence StratigraphyUploaded byTouseef Rehman
- L19_workflow (5 days).pptUploaded bycatarac19

- IJETR032314Uploaded byerpublication
- p717_chap01.pdfUploaded byByron Smith
- Weld Bead Geometry Control of Welds Made by Submerged Arc Welding: A ReviewUploaded byAdvanced Research Publications
- Distillation Steady-State MultiplicitiesUploaded byRosendo Monroy Loperena
- SMOLA 1998 - Nonlinear Component Analysis as a Kernel Eigenvalue Problem. Neural ComputationUploaded byDouglas Diniz Landim
- G-Factor (Physics) WikiUploaded bybugoff700
- 1dB Compression Point 20dBm 1dB Gain Change Saturated Output PowerUploaded byhummusian
- Xbc Dr10!14!20 30 e Data SheetUploaded byEdgar Bonetto
- A Treatise on the Adjustment of Observations (1884)Uploaded byMarcelo Silvano de Camargo
- Hirotugu Akaike - Wikipedia.pdfUploaded bystallone21
- Sensitive LPG Leakage AlarmUploaded bySrihari Thammisetti
- Diogo 2013 Technical NoteUploaded byLeonardo Flores Tymchuk
- Ecs-603 Compiler Design 2013-14Uploaded bySandeep Vishwakarma
- Fg 201701Uploaded byNeel Chakraborty
- varistorUploaded bySorryNOCI
- 6 OptiX OSN 1500 Hardware Description ISSUE 1.30Uploaded byRegina Paz
- BMW M3 and BMW M4 Press ReleaseUploaded byIndian Autos Blog
- Java prac2Uploaded byDrishya Pillai
- Explain About Push Pull Amplifier PDFUploaded byBraxton
- TLE 9 - Final ExamUploaded byNeilAndrewDomingo
- Module 13_ADC and DAC ProgrammingUploaded bynik ariff
- Spyglass CdcUploaded byRahul Sharma
- Smoke Rated DuctUploaded byBatak Ranau
- ASVAB Mechanical Comprehension Practice Test 4Uploaded byASVABTestBank
- 53 JNTUH Full Time Ph D in Engineering Under TEQIP II Programme Entrance Examination SyllabusUploaded byRalph Segundo Salvador
- Assignment (Form)1Uploaded byshuchita131
- RICM_61_23_0Uploaded byNedelcuGeorge
- Tech Appendix Mimolite 05may2015Uploaded byalanbrann
- The MotherboardUploaded byAko Si Dies Ü
- CFD Exercise #1_ Laminar Flow Through a PipeUploaded bykiran kumar g