12 Lecture

CS301

Midterm & Final Term Short Notes

Operations on Binary Tree

Operations on Binary Tree include inserting a node, deleting a node, searching for a node, traversing the tree in different orders (pre-order, in-order, post-order), finding the height of the tree, checking if the tree is balanced, and more. The


Important Mcq's
Midterm & Finalterm Prepration
Past papers included

Download PDF
  1. What is the height of a binary tree with only one node? a) 0 b) 1 c) 2 d) Undefined

Answer: a) 0

  1. Which traversal method visits the nodes in the order left subtree, root, right subtree? a) Pre-order traversal b) In-order traversal c) Post-order traversal d) Level-order traversal

Answer: b) In-order traversal

  1. Which traversal method visits the nodes in the order root, left subtree, right subtree? a) Pre-order traversal b) In-order traversal c) Post-order traversal d) Level-order traversal

Answer: a) Pre-order traversal

  1. What is the time complexity of searching for a node in a Binary Tree? a) O(1) b) O(log n) c) O(n) d) It depends on the implementation

Answer: c) O(n)

  1. What is the maximum number of nodes at level k in a Binary Tree? a) 2^k b) k^2 c) k+1 d) None of the above

Answer: a) 2^k

  1. Which of the following is a way to delete a node in a Binary Tree? a) Deleting the node and its children b) Replacing the node with its left child c) Replacing the node with its right child d) All of the above

Answer: d) All of the above

  1. What is the time complexity of finding the height of a Binary Tree? a) O(1) b) O(log n) c) O(n) d) It depends on the implementation

Answer: c) O(n)

  1. What is the maximum number of nodes in a Binary Tree with height h? a) 2^h b) h^2 c) h+1 d) None of the above

Answer: a) 2^h - 1

  1. Which of the following is a way to insert a node in a Binary Tree? a) As the left child of a leaf node b) As the right child of a leaf node c) As the left child of a non-leaf node d) All of the above

Answer: d) All of the above

  1. Which of the following is an advantage of using a Binary Tree over a linked list? a) Binary Tree can be searched faster than a linked list b) Binary Tree can be sorted faster than a linked list c) Binary Tree can store data in a hierarchical structure d) All of the above

Answer: d) All of the above



Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included

Download PDF
  1. What is a binary tree?

Answer: A binary tree is a tree data structure in which each node has at most two children, referred to as the left child and the right child.

  1. What is the height of a binary tree?

Answer: The height of a binary tree is the length of the longest path from the root node to a leaf node.

  1. What is the difference between a binary tree and a binary search tree?

Answer: A binary search tree is a binary tree with the property that the value of each node is greater than or equal to the values in its left subtree and less than or equal to the values in its right subtree.

  1. What is the time complexity of inserting a node in a binary tree?

Answer: The time complexity of inserting a node in a binary tree is O(h), where h is the height of the tree.

  1. What is the time complexity of deleting a node in a binary tree?

Answer: The time complexity of deleting a node in a binary tree is O(h), where h is the height of the tree.

  1. What is the difference between pre-order traversal and post-order traversal?

Answer: Pre-order traversal visits the root node first, followed by the left subtree and then the right subtree, while post-order traversal visits the left subtree first, followed by the right subtree and then the root node.

  1. How do you determine if a binary tree is balanced?

Answer: A binary tree is balanced if the height of its left subtree and the height of its right subtree differ by at most one.

  1. What is the difference between complete binary tree and a full binary tree?

Answer: A complete binary tree is a binary tree in which every level except possibly the last is completely filled, while a full binary tree is a binary tree in which every node has either two children or zero children.

  1. What is the time complexity of finding the maximum element in a binary tree?

Answer: The time complexity of finding the maximum element in a binary tree is O(n), where n is the number of nodes in the tree.

  1. What is the time complexity of finding the height of a binary tree using dynamic programming?

Answer: The time complexity of finding the height of a binary tree using dynamic programming is O(n), where n is the number of nodes in the tree.

Operations on binary trees include several algorithms and techniques used to traverse, insert, delete, and search for nodes in a binary tree. Traversing a binary tree involves visiting each node in the tree in a specific order, such as in-order, pre-order, or post-order. Inserting a node involves finding the correct position for the node based on its value and then adding it to the tree as a leaf node. Deleting a node involves finding the node to be deleted and then either removing it and its children or replacing it with another node in the tree. Searching for a node in a binary tree involves traversing the tree and comparing the value of each node to the target value until a match is found or the end of the tree is reached. Binary trees can also be balanced to optimize their performance, with balanced trees having a height proportional to the logarithm of the number of nodes in the tree. Other operations on binary trees include finding the maximum or minimum value in the tree, determining if the tree is a binary search tree, and constructing a binary tree from its given pre-order and in-order traversals or post-order and in-order traversals. Binary trees can be implemented in various ways, such as using arrays, linked lists, or dynamic memory allocation. Operations on binary trees are used in many applications, including computer graphics, database management systems, and network routing algorithms.