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 PA 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:
definitself val leftNone, rightNone:
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 Your program must
traverse the tree and set all of the node values to 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 resub" 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
cecspapy 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.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
