Question: For Programming Assignment 2 ( PA 2 ) , you will learn how to traverse a binary tree using Python. A binary tree is a

For Programming Assignment 2(PA2), you will learn how to traverse a binary tree using Python. A binary
tree is a tree in which each node has at most two children.
Assume the node is represented by the following Python class:
class TreeNode:
def_init_(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right
self.val is the node's value, self.left and self.right represent the node's left and right nodes, respectively.
For this assignment, you will be given a tree as input and all of its values are 0. Your program must
traverse the tree and set all of the node values to 1. Then print out the tree. See the Examples section
for exactly what I expect.
In addition, usage of any string manipulation (instead of actually traversing the tree) for this assignment
is prohibited. This includes, but is not limited to, the usage of Python's "replace" and "re.sub" functions.
If you do, you will get an automatic zero for this assignment.
Your code cannot import any library.
To reduce any misunderstanding, you will be given a template
cecs328pa2.py file. All you need to do is
fill out the file with your code, specifically where it says "Insert your code here". Do not add or change
anything else within that file. You still need to add your name at the top of the code though, as a
comment.
 For Programming Assignment 2(PA2), you will learn how to traverse a

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!