A. Cannot use None for Box<Node> fields; should use Option
B. Missing semicolon after struct definition
C. Box cannot be used inside structs
D. Cannot create nested structs in Rust
Solution
Step 1: Identify the field types and assigned values
The struct fields left and right are Box<Node>, but code assigns None to some of them.
Step 2: Understand why None is invalid here
None is an Option variant, but fields are Box<Node> (non-optional), so None cannot be assigned.
Final Answer:
Cannot use None for Box<Node> fields; should use Option -> Option B
Quick Check:
Use Option for nullable children [OK]
Hint: Use Option to allow None children [OK]
Common Mistakes:
Thinking Box<Node> can be None
Ignoring Option wrapper for nullable fields
Assuming Box is not allowed in structs
5. Given that arrays and linked lists store data linearly, which of the following real-world problems is best solved using a tree data structure instead?
medium
A. Storing a list of daily temperatures in order
B. Maintaining a queue of customers waiting in line
C. Storing a sequence of characters in a string
D. Representing a company's organizational chart with managers and employees
Solution
Step 1: Analyze each problem type
Options A, B, and D represent linear data best suited for arrays or linked lists.
Step 2: Identify hierarchical data
Representing a company's organizational chart with managers and employees describes an organizational chart, which is hierarchical and fits tree structures.
Final Answer:
Representing a company's organizational chart with managers and employees -> Option D
Quick Check:
Hierarchical data needs trees [OK]
Hint: Use trees for hierarchical data like org charts [OK]
Common Mistakes:
Choosing linear data problems for trees
Confusing queues or sequences with trees
Ignoring data relationships
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.