• Home
  • University of the People
  • Data Structures (proctored course) CS 3303
  • Binary Trees and Data Structures

Binary Trees and Data Structures

CS 3303 Data Structure Unit 4 Discussion Assignment QUESTION: In your own words, provide a de nition of a binary tree and discuss its' implementation. Include in your discussion the following terminology: Root, Node, Sub-Tree, Height, Depth, and Leaf. ANSWER: Look at these two words "Binary and Tree", The term Binary refers to any digital encoding/decoding system in which there are precisely two conceivable states, in other words, a numbering structure in which there are only two possible values for each digit: 0 and 1. While the term "Tree" is a nonlinear hierarchical data structure that comprises of nodes linked by edges. So, Binary Trees: is made up of a limited set of elements or data called nodes. Likewise a binary tree is a tree data structure in which each parent node can have at most two children. Binary suggests that 'two'; therefore each node have either 0, 1 or 2 children. And each node of a binary tree consists of three items, Data item (Root) Address of left child Address of right child of left chilc TYPES OF BINARY TREE 1) Full Binary Tress: This is a unique sort of binary tree in which each parent/internal node has two or no children, to say each node must contain 2 children except the leaf nodes The full binary tree is also known to be strict binary tree Example of Full Binary Tree 2) Perfect Binary Type: Each internal node has precisely two nodes and all the leaf nodes are at them level. Perfect Binary Tree 3) Complete Binary Tree: This type of binary tree has some attributes as the full binary tree, except that in a complete binary tree, every level must be completely filled, all the leaf elements must lean towards the left, and the last leaf element might not have a right sibling. That is to say, a complete binary tree doesn't have to be a full binary tree. Complete Binary Tree Other types of Binary Tree are: (4) Degenerate or Pathological Tree, (5) Skewed Binary Tree and (6) Balancanced Binary Tree. A sub-tree has its personal leaf (respective nodes), and this is known as the heat level down from the root node. We can determine the height of the tree by counting from the root to the base of the tree, which is the lowest depth. For successful tree implementation, the starting point is a single root node and it can be extended with nodes,the highest number of nodes is 3 (0,1 or 2). There are two ways to transverse a tree, it can either be depth-first or breadth-first. In depth-first transversal, the parent will be visited first, then the left and right children's nodes. It has to be in Ieft-to-right order, the left child first and then the right, or it can also be the left child first, then the right child and their parent. This is called a post-order. And in breadth-first transversal, it has only one way of traversing, it visits all the nodes