1. DATA STRUCTURESDEF:DS is a collection oforganized data that are related toeach other.
2. DATA STRUCTURES LINEAR DS NON-LINEARSTACKS 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 ELEFT 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. 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.
8. 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…………….
9. 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
10. 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.
11. 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
12. 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
13. 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
14. 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. n1In fig2 n2 is the son of ‘b’ where bB is the descendent of n1 the n2 is son of descendent of n1 n2Then n2 is descendent of n1.
15. Brother Nodes Two nodes are said to be brothers if they ae left and right sons of the same father node A B C
16. 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.
17. 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.
18. 1 2 3 5 6 7 4 10 11 128 9
19. 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.
20. 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.
21. 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.
22. A B C F G HE A B C D E F
23. 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
24. 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
25. LEVEL 0 A LEVEL 1 B C LEVEL 2 D ELEVEL3 E
26. 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
27. LEVEL:4 DEPTH=4 Depth always equals to length of longest path from root to leaves
28. Complete BTree A complete Btree of Depth “D” is a strict Btree whose all leaf nodes must exist at level”D”.
29. REPRESENTATION OF B TREE USING ARRAYS
30. 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].
31. 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+2CIS 068
32. Sequential   A  B Representation   C (1) waste space A  A  (2) insertion/deletion  B  D problem  --  B   E  C A  -- F  -- H C   -- B I C D . D  -- . E D E F GE H I
33. REPRESENTATION OF B TREE USING LINKED LIST
34. Data Structures: APseudocode Approachwith C 36
35. Operations on BTThere are 3 important operations on BT. Insertion Deletion Searching