Recall & Review
beginner
What is a binary tree node?
A binary tree node is a basic unit of a binary tree that contains data and two pointers or references: one to the left child and one to the right child.
Click to reveal answer
beginner
What are the main components of a binary tree node in C++?
The main components are:<br>1. Data (value stored in the node)<br>2. Pointer to the left child node<br>3. Pointer to the right child node
Click to reveal answer
beginner
Show a simple C++ struct definition for a binary tree node.
struct Node {<br> int data;<br> Node* left;<br> Node* right;<br> Node(int val) : data(val), left(nullptr), right(nullptr) {}<br>};
Click to reveal answer
beginner
Why do we initialize left and right pointers to nullptr in a binary tree node?
We initialize left and right pointers to nullptr to indicate that the node does not have children yet. It helps avoid undefined behavior when accessing child nodes.
Click to reveal answer
beginner
Can a binary tree node have only one child? Explain.
Yes, a binary tree node can have zero, one, or two children. If it has only one child, either the left or right pointer will point to a child node, and the other will be nullptr.
Click to reveal answer
What does a binary tree node typically contain?
✗ Incorrect
A binary tree node contains data and two pointers: one to the left child and one to the right child.
In C++, what keyword is used to indicate a pointer that points to no object?
✗ Incorrect
nullptr is the keyword in modern C++ to indicate a pointer that points to no object.
If a binary tree node has no children, what are its left and right pointers set to?
✗ Incorrect
Left and right pointers are set to nullptr to show no children.
How many children can a binary tree node have at most?
✗ Incorrect
A binary tree node can have at most two children: left and right.
Which of these is a correct way to define a binary tree node constructor in C++?
✗ Incorrect
Setting left and right to nullptr is the modern and correct way to initialize pointers to no child.
Describe the structure of a binary tree node and its components.
Think about what each node stores and how it connects to children.
You got /4 concepts.
Explain why initializing child pointers to nullptr is important in a binary tree node.
Consider what happens if pointers are not initialized.
You got /3 concepts.