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 links: one for the left child and one for the right child. Both children start as empty (None).
Click to reveal answer
beginner
What does 'None' represent in a binary tree node?
'None' means there is no child node in that position. It shows the end of a branch or that the node has no left or right child.
Click to reveal answer
beginner
Why do we link nodes in a binary tree?
Linking nodes connects parents to their children, making the tree structure. Without links, nodes are just separate pieces with no order or relationship.
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 reach all other nodes.
Click to reveal answer
What is the maximum number of children a node in a binary tree can have?
ATwo
BThree
COne
DUnlimited
✗ Incorrect
In a binary tree, each node can have at most two children: left and right.
What does a 'None' value in a node's child link mean?
AThe node has two children
BThe child node exists
CThe node is the root
DThe child node does not exist
✗ Incorrect
'None' means there is no child node connected in that position.
Which node is the starting point of a binary tree?
ALeft child
BLeaf node
CRoot node
DRight child
✗ Incorrect
The root node is the top node and starting point of the tree.
How do you manually create a binary tree node in Python?
ABy calling a built-in binary tree function
BBy creating a class with value, left, and right attributes
CBy using a dictionary with keys 'value' and 'children'
DBy using a list with three elements
✗ Incorrect
Manually creating a node involves defining a class with value, left, and right attributes.
What is the purpose of linking nodes in a binary tree?
ATo connect parents to children and form the tree structure
BTo store values only
CTo sort the nodes automatically
DTo delete nodes easily
✗ Incorrect
Linking nodes connects parents to children, creating the tree shape.
Explain how to create a simple binary tree manually with three nodes.
Think about making a parent and two children connected by links.
You got /4 concepts.
Describe what 'None' means in the context of binary tree nodes and why it is important.
Consider what happens when a node does not have a left or right child.
You got /4 concepts.
Practice
(1/5)
1. What is the correct way to create a root node manually in a binary tree using a simple class with attributes data, left, and right?
easy
A. root = Node(10) # creates root with data 10 and no children
B. root = Node() # creates root with no data
C. root = Node.left(10) # creates left child with data 10
D. root = Node.right(10) # creates right child with data 10
Solution
Step 1: Understand Node class constructor
The Node class constructor takes data as an argument and initializes left and right children as None.
Step 2: Create root node with data
Using root = Node(10) creates a root node with data 10 and no children.
Final Answer:
root = Node(10) # creates root with data 10 and no children -> Option A
Quick Check:
Create root node with data = root = Node(10) [OK]
Hint: Use Node(data) to create a node with data and empty children [OK]
Common Mistakes:
Trying to create children directly without root
Calling left or right as methods
Creating node without data when constructor requires it
2. Which of the following code snippets correctly assigns a left child node with data 5 to an existing root node named root?
easy
A. root.left = 5
B. root.left(5)
C. root.left.data = 5
D. root.left = Node(5)
Solution
Step 1: Assign a new Node object to root.left
To add a left child, assign a new Node instance with data 5 to root.left.
Step 2: Check syntax correctness
root.left = Node(5) correctly creates and assigns the left child node.
Final Answer:
root.left = Node(5) -> Option D
Quick Check:
Assign left child node = root.left = Node(5) [OK]
Hint: Assign Node(data) to left or right attribute to add child [OK]
Common Mistakes:
Calling left as a function instead of assigning
Assigning data directly without creating Node
Assigning integer directly to left attribute
3. Given the following code, what is the printed output representing the tree structure?