×

Close

- Data Structure and Algorithms - DSA
- Note
**28 Views**- Uploaded 10 months ago

CHAPTER—6 2 MARKS 1.Define general tree. How it is different from Binary tree? 2012(w) AnsGeneral Tree Binary Tree 1. A general tree is a data structure in that each node can have infinite number of children, 2. A General tree can’t be empty. 3. There is no limit on the degree of node in a general tree. 1. A Binary tree is a data structure in that each node has at most two nodes left and right. 2. A Binary tree can be empty. 3. Nodes in a binary tree cannot have more than degree 2. 2. 2.Define binary tree. 2017(s),2015(w),2014(bp) Ans-A binary tree is a finite set of nodes which is either empty or consists of a root and two disjoint binary trees called the left subtree and the right subtree. -> A Binary tree can be empty. -> Nodes in a binary tree cannot have more than degree 2. ->In binary tree, root have in-degree 0 and maximum out-degree 2. ->In binary tree, each node have in-degree one and maximum out-degree 2. 3. Define binary search tree(BST). 2012(w),2014(w),2013(w),2015 Ans-A binary search tree (BST), sometimes also called an ordered or sorted binary tree, is a node-based binary tree data structure, where each node has a comparable key • The left subtree of a node contains only nodes with keys less than the node's key. • The right subtree of a node contains only nodes with keys greater than the node's key. • The left and right subtree each must also be a binary search tree. • Each node can have up to two successor nodes. • There must be no duplicate nodes. • A unique path exists from the root to every other node

5 MARKS 1. What do you mean by tree traversal? Explain different traversal . 2014(w),2015(w) Ans- Tree traversal (also known as tree search) is refers to the process of visiting (checking and/or updating) each node in a tree data structure, exactly once. There are three commonly used patterns to visit all the nodes in a tree. The difference between these patterns is the order in which each node is visited. The three traversals we will look at are called preorder, inorder, and postorder Inorder traversal 1. Traverse the left subtree, i.e., call Inorder(left-subtree) 2. Visit the root. 3. Traverse the right subtree, i.e., call Inorder(right-subtree Uses of Inorder In case of binary search trees (BST), Inorder traversal gives nodes in non-decreasing order. To get nodes of BST in non-increasing order, a variation of Inorder traversal where Inorder itraversal s reversed, can be used. preorder traversal 1. Visit the root. 2. Traverse the left subtree, i.e., call Preorder(left-subtree) 3. Traverse the right subtree, i.e., call Preorder(right-subtree) Uses of Preorder Preorder traversal is also used to get prefix expression on of an expression tree. preorder traversal 1. Traverse the left subtree, i.e., call Postorder(left-subtree) 2. Traverse the right subtree, i.e., call Postorder(right-subtree) 3. Visit the root. Uses of Postorder Postorder traversal is useful to get the postfix expression of an expression tree. 2.Consider the tree T.list the nodes of the tree T in a) Preorder b)inorder c)postorder 2013(w),2015(w)

Ans-preorderInorderPostorder- 7 MARKS 1. What do you mean by BSt?How insertion and deletion takes place in a BST?Draw a BST with following data. 50,33,44,22,77,35,60,40,90,30. 2014(w),2017(s) Ans- A binary search tree (BST), also known as an ordered binary tree, is a node-based data structure in which each node has no more than two child nodes. The left sub-tree contains only nodes with keys less than the parent node; the right sub-tree contains only nodes with keys greater than the parent node. Insertion 1.Always insert new node as leaf node 2. Start at root node as current node 3. If new node‘s key < current‘s key a. If current node has a left child, search left b. Else add new node as current‘s left child 4. If new node‘s key > current‘s key a. If current node has a right child, search right b. Else add new node as current‘s right child Deletion Basically, in can be divided into two stages: • search for a node to remove; • if the node is found, run remove algorithm. 1. Node to be removed has no children. Algorithm sets corresponding link of the parent to NULL and disposes the node 2. Explain how BST is different from binary tree?Explain how insertion and deletion takes place in BST with suitable example. 2015(w)

## Leave your Comments