A binary tree is a structure where each node has up to two children called left and right. It looks like a family tree with each parent having at most two kids.
Click to reveal answer
beginner
How do you create a node in a binary tree manually?
You create a node by making an object with a value and two pointers: left and right. Both pointers start as null because the node has no children yet.
Click to reveal answer
beginner
What does the 'left' pointer in a binary tree node represent?
The 'left' pointer points to the left child node. If there is no left child, it is null.
Click to reveal answer
beginner
What is the root node in a binary tree?
The root node is the top node of the tree. It has no parent and is the starting point to access all other nodes.
Click to reveal answer
beginner
How do you link nodes to form a binary tree manually?
You assign the left and right pointers of a node to other nodes to connect them. This builds the tree structure step by step.
Click to reveal answer
What is the maximum number of children a node can have in a binary tree?
AOne
BUnlimited
CThree
DTwo
✗ Incorrect
In a binary tree, each node can have at most two children: left and right.
What is the initial value of left and right pointers when creating a new node manually?
AUndefined
BNull
CZero
DEmpty string
✗ Incorrect
Left and right pointers start as null because the node has no children yet.
Which node is called the root in a binary tree?
AThe top node with no parent
BAny leaf node
CThe bottom-most node
DA node with two children
✗ Incorrect
The root node is the top node with no parent and is the starting point of the tree.
How do you connect nodes to form a binary tree manually?
ABy deleting nodes
BBy copying node values
CBy assigning left and right pointers
DBy swapping nodes
✗ Incorrect
You connect nodes by assigning the left and right pointers to other nodes.
If a node has no left child, what is the left pointer value?
ANull
BZero
CUndefined
DEmpty string
✗ Incorrect
If there is no left child, the left pointer is null.
Explain how to create a simple binary tree manually with three nodes.
Think about making three boxes and linking them with arrows for left and right.
You got /3 concepts.
Describe the role of left and right pointers in a binary tree node.
Imagine each node as a person holding hands with up to two children.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of creating a binary tree manually in JavaScript?
easy
A. To convert a string into an array
B. To automatically sort numbers in an array
C. To create a list of numbers without any hierarchy
D. To build a tree structure by linking nodes with left and right children
Solution
Step 1: Understand what a binary tree is
A binary tree is a structure where each node has up to two children: left and right.
Step 2: Purpose of manual creation
Manually creating a binary tree means linking nodes by setting their left and right child references.
Final Answer:
To build a tree structure by linking nodes with left and right children -> Option D
Quick Check:
Binary tree = linked nodes with left/right children [OK]
Hint: Binary tree nodes link left and right children manually [OK]
Common Mistakes:
Thinking binary tree sorts data automatically
Confusing binary tree with arrays or lists
Assuming binary tree nodes have more than two children
2. Which of the following is the correct way to create a node object for a binary tree in JavaScript?
A. Cannot assign value to left because left is null
B. Syntax error in object declaration
C. Missing semicolon after node declaration
D. No error, code runs fine
Solution
Step 1: Analyze node.left value
node.left is set to null, so it has no properties.
Step 2: Assigning to node.left.value
Trying to assign node.left.value = 3 causes error because node.left is null, cannot set property on null.
Final Answer:
Cannot assign value to left because left is null -> Option A
Quick Check:
Assigning property on null causes error [OK]
Hint: Check if child node exists before assigning properties [OK]
Common Mistakes:
Ignoring that null has no properties
Assuming automatic node creation on assignment
Thinking missing semicolon causes error here
5. You want to manually create a binary tree with root value 20, left child 10, and right child 30. Which code correctly creates this tree and prints the right child's value?