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 branches splitting into two.
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: one for the left child and one for the right child. Both children can be empty (null) if no child exists.
Click to reveal answer
beginner
What does the root node represent in a binary tree?
The root node is the top node of the tree. It is the starting point from where you can reach all other nodes by following left and right children.
Click to reveal answer
intermediate
In TypeScript, how can you define a simple binary tree node type?
You can define it as a type or interface with a value of any type and two optional children nodes: left and right, which can be null or another node.
Click to reveal answer
beginner
Why is it useful to create a binary tree manually?
Creating a binary tree manually helps understand how nodes connect and how trees grow. It is the base for learning tree traversal and other tree operations.
Click to reveal answer
What is the maximum number of children a node in a binary tree can have?
AUnlimited
BThree
COne
DTwo
✗ Incorrect
In a binary tree, each node can have at most two children: left and right.
Which node is the starting point of a binary tree?
ARoot node
BLeaf node
CChild node
DSibling node
✗ Incorrect
The root node is the top node and starting point of a binary tree.
In TypeScript, what type can represent a missing child in a binary tree node?
Anull
B0
Cundefined
Dempty string
✗ Incorrect
We use null to show that a child node does not exist.
What does a binary tree node usually contain?
AOnly a value
BOnly two children
CValue and two children
DValue and three children
✗ Incorrect
A binary tree node contains a value and pointers to left and right children.
Why create a binary tree manually?
ATo sort numbers automatically
BTo understand node connections
CTo create a linked list
DTo avoid learning trees
✗ Incorrect
Manual creation helps understand how nodes connect and how trees work.
Explain how to create a binary tree manually using nodes with left and right children.
Think about how each node connects to two others or none.
You got /5 concepts.
Describe the role of the root node in a binary tree and how other nodes relate to it.
Imagine the root as the tree trunk from which branches grow.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of manually creating a binary tree in TypeScript?
easy
A. To avoid using classes or objects
B. To automatically sort data without coding
C. To understand how nodes connect and form the tree structure
D. To create a linked list instead of a tree
Solution
Step 1: Understand binary tree structure
A binary tree consists of nodes where each node has at most two children, left and right.
Step 2: Purpose of manual creation
Manually creating a binary tree helps visualize and understand how nodes connect to form the tree.
Final Answer:
To understand how nodes connect and form the tree structure -> Option C
D. Assigning number 5 to root.left instead of a Node or null
Solution
Step 1: Check type of root.left assignment
root.left is declared as Node or null, but assigned number 5 which is invalid.
Step 2: Confirm correct assignment type
root.left should be assigned a Node instance or null, not a number.
Final Answer:
Assigning number 5 to root.left instead of a Node or null -> Option D
Quick Check:
Type mismatch in root.left assignment = Assigning number 5 to root.left instead of a Node or null [OK]
Hint: Children must be Node or null, not a number [OK]
Common Mistakes:
Assigning primitive values to node children
Ignoring type errors in assignments
Assuming number can be assigned directly
5. You want to manually create a binary tree with root value 20, left child 10, and right child 30. Which code snippet correctly creates this tree and prints the root, left, and right values in order?
hard
A. const root = new Node(20);
root.left = 10;
root.right = 30;
console.log(root.value, root.left, root.right);
B. const root = new Node(20);
root.left = new Node(10);
root.right = new Node(30);
console.log(root.value, root.left?.value, root.right?.value);
C. const root = new Node(20);
root.left = new Node(30);
root.right = new Node(10);
console.log(root.value, root.left?.value, root.right?.value);
D. const root = new Node(20);
root.left = null;
root.right = null;
console.log(root.left?.value, root.value, root.right?.value);
Solution
Step 1: Create root and children nodes correctly
Root node with value 20, left child 10, right child 30 must be Node instances.
Step 2: Print values in order root, left, right
console.log prints root.value, root.left?.value, root.right?.value which outputs 20 10 30.
Final Answer:
const root = new Node(20);
root.left = new Node(10);
root.right = new Node(30);
console.log(root.value, root.left?.value, root.right?.value); -> Option B
Quick Check:
Correct node creation and print order = const root = new Node(20);
root.left = new Node(10);
root.right = new Node(30);
console.log(root.value, root.left?.value, root.right?.value); [OK]
Hint: Create nodes with new, assign children as nodes, print values [OK]
Common Mistakes:
Assigning numbers directly to children
Swapping left and right child values
Printing children before root or using null children
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.