SlideShare una empresa de Scribd logo
1 de 37
DATA STRUCTURES

DEF:DS is a collection of
organized data that are related to
each other.
DATA STRUCTURES




     LINEAR DS                          NON-LINEAR




STACKS           QUEUES   LINKED LIST
                                          TREES      GRAPHS
TREES
 DEF:A TREE IS A SET OF NODES AND LINKS
 BINARY TREE:A BINARY TREE IS A FINITE SET OF ELEMENTS
  THAT IS EITHER EMPTY OR PARTITIONED INTO 3 DISJOINT
  SUBSETS .
 THE 1ST SUBSET CONTAINS A SINGLE ELEMENT CALLED AS
  “ROOT OF THE BINARY TREE”.THE OTHER TWO SUBSETS ARE
  THEMSELVES TREES CALLED LEFT AND RIGHT SUBTREES OF
  THE ORIGINAL TREE.
 EACH ELEMENT OF THE BINARY TREE IS CALLED “NODE” OF
  THE BINARY TREE.
A


          B                C



  D                    F           G
               E




LEFT SUBTREE
                           RIGHT SUBTREE
 In the above example A is the root node of
  the tree and B is the root of the left sub tree
  and C is the root of the right subtree.
 Then A is called as father of B and C.
 Where B is the left son of A and C is the
  right son of A.
TREE BASICS
   Number of nodes
   Height
   Root Node
   Leaves
   Interior nodes
   Number of levels
   Ancestors of H
   Descendants of B
   Siblings of E
   Right subtree
SIBLING
 If N is a node In T that has left sub tree S1,
  and a right sub tree S2, then N is called as
  the parent of the S1& S2
 So S1 &S2 are called siblings.
LEVEL NUMBER
 Every node in a tree is assigned a level
  number.
 The root is defined at level 0
 The left and right child of root node has
  level n0.1 and so on…………….
DEGREE
 The degree of the node is equal to the num
   ber of children that a node has.
     for eg: the degree of root node A is 2
IN DEGREE AND OUT DEGREE
 In in-degree of a node is the number of
  edges arriving at that node.
      for eg: the root node is the only node that
  has an in-degree 0.
 Similarly the out degree of a node is the
  number of edges that leaving the node.
Leaf(or)Leaf Node or Terminal node
 A “Node” that has no sons is called as “leaf
  node”
 In the above fig D,E,F&G are the leaf nodes
 Where A,B,C are the non leaf nodes

                           A


                   B                C



                       LEAF NODES
ANCESTOR
 A Node ‘n1’ is an ancestor of node ‘n2’ if
  ‘n1’ is neither father of ‘n2’(or) father of
  some ancestor of ‘n2’.              n1


                                         n2
                   n1


                             B



                        n2
 In the above fig 1 ‘n1’ is the father of ‘n2’ so
  directly we call ‘n1 as ancestor of ‘n2’
 In fig2 there is no direct relation ship b/w n1
  and n2 even though n1 Is the father of B
  where b is the father of n2 then we call n1
  as father of ancestor of ‘n2’ so n1 become
  ancestor of n2
Descendent
 A node ‘n2 is descendent of ‘n1’if ‘n2 is son
  of ‘n1’                              n1
 In the above fig directly n2 is the
                                             n2
 son of n1.
                                      n1
In fig2 n2 is the son of ‘b’ where
                                              b
B is the descendent of n1 the n2 is son of
  descendent of n1                        n2
Then n2 is descendent of n1.
Brother Nodes
 Two nodes are said to be brothers if they ae
  left and right sons of the same father node

                                   A




                            B              C
 The direction of travelling from roots to
  leaves is “down” and the travelling from
  leaves to root is up.
 Moving from leaves is known as “climbing”
 And moving from roots to leaves is also
  known as descending.
BINARY TREE
 A binary tree is a non-linear data structure
  which is defined as collection of elements
  called nodes.
 Every node has left pointer and right pointer
  and the data element.
 Every binary tree has a root node which is
  the top most node in the tree.
 If root is equal to null then the tree is empty.
1


            2                 3


                5        6        7
    4

                    10       11       12
8
        9
 In the above figure, node-2 is the left
  successor and node-3 is the right succesor
 Note that the left sub-tree of the root node
  consists of nodes-2,4,5,8,and 9. and right
  sub-tree consists of nodes-3,6,7,10,11,12
 The leaf nodes are 5,8,9,10,11,12.
Properties of BinaryTree
 Property1:A tree with ‘n’ nodes has exactly
  n-1 edges or branches.
 Property2:In a tree every node except the
  root has exactly 1 parent
 Property3:There is exactly one path
  connecting any 2 nodes in a tree.
 Property4:the max no of nodes in a binary
  tree of height k is 2k+1 -1 (k>=0)
 Property5:Btree with n internal nodes has
  n+1 external nodes.
Strict Binary Tree
 If every non leaf node in the binary tree
  having non empty left and right sub trees
  then it is known as strict binary trees
 In a binary tree if every non-leaf node
  having both left and right sons then it is
  called as strict binary tree.
A


        B                       C


                F           G           H
E




                    A
    B                           C

                    D               E

            F
 In the above fig1 is a strict binary tree where
  as fig2 is not because the non leaf node D
  having only leftson ‘F’ it doesnot have right
  son.
 So in a strict binary tree with n leaves totally
  we have (2n-1) nodes.
 Ie from the above fig we have 4 leaf nodes
  the n we have (2*4-1)=7
Level of the node:
 The level of the node in a binary tree is
  defined as follows.
 The root of the binary tree always having
  level ’0’ and the level of any other node is
  one more that its father node.
 Level of a node=1+its father node level
LEVEL 0
               A



                                     LEVEL 1
 B                     C




     LEVEL 2       D             E




LEVEL3         E
DEPTH OF BT
 The depth of bt is the max level of any leaf
  node in that tree.         A
                                        LEVEL0

                                               LEVEL1
                          B               C


                     LEVEL2       D                E


                 LEVEL3       F



                                      G   LEVEL4
   LEVEL:4
   DEPTH=4
   Depth always equals to length of longest
    path from root to leaves
Complete BTree
 A complete Btree of Depth “D” is a strict
  Btree whose all leaf nodes must exist at
  level”D”.
REPRESENTATION OF B TREE
     USING ARRAYS
 Suppose T is a Binary tree that is complete.
  there is an efficient way of maintaining T
  in memory called Sequential representation
  of T.
The representation uses only a single linear
  array tree as follows.
a)The root R of tree T is stored in Tree[i]
b)If a node N occupies Tree[K],then the left
  child is stored in Tree[2k+1] and right child
  is stored in Tree[2k+2].

                    Complete trees in arrays:
              Storage of complete
                                  Trees
                                   0
                                  1 2
                                3 4 5 6
                            7 8



                    …


          0     1       2   3      4      5   6   7    8


                            k=3                   2k+1, 2k+2

CIS 068
Sequential                                                   [1]
                                                                 [2]
                                                                       A

                                                                 [3]   B
    Representation                                               [4]
                                                                 [5]   C
                                    (1) waste space
                A   [1]    A                                     [6]
                                    (2) insertion/deletion
                    [2]    B                                     [7]   D
                                        problem
                    [3]    --                                    [8]
            B       [4]                                          [9]   E
                    [5]    C
                                                  A
                    [6]    --                                          F
                    [7]    --                                          H
        C
                    [8]
                    [9]    --           B                              I
                                                             C
    D               .      D
                    [16]   --
                           .
                           E        D        E        F            G
E



                                H        I
REPRESENTATION OF B TREE
    USING LINKED LIST
Data Structures: A
Pseudocode Approach
with C                36
Operations on BT

There are 3 important operations
             on BT.
            Insertion
            Deletion
           Searching

Más contenido relacionado

Similar a Data structures

Similar a Data structures (20)

Lecture 8 data structures and algorithms
Lecture 8 data structures and algorithmsLecture 8 data structures and algorithms
Lecture 8 data structures and algorithms
 
non linear data structure -introduction of tree
non linear data structure -introduction of treenon linear data structure -introduction of tree
non linear data structure -introduction of tree
 
binary tree.pptx
binary tree.pptxbinary tree.pptx
binary tree.pptx
 
Lecture-7-Binary-Trees-and-Algorithms-11052023-054009pm.pptx
Lecture-7-Binary-Trees-and-Algorithms-11052023-054009pm.pptxLecture-7-Binary-Trees-and-Algorithms-11052023-054009pm.pptx
Lecture-7-Binary-Trees-and-Algorithms-11052023-054009pm.pptx
 
Unit 6 tree
Unit   6 treeUnit   6 tree
Unit 6 tree
 
Unit – vi tree
Unit – vi   treeUnit – vi   tree
Unit – vi tree
 
7.tree
7.tree7.tree
7.tree
 
07 trees
07 trees07 trees
07 trees
 
Tree
TreeTree
Tree
 
Tree terminology and introduction to binary tree
Tree terminology and introduction to binary treeTree terminology and introduction to binary tree
Tree terminology and introduction to binary tree
 
09 binary-trees
09 binary-trees09 binary-trees
09 binary-trees
 
Trees
TreesTrees
Trees
 
Data structure using c module 2
Data structure using c module 2Data structure using c module 2
Data structure using c module 2
 
Unit 3.ppt
Unit 3.pptUnit 3.ppt
Unit 3.ppt
 
Chapter 5_Trees.pdf
Chapter 5_Trees.pdfChapter 5_Trees.pdf
Chapter 5_Trees.pdf
 
Lecture 5 tree.pptx
Lecture 5 tree.pptxLecture 5 tree.pptx
Lecture 5 tree.pptx
 
Tree and Binary Search tree
Tree and Binary Search treeTree and Binary Search tree
Tree and Binary Search tree
 
Chapter 8 ds
Chapter 8 dsChapter 8 ds
Chapter 8 ds
 
Tree
TreeTree
Tree
 
Trees in Data Structure
Trees in Data StructureTrees in Data Structure
Trees in Data Structure
 

Más de IIUI

Rank brain
Rank brainRank brain
Rank brainIIUI
 
Chapter 10 cs 2o-p
Chapter 10 cs 2o-pChapter 10 cs 2o-p
Chapter 10 cs 2o-pIIUI
 
Chapter 09 io devices 3o-p
Chapter 09 io devices 3o-pChapter 09 io devices 3o-p
Chapter 09 io devices 3o-pIIUI
 
Chapter 09 io devices 2o-p
Chapter 09 io devices 2o-pChapter 09 io devices 2o-p
Chapter 09 io devices 2o-pIIUI
 
Chapter 09 io devices
Chapter 09 io devicesChapter 09 io devices
Chapter 09 io devicesIIUI
 
Chapter 08 secondary storage 3o-p
Chapter 08 secondary storage 3o-pChapter 08 secondary storage 3o-p
Chapter 08 secondary storage 3o-pIIUI
 
Chapter 08 secondary storage 2o-p
Chapter 08 secondary storage 2o-pChapter 08 secondary storage 2o-p
Chapter 08 secondary storage 2o-pIIUI
 
Chapter 08 secondary storage
Chapter 08 secondary storageChapter 08 secondary storage
Chapter 08 secondary storageIIUI
 
Chapter 07 pam 3o-p
Chapter 07 pam 3o-pChapter 07 pam 3o-p
Chapter 07 pam 3o-pIIUI
 
Chapter 07 pam 2o-p
Chapter 07 pam 2o-pChapter 07 pam 2o-p
Chapter 07 pam 2o-pIIUI
 
Chapter 07 pam
Chapter 07 pamChapter 07 pam
Chapter 07 pamIIUI
 
Chapter 06 boolean algebra 3o-p
Chapter 06 boolean algebra 3o-pChapter 06 boolean algebra 3o-p
Chapter 06 boolean algebra 3o-pIIUI
 
Chapter 06 boolean algebra 2o-p
Chapter 06 boolean algebra 2o-pChapter 06 boolean algebra 2o-p
Chapter 06 boolean algebra 2o-pIIUI
 
Chapter 06 boolean algebra
Chapter 06 boolean algebraChapter 06 boolean algebra
Chapter 06 boolean algebraIIUI
 
Chapter 05 computer arithmetic 2o-p
Chapter 05 computer arithmetic 2o-pChapter 05 computer arithmetic 2o-p
Chapter 05 computer arithmetic 2o-pIIUI
 
Chapter 05 computer arithmetic
Chapter 05 computer arithmeticChapter 05 computer arithmetic
Chapter 05 computer arithmeticIIUI
 
Chapter 04 computer codes 3o-p
Chapter 04 computer codes 3o-pChapter 04 computer codes 3o-p
Chapter 04 computer codes 3o-pIIUI
 
Chapter 04 computer codes
Chapter 04 computer codesChapter 04 computer codes
Chapter 04 computer codesIIUI
 
Chapter 03 number system 3o-p
Chapter 03 number system 3o-pChapter 03 number system 3o-p
Chapter 03 number system 3o-pIIUI
 
Chapter 03 number system 2o-p
Chapter 03 number system 2o-pChapter 03 number system 2o-p
Chapter 03 number system 2o-pIIUI
 

Más de IIUI (20)

Rank brain
Rank brainRank brain
Rank brain
 
Chapter 10 cs 2o-p
Chapter 10 cs 2o-pChapter 10 cs 2o-p
Chapter 10 cs 2o-p
 
Chapter 09 io devices 3o-p
Chapter 09 io devices 3o-pChapter 09 io devices 3o-p
Chapter 09 io devices 3o-p
 
Chapter 09 io devices 2o-p
Chapter 09 io devices 2o-pChapter 09 io devices 2o-p
Chapter 09 io devices 2o-p
 
Chapter 09 io devices
Chapter 09 io devicesChapter 09 io devices
Chapter 09 io devices
 
Chapter 08 secondary storage 3o-p
Chapter 08 secondary storage 3o-pChapter 08 secondary storage 3o-p
Chapter 08 secondary storage 3o-p
 
Chapter 08 secondary storage 2o-p
Chapter 08 secondary storage 2o-pChapter 08 secondary storage 2o-p
Chapter 08 secondary storage 2o-p
 
Chapter 08 secondary storage
Chapter 08 secondary storageChapter 08 secondary storage
Chapter 08 secondary storage
 
Chapter 07 pam 3o-p
Chapter 07 pam 3o-pChapter 07 pam 3o-p
Chapter 07 pam 3o-p
 
Chapter 07 pam 2o-p
Chapter 07 pam 2o-pChapter 07 pam 2o-p
Chapter 07 pam 2o-p
 
Chapter 07 pam
Chapter 07 pamChapter 07 pam
Chapter 07 pam
 
Chapter 06 boolean algebra 3o-p
Chapter 06 boolean algebra 3o-pChapter 06 boolean algebra 3o-p
Chapter 06 boolean algebra 3o-p
 
Chapter 06 boolean algebra 2o-p
Chapter 06 boolean algebra 2o-pChapter 06 boolean algebra 2o-p
Chapter 06 boolean algebra 2o-p
 
Chapter 06 boolean algebra
Chapter 06 boolean algebraChapter 06 boolean algebra
Chapter 06 boolean algebra
 
Chapter 05 computer arithmetic 2o-p
Chapter 05 computer arithmetic 2o-pChapter 05 computer arithmetic 2o-p
Chapter 05 computer arithmetic 2o-p
 
Chapter 05 computer arithmetic
Chapter 05 computer arithmeticChapter 05 computer arithmetic
Chapter 05 computer arithmetic
 
Chapter 04 computer codes 3o-p
Chapter 04 computer codes 3o-pChapter 04 computer codes 3o-p
Chapter 04 computer codes 3o-p
 
Chapter 04 computer codes
Chapter 04 computer codesChapter 04 computer codes
Chapter 04 computer codes
 
Chapter 03 number system 3o-p
Chapter 03 number system 3o-pChapter 03 number system 3o-p
Chapter 03 number system 3o-p
 
Chapter 03 number system 2o-p
Chapter 03 number system 2o-pChapter 03 number system 2o-p
Chapter 03 number system 2o-p
 

Último

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 

Último (20)

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 

Data structures

  • 1. DATA STRUCTURES DEF:DS is a collection of organized data that are related to each other.
  • 2. DATA STRUCTURES LINEAR DS NON-LINEAR STACKS QUEUES LINKED LIST TREES GRAPHS
  • 3. TREES  DEF:A TREE IS A SET OF NODES AND LINKS  BINARY TREE:A BINARY TREE IS A FINITE SET OF ELEMENTS THAT IS EITHER EMPTY OR PARTITIONED INTO 3 DISJOINT SUBSETS .  THE 1ST SUBSET CONTAINS A SINGLE ELEMENT CALLED AS “ROOT OF THE BINARY TREE”.THE OTHER TWO SUBSETS ARE THEMSELVES TREES CALLED LEFT AND RIGHT SUBTREES OF THE ORIGINAL TREE.  EACH ELEMENT OF THE BINARY TREE IS CALLED “NODE” OF THE BINARY TREE.
  • 4. A B C D F G E LEFT SUBTREE RIGHT SUBTREE
  • 5.  In the above example A is the root node of the tree and B is the root of the left sub tree and C is the root of the right subtree.  Then A is called as father of B and C.  Where B is the left son of A and C is the right son of A.
  • 6. TREE BASICS  Number of nodes  Height  Root Node  Leaves  Interior nodes  Number of levels  Ancestors of H  Descendants of B  Siblings of E  Right subtree
  • 7.
  • 8. SIBLING  If N is a node In T that has left sub tree S1, and a right sub tree S2, then N is called as the parent of the S1& S2  So S1 &S2 are called siblings.
  • 9. LEVEL NUMBER  Every node in a tree is assigned a level number.  The root is defined at level 0  The left and right child of root node has level n0.1 and so on…………….
  • 10. DEGREE  The degree of the node is equal to the num ber of children that a node has. for eg: the degree of root node A is 2
  • 11. IN DEGREE AND OUT DEGREE  In in-degree of a node is the number of edges arriving at that node. for eg: the root node is the only node that has an in-degree 0.  Similarly the out degree of a node is the number of edges that leaving the node.
  • 12. Leaf(or)Leaf Node or Terminal node  A “Node” that has no sons is called as “leaf node”  In the above fig D,E,F&G are the leaf nodes  Where A,B,C are the non leaf nodes A B C LEAF NODES
  • 13. ANCESTOR  A Node ‘n1’ is an ancestor of node ‘n2’ if ‘n1’ is neither father of ‘n2’(or) father of some ancestor of ‘n2’. n1 n2 n1 B n2
  • 14.  In the above fig 1 ‘n1’ is the father of ‘n2’ so directly we call ‘n1 as ancestor of ‘n2’  In fig2 there is no direct relation ship b/w n1 and n2 even though n1 Is the father of B where b is the father of n2 then we call n1 as father of ancestor of ‘n2’ so n1 become ancestor of n2
  • 15. Descendent  A node ‘n2 is descendent of ‘n1’if ‘n2 is son of ‘n1’ n1  In the above fig directly n2 is the n2 son of n1. n1 In fig2 n2 is the son of ‘b’ where b B is the descendent of n1 the n2 is son of descendent of n1 n2 Then n2 is descendent of n1.
  • 16. Brother Nodes  Two nodes are said to be brothers if they ae left and right sons of the same father node A B C
  • 17.  The direction of travelling from roots to leaves is “down” and the travelling from leaves to root is up.  Moving from leaves is known as “climbing”  And moving from roots to leaves is also known as descending.
  • 18. BINARY TREE  A binary tree is a non-linear data structure which is defined as collection of elements called nodes.  Every node has left pointer and right pointer and the data element.  Every binary tree has a root node which is the top most node in the tree.  If root is equal to null then the tree is empty.
  • 19. 1 2 3 5 6 7 4 10 11 12 8 9
  • 20.  In the above figure, node-2 is the left successor and node-3 is the right succesor  Note that the left sub-tree of the root node consists of nodes-2,4,5,8,and 9. and right sub-tree consists of nodes-3,6,7,10,11,12  The leaf nodes are 5,8,9,10,11,12.
  • 21. Properties of BinaryTree  Property1:A tree with ‘n’ nodes has exactly n-1 edges or branches.  Property2:In a tree every node except the root has exactly 1 parent  Property3:There is exactly one path connecting any 2 nodes in a tree.  Property4:the max no of nodes in a binary tree of height k is 2k+1 -1 (k>=0)  Property5:Btree with n internal nodes has n+1 external nodes.
  • 22. Strict Binary Tree  If every non leaf node in the binary tree having non empty left and right sub trees then it is known as strict binary trees  In a binary tree if every non-leaf node having both left and right sons then it is called as strict binary tree.
  • 23. A B C F G H E A B C D E F
  • 24.  In the above fig1 is a strict binary tree where as fig2 is not because the non leaf node D having only leftson ‘F’ it doesnot have right son.  So in a strict binary tree with n leaves totally we have (2n-1) nodes.  Ie from the above fig we have 4 leaf nodes the n we have (2*4-1)=7
  • 25. Level of the node:  The level of the node in a binary tree is defined as follows.  The root of the binary tree always having level ’0’ and the level of any other node is one more that its father node.  Level of a node=1+its father node level
  • 26. LEVEL 0 A LEVEL 1 B C LEVEL 2 D E LEVEL3 E
  • 27. DEPTH OF BT  The depth of bt is the max level of any leaf node in that tree. A LEVEL0 LEVEL1 B C LEVEL2 D E LEVEL3 F G LEVEL4
  • 28. LEVEL:4  DEPTH=4  Depth always equals to length of longest path from root to leaves
  • 29. Complete BTree  A complete Btree of Depth “D” is a strict Btree whose all leaf nodes must exist at level”D”.
  • 30. REPRESENTATION OF B TREE USING ARRAYS
  • 31.  Suppose T is a Binary tree that is complete. there is an efficient way of maintaining T in memory called Sequential representation of T. The representation uses only a single linear array tree as follows. a)The root R of tree T is stored in Tree[i] b)If a node N occupies Tree[K],then the left child is stored in Tree[2k+1] and right child is stored in Tree[2k+2].
  • 32. Complete trees in arrays: Storage of complete Trees 0 1 2 3 4 5 6 7 8 … 0 1 2 3 4 5 6 7 8 k=3 2k+1, 2k+2 CIS 068
  • 33. Sequential [1] [2] A [3] B Representation [4] [5] C (1) waste space A [1] A [6] (2) insertion/deletion [2] B [7] D problem [3] -- [8] B [4] [9] E [5] C A [6] -- F [7] -- H C [8] [9] -- B I C D . D [16] -- . E D E F G E H I
  • 34. REPRESENTATION OF B TREE USING LINKED LIST
  • 35.
  • 36. Data Structures: A Pseudocode Approach with C 36
  • 37. Operations on BT There are 3 important operations on BT. Insertion Deletion Searching

Notas del editor

  1. de