Why do left and right children start as null in a new binary tree node?
Because when a node is created, it has no children yet. Null means no child node connected on that side.
Click to reveal answer
intermediate
How does a binary tree node differ from a linked list node?
A binary tree node has two pointers (left and right), while a linked list node has only one pointer to the next node.
Click to reveal answer
What does a binary tree node typically contain?
AData, left child, right child
BData, next node
COnly data
DData, previous node
✗ Incorrect
A binary tree node contains data and two children pointers: left and right.
In JavaScript, how do you represent a missing child in a binary tree node?
Aundefined
Bnull
C0
Dfalse
✗ Incorrect
Null is used to show that a child node does not exist.
Which of these is NOT a part of a binary tree node?
ARight child pointer
BLeft child pointer
CParent pointer
DValue
✗ Incorrect
A basic binary tree node does not have a parent pointer.
What is the initial value of left and right children when a node is created?
Anull
B0
Cundefined
Dempty string
✗ Incorrect
Left and right children start as null to show no children exist yet.
How many children can a binary tree node have at most?
A1
B3
CUnlimited
D2
✗ Incorrect
A binary tree node can have up to two children: left and right.
Describe the structure of a binary tree node and its parts.
Think about what each node stores and how it connects to others.
You got /4 concepts.
Write a simple JavaScript class for a binary tree node and explain why left and right start as null.
Focus on the code and the meaning of null pointers.
You got /5 concepts.
Practice
(1/5)
1. What does a typical binary tree node contain in its structure?
easy
A. A value and multiple child nodes in a list
B. A value, a left child node, and a right child node
C. Only a value and a pointer to the next node
D. Only a value without any child references
Solution
Step 1: Understand binary tree node components
A binary tree node stores a value and has exactly two child references: left and right.
Step 2: Compare options with binary tree definition
A value, a left child node, and a right child node correctly lists value, left child, and right child. Others describe linked list or general tree nodes.
Final Answer:
A value, a left child node, and a right child node -> Option B
Quick Check:
Binary tree node = value + left + right [OK]
Hint: Binary tree nodes always have left and right child pointers [OK]
Common Mistakes:
Confusing binary tree node with linked list node
Thinking nodes have multiple children like general trees
Ignoring child pointers in node structure
2. Which of the following is the correct JavaScript syntax to define a binary tree node class?
easy
A. class Node { constructor(value) { this.value = value; this.left = null; this.right = null; } }
B. function Node(value) { this.value = value; this.next = null; }
C. class Node { constructor(value) { this.value = value; this.children = []; } }
D. var Node = (value) => { this.value = value; this.left = null; this.right = null; }
Solution
Step 1: Identify correct class syntax for binary tree node
class Node { constructor(value) { this.value = value; this.left = null; this.right = null; } } uses ES6 class with constructor setting value, left, and right to null.
Step 2: Check other options for errors
function Node(value) { this.value = value; this.next = null; } uses next pointer (linked list), C uses children array (general tree), D uses arrow function incorrectly for constructor.
Final Answer:
class Node { constructor(value) { this.value = value; this.left = null; this.right = null; } } -> Option A
Quick Check:
Class with value, left, right = class Node { constructor(value) { this.value = value; this.left = null; this.right = null; } } [OK]
Hint: Use ES6 class with left and right set to null [OK]
A. function countNodes(node) { if (node === null) return null; return 1 + countNodes(node.left) + countNodes(node.right); }
B. function countNodes(node) { if (!node) return 1; return countNodes(node.left) + countNodes(node.right); }
C. function countNodes(node) { return node.value + countNodes(node.left) + countNodes(node.right); }
D. function countNodes(node) { if (!node) return 0; return 1 + countNodes(node.left) + countNodes(node.right); }
Solution
Step 1: Understand base case for recursion
If node is null, count is zero because no node exists there.
Step 2: Sum current node plus counts of left and right subtrees
Return 1 (current node) plus recursive counts of left and right children.
Step 3: Check options for correct base case and sum
function countNodes(node) { if (!node) return 0; return 1 + countNodes(node.left) + countNodes(node.right); } correctly returns 0 for null and sums 1 + left + right counts.
Final Answer:
function countNodes(node) { if (!node) return 0; return 1 + countNodes(node.left) + countNodes(node.right); } -> Option D
Quick Check:
Count nodes = 1 + left count + right count [OK]
Hint: Return 0 for null, else 1 + left + right counts [OK]
Common Mistakes:
Returning 1 for null node instead of 0
Adding node.value instead of count 1
Returning null instead of 0 in base case
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.