29 Lecture

CS301

Midterm & Final Term Short Notes

Complete Binary Tree

A complete binary tree is a binary tree where all levels except possibly the last are completely filled, and all nodes are as far left as possible. In other words, for a complete binary tree of height h, the first h-1 levels should contain 2^(i-


Important Mcq's
Midterm & Finalterm Prepration
Past papers included

Download PDF
  1. A binary tree is said to be complete if: a) All nodes have two children b) All levels are completely filled except possibly the last level c) All nodes have at most two children d) None of the above

Answer: b) All levels are completely filled except possibly the last level

  1. What is the maximum number of nodes a complete binary tree of height h can have? a) 2^h+1 b) 2^h-1 c) h^2 d) None of the above

Answer: b) 2^h-1

  1. What is the minimum number of nodes a complete binary tree of height h can have? a) 2^(h-1) b) 2^(h-1)-1 c) h^2-1 d) None of the above

Answer: a) 2^(h-1)

  1. A complete binary tree of height h has _____ leaf nodes. a) 2^h-1 b) 2^(h-1) c) 2^(h-1)+1 d) None of the above

Answer: b) 2^(h-1)

  1. What is the height of a complete binary tree with 15 nodes? a) 3 b) 4 c) 5 d) None of the above

Answer: b) 4

  1. A complete binary tree can be efficiently stored in an array using: a) Inorder traversal b) Preorder traversal c) Postorder traversal d) Level order traversal

Answer: d) Level order traversal

  1. The number of internal nodes in a complete binary tree of height h is: a) 2^h b) 2^h-1 c) 2^(h+1)-1 d) None of the above

Answer: b) 2^h-1

  1. What is the parent of the node at index i in an array representation of a complete binary tree? a) i-1 b) i/2 c) 2*i d) None of the above

Answer: b) i/2

  1. A complete binary tree of n nodes has its root at index: a) 0 b) 1 c) n-1 d) n

Answer: a) 0

  1. Which of the following is NOT true about a complete binary tree? a) It can have a maximum of 2^h-1 nodes b) It can have a minimum of 2^(h-1) nodes c) Its last level can have any number of nodes d) All levels except possibly the last level are completely filled

Answer: c) Its last level can have any number of nodes



Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included

Download PDF
  1. What is a complete binary tree? A complete binary tree is a binary tree in which all levels are completely filled, except possibly the last level, which is filled from left to right.

  2. How can we determine the level of a node in a complete binary tree? The level of a node in a complete binary tree can be determined by counting the number of edges from the root to the node.

  3. What is the maximum number of nodes that a complete binary tree of height h can have? The maximum number of nodes that a complete binary tree of height h can have is 2^(h+1) - 1.

  4. How can we check if a binary tree is complete or not? We can check if a binary tree is complete or not by performing a level-order traversal and checking if any node is missing or if there are any nodes after the first null node encountered.

  5. What is the height of a complete binary tree with n nodes? The height of a complete binary tree with n nodes is floor(log2(n)).

  6. How can we construct a complete binary tree from its array representation? We can construct a complete binary tree from its array representation by starting at the root, then setting the left child to the next element in the array and the right child to the element after that. We can then recursively apply this process to each node in the tree.

  7. What is the time complexity of finding the height of a complete binary tree? The time complexity of finding the height of a complete binary tree is O(logn).

  8. Can a complete binary tree be a balanced binary tree? Yes, a complete binary tree can be a balanced binary tree if all levels have the maximum possible number of nodes.

  9. What is the relationship between the height and number of nodes in a complete binary tree? The relationship between the height and number of nodes in a complete binary tree is that the number of nodes is 2^(h+1) - 1, where h is the height of the tree.

  10. Can a binary tree with only one node be considered a complete binary tree? Yes, a binary tree with only one node can be considered a complete binary tree as it satisfies the condition that all levels are completely filled.

A complete binary tree is a binary tree in which all the levels are filled except the last level, which is filled from left to right. This type of binary tree is useful in certain applications where we need to access nodes in a particular order, such as in heaps and priority queues. The main properties of a complete binary tree are as follows:
  1. The height of a complete binary tree with n nodes is log2(n) (base 2 logarithm) rounded up to the nearest integer.
  2. The maximum number of nodes in a complete binary tree of height h is 2^(h+1) - 1.
  3. If we assign numbers to the nodes in a complete binary tree from left to right, starting at the root with 1, then for any node with number i, its left child has number 2i and its right child has number 2i+1. Conversely, for any node with number i > 1, its parent has number i/2 rounded down.
Complete binary trees have several useful properties that make them suitable for certain algorithms and data structures. For example, in a complete binary heap, the root node is always the minimum (or maximum) element, and we can efficiently perform insertions and deletions by maintaining the heap property and the completeness property. Similarly, in a complete binary search tree, we can efficiently perform search, insert, and delete operations using binary search.