Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Im trying to traverse a BFS but I continue to get an error. I believed I have fo

ID: 3912802 • Letter: I

Question

Im trying to traverse a BFS but I continue to get an error. I believed I have followed the instructions correctly but I continue to get an error. Can someone tell me what I am doing wrong and solve my problem with an explatation?

1. create a Q with the root element, and an empty list

2. while there are nodes in the Q grab the first one and add it to the result list

3. if there is a node to the left, add that to the Q

4. if there is a node to the right, add that to the Q

This is the test case I need to pass.

This is the error I am getting AssertionError: Lists differ: [] != [20, 10, 30, > 25, 35]

Explanation / Answer

according to your concept for the above, code you want to traverse left node if the child of the left node is not null and traverse right node if the child of the right node is not null.

and this is your code in which you made a small mistake.

where the bold statement is wrong.

this should be your code where you check both the sides of the tree.