Question: python coding Problem 1: reconstructBT Given the preorder and inorder traversals of a tree, construct the binary tree, assuming the values of all nodes in

python coding

python coding Problem 1: reconstructBT Given the preorder and inorder traversals ofa tree, construct the binary tree, assuming the values of all nodesin the tree are distinct. The preorder and inorder traversals are represented

Problem 1: reconstructBT Given the preorder and inorder traversals of a tree, construct the binary tree, assuming the values of all nodes in the tree are distinct. The preorder and inorder traversals are represented as Python lists, with the elements being the values of the nodes. The output is the root of the constructed binary tree. Note: Assume the inputs are always valid, i.e., there is always a unique binary tree given the input preorder and inorder traversals. Example: Given preorder = [3, 9, 20, 15, 7] inorder = [9, 3, 15, 20, 7], the constructed binary tree is 3 9 20 15Problem 2: convertBSTtoGST Given the root of a binary search tree (BSD, convert it to a greater sum tree {CST} such that for each node in the HST, its value on! is updated to the sum of all values greater than or equal to mil. Note: 0 Assume thevalues ofall nodes are disnct. - You may change the values of the input BST directly or may create a new In'ee as the output. Either way, you need to return the root of the G511 Example: Given the root of the following EST: theGST is: Follow up: not as a requirement for the homework, but the problem as a DUI} solution (9: is the number of nodes in the input BSD. Can you gure it out? BinaryTreeNode class class BinaryTreeNode: def init_(self, data) : self . val = data # the data the node holds self . left = None # a pointer to the left child self . right = None 1. Reconstruct Binary Tree def reconstructBT (preorder, inorder ) : 2. Convert Binary Search Tree def convertBSTtoGST (root ) : 3. Top k Frequent Elements def kFrequent (nums, k) : 4. All paths from one vertex to another in DAG def allpaths (edges, source, destination)

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 Programming Questions!