28 Lecture

CS301

Midterm & Final Term Short Notes

Inorder traversal in threaded trees

Inorder traversal in threaded trees is a technique for traversing a threaded binary tree in the order of the inorder traversal without using recursion or a stack. In a threaded binary tree, each node has a left and right pointer, which point to


Important Mcq's
Midterm & Finalterm Prepration
Past papers included

Download PDF
  1. In threaded binary tree, a node that has no left child and whose left pointer points to the ___________. a) in-order predecessor b) in-order successor c) null d) none of the mentioned Answer: a

  2. What is a threaded binary tree? a) A binary tree in which each node can have any number of children b) A binary tree in which all the left pointers point to inorder predecessors and right pointers point to inorder successors. c) A binary tree in which each node can have at most 2 children d) A binary tree in which all the leaf nodes have a level of 0. Answer: b

  3. What is the time complexity for finding the inorder successor in a threaded binary tree? a) O(1) b) O(n) c) O(log n) d) O(n^2) Answer: a

  4. In which traversal, the nodes are visited in increasing order of their values? a) Inorder Traversal b) Preorder Traversal c) Postorder Traversal d) Level order Traversal Answer: a

  5. In threaded binary trees, the right pointer of a node points to its ____________. a) Predecessor b) Successor c) Ancestor d) Descendant Answer: b

  6. Which of the following is not true for threaded binary trees? a) In-order traversal can be performed in O(n) time complexity b) They save storage space c) They are more efficient than normal binary trees for finding in-order predecessors and successors. d) They allow for easy deletion of a node Answer: d

  7. Which of the following is a disadvantage of threaded binary trees? a) They take up more space than normal binary trees b) They are less efficient than normal binary trees for finding in-order predecessors and successors. c) They make deletion of a node difficult. d) They require extra memory space to store the thread pointers. Answer: d

  8. What is the main advantage of using threaded binary trees? a) They are easier to implement than normal binary trees b) They allow for efficient finding of in-order predecessors and successors c) They have a shorter height than normal binary trees d) They can store more data than normal binary trees Answer: b

  9. Which of the following is not a type of threaded binary tree? a) Single threaded binary tree b) Double threaded binary tree c) Circular threaded binary tree d) Quadruple threaded binary tree Answer: d

  10. Which of the following is not true for threaded binary trees? a) They are used for storing large amounts of data b) They allow for efficient traversal of the tree c) They can be used for faster searching of data d) They have a shorter height than normal binary trees. Answer: a



Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included

Download PDF
  1. What is a threaded binary tree? A threaded binary tree is a binary tree in which each node that does not have a right child has a threaded pointer to its successor in the inorder traversal.

  2. What is an inorder traversal? Inorder traversal is a way of visiting all the nodes in a binary tree. In this traversal, we first visit the left subtree of the root, then the root node itself, and finally, the right subtree of the root.

  3. What is a threaded inorder traversal? A threaded inorder traversal is a way of traversing a threaded binary tree. In this traversal, we use the threaded pointers to traverse the tree instead of recursion or a stack.

  4. How do we traverse a threaded binary tree using threaded inorder traversal? We start from the leftmost node of the tree and use the threaded pointer to visit the next node in the inorder sequence. We continue doing this until we reach the rightmost node of the tree.

  5. What is the advantage of using threaded binary trees? Using threaded binary trees reduces the amount of memory required to store a binary tree. It also speeds up the traversal of the tree, as we no longer need to use recursion or a stack to visit all the nodes.

  6. What is a single-threaded binary tree? A single-threaded binary tree is a binary tree in which each node that does not have a right child has a threaded pointer to its successor in the inorder traversal, but nodes with right children do not have threaded pointers.

  7. What is a double-threaded binary tree? A double-threaded binary tree is a binary tree in which each node has both a left and right threaded pointer.

  8. How do we create a threaded binary tree? We create a threaded binary tree by adding threaded pointers to a standard binary tree. We can do this either during the tree creation process or after the tree has been created.

  9. What are the types of threaded binary trees? The types of threaded binary trees are single-threaded binary trees and double-threaded binary trees.

  10. What is the difference between a threaded binary tree and a standard binary tree? A threaded binary tree has additional pointers (threaded pointers) that allow us to traverse the tree using the inorder sequence without recursion or a stack. A standard binary tree does not have these additional pointers.

In threaded binary trees, the null pointers of leaf nodes are replaced with pointers to either their inorder predecessor or successor. This modification enables traversal in either direction without explicitly using stack memory or recursion. In inorder traversal of a threaded binary tree, the leftmost node is reached by following all left child pointers until a node with a null left child is encountered. Then, the parent node is visited, followed by the right subtree rooted at that node. If the right child pointer of the visited node is a thread pointer, it leads to the inorder successor. Otherwise, we follow the right child pointer and repeat the process of reaching the leftmost node in the subtree rooted at that node. This traversal technique reduces the space complexity required for recursive or iterative inorder traversal in binary trees. However, it requires additional links to be stored in the threaded binary tree. Also, the insertion or deletion of nodes in a threaded binary tree requires updating the thread pointers of their predecessor or successor nodes. Overall, inorder traversal in threaded trees is a useful technique for reducing space complexity and increasing the efficiency of traversal in binary trees.