Binary Trees Quiz

Tree
0 Passed
0% acceptance

40 comprehensive questions exploring binary tree fundamentals — with 16 code examples covering definitions, properties, full/complete/perfect trees, and basic implementations in this cpp quiz.

40 Questions
~80 minutes
1

Question 1

What is a binary tree?

A
A tree data structure where each node has at most two children, referred to as the left child and right child, forming a hierarchical structure with a single root and no cycles
B
A tree with exactly two children per node
C
A tree with nodes arranged in a linear fashion
D
A tree that can have any number of children
2

Question 2

In a binary tree, what is the maximum number of nodes at level k (starting from level 0 at root)?

text
Level 0: 1 node
Level 1: 2 nodes
Level 2: 4 nodes
Level k: ?
A
2^k nodes, following the exponential growth pattern where each level doubles the number of nodes from the previous level in a complete binary tree structure
B
k nodes
C
k^2 nodes
D
1 node
3

Question 3

What is a full binary tree?

A
A binary tree where every node has either 0 or 2 children, meaning no node has exactly one child, creating a balanced structure with maximum branching at each level
B
A binary tree with all levels completely filled
C
A binary tree where all leaves are at the same level
D
A binary tree with exactly two children per node
4

Question 4

What is a complete binary tree?

text
Complete tree: nodes filled left to right
Incomplete tree: gaps in the structure
A
A binary tree where all levels are completely filled except possibly the last level, which is filled from left to right without any gaps in the node positions
B
A binary tree where every node has two children
C
A binary tree where all leaves are at the same level
D
A binary tree with no missing nodes
5

Question 5

What is a perfect binary tree?

A
A binary tree where all internal nodes have exactly two children and all leaves are at the same level, creating a complete and balanced structure with maximum possible nodes for its height
B
A binary tree with all levels completely filled
C
A binary tree where every node has either 0 or 2 children
D
A binary tree that is balanced
6

Question 6

In a binary tree with n nodes, what is the minimum possible height?

text
Height = longest path from root to leaf
Minimum height for n nodes: floor(log2(n))
A
Floor(log2(n)), achieved when the tree is as balanced as possible with nodes distributed to minimize the maximum path length from root to any leaf
B
n-1
C
1
D
log2(n)
7

Question 7

What is the maximum number of nodes in a binary tree of height h?

A
2^(h+1) - 1, representing the total nodes in a perfect binary tree where each level contributes exponentially more nodes than the previous level
B
2^h
C
h^2
D
h+1
8

Question 8

In a complete binary tree, where would the parent of a node at position i be located?

text
Array indices: 0-based
Left child: 2*i + 1
Right child: 2*i + 2
Parent of i: ?
A
At position floor((i-1)/2), using integer division to calculate the parent index from any child position in the array-based complete binary tree representation
B
At position i/2
C
At position i-1
D
At position 0
9

Question 9

What is the relationship between the number of leaf nodes and internal nodes in a full binary tree?

A
Number of leaf nodes equals number of internal nodes plus one, because each internal node contributes to creating branches that eventually terminate in leaves
B
Leaf nodes are twice the internal nodes
C
Internal nodes are twice the leaf nodes
D
No specific relationship exists
10

Question 10

How many different binary trees can be formed with 3 nodes?

text
Nodes: A, B, C
Possible trees: 5 different structures
A
5 different trees, considering all possible ways to arrange the nodes while maintaining the binary tree properties and different root/branching configurations
B
3 different trees
C
6 different trees
D
1 different tree
11

Question 11

What is a skewed binary tree?

A
A binary tree where each node has only one child, creating a linear structure that resembles a linked list with poor balance and height equal to number of nodes minus one
B
A binary tree with all leaves at the same level
C
A binary tree where every node has two children
D
A balanced binary tree
12

Question 12

In a binary tree, what is the maximum number of nodes at level k in a tree of height h?

text
Height h means levels 0 to h
Level k has at most 2^k nodes
A
2^k nodes, as each level can have up to twice as many nodes as the previous level in a complete binary tree configuration
B
k nodes
C
2^h nodes
D
1 node
13

Question 13

What is the height of a single-node binary tree?

text
Tree with one node: root
Height: 0
A
0, since height is defined as the number of edges on the longest path from root to leaf, and a single node has no edges
B
1
C
2
D
Undefined
14

Question 14

How many edges does a binary tree with n nodes have?

A
n-1 edges, following the fundamental tree property that any tree with n nodes must have exactly n-1 edges to maintain connectivity without cycles
B
n edges
C
2n edges
D
n+1 edges
15

Question 15

What is the minimum number of nodes in a binary tree of height h?

text
Height h: minimum nodes = h + 1
(skewed tree)
A
h + 1, achieved in a skewed binary tree where nodes form a straight line with each node having only one child, maximizing height for minimum nodes
B
2^h
C
h^2
D
1
16

Question 16

In a complete binary tree with n nodes, what is the height of the tree?

text
Complete tree: floor(log2(n))
A
Floor(log2(n)), representing the level where the last node is placed in the left-to-right filling pattern of a complete binary tree
B
Ceil(log2(n))
C
n-1
D
1
17

Question 17

What distinguishes a binary tree from a general tree?

A
Binary trees restrict each node to at most two children with explicit left and right designations, while general trees allow unlimited children without positional ordering
B
Binary trees have cycles
C
Binary trees allow multiple roots
D
General trees have exactly two children
18

Question 18

In a perfect binary tree of height h, how many nodes are there?

A
2^(h+1) - 1, calculated as the sum of a geometric series where each level contributes 2^k nodes, giving the maximum possible nodes for that height
B
2^h
C
h^2
D
h+1
19

Question 19

What is the balance factor of a node in binary tree analysis?

text
Balance factor = height(left) - height(right)
A
Height of left subtree minus height of right subtree, used to measure how balanced the node is and determine if rotations are needed in balanced tree algorithms
B
Number of children
C
Depth from root
D
Number of nodes in subtree
20

Question 20

How many different binary search trees can be formed with keys 1, 2, 3?

A
5 different BSTs, considering all possible root choices and the resulting left and right subtree arrangements that maintain the BST ordering property
B
3 different BSTs
C
6 different BSTs
D
1 different BST
21

Question 21

What is the maximum height of a binary tree with n nodes?

text
Skewed tree: height = n-1
A
n-1, achieved when the tree is skewed with each node having only one child, creating a linear structure resembling a linked list
B
log2(n)
C
n/2
D
1
22

Question 22

In a binary tree, what is the relationship between internal nodes and total nodes?

A
Number of internal nodes = floor(n/2), since in a binary tree, roughly half the nodes are internal with the remainder being leaves, though this varies with tree structure
B
Internal nodes = n-1
C
Internal nodes = n
D
No relationship exists
23

Question 23

What is a degenerate binary tree?

text
All nodes have one child: linear structure
A
A binary tree that has become skewed or linear, where each node has at most one child, effectively reducing the tree to a linked list with poor performance characteristics
B
A binary tree with all leaves at the same level
C
A binary tree where every node has two children
D
A balanced binary tree
24

Question 24

How does the height of a complete binary tree relate to the number of nodes?

A
Height is floor(log2(n)), meaning the tree grows logarithmically with the number of nodes, providing optimal balance and efficient operations
B
Height is n
C
Height is constant
D
Height is n/2
25

Question 25

What is the significance of the binary tree property in algorithm design?

text
Binary choices: left/right, true/false, yes/no
A
Binary trees naturally model decision processes with two-way branches, enabling efficient divide-and-conquer algorithms and logarithmic-time operations in balanced structures
B
They allow unlimited children
C
They have cycles
D
They require linear time for all operations
26

Question 26

In a full binary tree with n internal nodes, how many leaves are there?

A
n + 1 leaves, because each internal node contributes to creating the branching structure that terminates in one more leaf than internal nodes
B
n leaves
C
2n leaves
D
n-1 leaves
27

Question 27

What is the minimum height of a binary tree with n nodes?

text
Balanced tree: height ≈ log2(n)
A
Floor(log2(n)), achieved when the tree is as complete as possible, distributing nodes to minimize the longest path from root to leaf
B
n-1
C
1
D
n
28

Question 28

How many leaves can a binary tree with n nodes have at most?

A
Ceil(n/2) + 1, depending on the tree structure where leaves can range from 1 in a skewed tree to approximately half the nodes plus one in a balanced configuration
B
n
C
1
D
n/2
29

Question 29

What is the structural difference between complete and perfect binary trees?

text
Perfect: all levels full
Complete: last level left-filled
A
Perfect trees have all levels completely filled, while complete trees allow the last level to be partially filled but require left-to-right filling without gaps
B
They are identical
C
Complete trees have all levels full
D
Perfect trees allow gaps
30

Question 30

In terms of space complexity, how do binary trees compare to arrays for storing hierarchical data?

A
Binary trees use O(n) space for n nodes with pointers, while arrays for complete trees also use O(n) space but may waste space for incomplete trees, making trees more flexible for dynamic structures
B
Arrays always use less space
C
Binary trees use O(n^2) space
D
Arrays use O(1) space
31

Question 31

What is the Catalan number's significance in binary tree enumeration?

text
C_n = number of binary trees with n nodes
C_3 = 5
A
Catalan numbers count the possible binary tree structures for n nodes, providing a mathematical formula for determining how many different ways n distinct nodes can be arranged in binary tree formations
B
They count only perfect binary trees
C
They count the number of leaves
D
They are not related to binary trees
32

Question 32

How does the height of a binary tree affect algorithm performance?

A
Height determines the worst-case time complexity for operations like search and insertion, with balanced trees providing O(log n) performance while skewed trees degrade to O(n) linear time
B
Height has no effect on performance
C
Only affects space usage
D
Makes all operations O(1)
33

Question 33

What is the relationship between a binary tree's height and its balance?

text
Balanced: height ≈ log2(n)
Unbalanced: height ≈ n
A
A balanced binary tree has height proportional to log n, while unbalanced trees can have height linear in the number of nodes, affecting performance and structural integrity
B
Balance is unrelated to height
C
All binary trees have the same height
D
Height determines balance factor
34

Question 34

In a binary tree implementation, what is the significance of the null pointer representation?

cpp
TreeNode* left = nullptr;
TreeNode* right = nullptr;
A
Null pointers indicate missing children, allowing flexible tree structures where nodes can have 0, 1, or 2 children and enabling recursive algorithms to terminate properly
B
Null pointers waste memory
C
Null pointers indicate cycles
D
Null pointers are not used in trees
35

Question 35

How do binary trees support recursive algorithm design?

A
The hierarchical structure with left and right subtrees enables natural recursive decomposition, where problems can be solved by recursively processing smaller subproblems on child subtrees
B
Binary trees don't support recursion
C
Only iterative algorithms work
D
Recursion requires additional data structures
36

Question 36

What is the impact of tree shape on binary tree operations?

text
Balanced: O(log n)
Skewed: O(n)
A
Tree shape determines operation complexity, with balanced trees providing logarithmic performance while skewed trees can degrade operations to linear time, making shape optimization crucial for efficiency
B
Shape has no impact
C
All shapes perform identically
D
Shape only affects memory usage
37

Question 37

In binary tree analysis, what does the term 'degeneracy' refer to?

A
A tree that has degenerated into a linear structure, losing its branching advantages and performing like a linked list with poor algorithmic complexity
B
A tree with all leaves at the same level
C
A tree with maximum branching
D
A tree with no nodes
38

Question 38

How does the binary tree structure enable efficient searching algorithms?

text
Binary search: compare, go left or right
A
The ordered left-right structure allows binary search algorithms to eliminate half the remaining possibilities at each step, achieving logarithmic time complexity for search operations
B
Binary trees don't support searching
C
Searching requires O(n) time
D
All nodes must be visited
39

Question 39

What is the fundamental property that distinguishes binary trees from other tree types in terms of structural constraints?

A
The strict limitation to at most two children per node with explicit left and right positioning, creating ordered subtrees that enable specialized algorithms and traversal patterns
B
The ability to have cycles
C
The requirement for all leaves at the same level
D
The limitation to single root only
40

Question 40

Considering the various properties and classifications of binary trees, which structural characteristic most directly influences the efficiency of tree-based algorithms and data structure performance in practice?

A
Tree balance and height, where balanced trees with logarithmic height enable O(log n) operations while unbalanced trees can degrade to O(n) performance, making height maintenance critical for algorithmic efficiency across search, insertion, and deletion operations
B
The number of leaves
C
The root node value
D
The total number of nodes

QUIZZES IN Tree