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
- 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
- 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
- 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)
- 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)
- 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
- 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
- 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
- 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
- A complete binary tree of n nodes has its root at index: a) 0 b) 1 c) n-1 d) n
Answer: a) 0
- 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
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.
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.
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.
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.
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)).
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.
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).
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.
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.
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.
- The height of a complete binary tree with n nodes is log2(n) (base 2 logarithm) rounded up to the nearest integer.
- The maximum number of nodes in a complete binary tree of height h is 2^(h+1) - 1.
- 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.