Question: PYTHON PLS Write a function that takes a root node as input, and returns a string with the values of the tree in depth first
PYTHON PLS
Write a function that takes a root node as input, and returns a string with the values of the tree in depth first pre-order (root, then left subtree, then right subtree), separated by spaces
tree1= TreeNode('1', TreeNode('2', TreeNode('3'), TreeNode('4')), TreeNode('5', TreeNode('6'), TreeNode('7'))) print(preorder(tree)) #tree2 = TreeNode('1', TreeNode('2', TreeNode('3', TreeNode('4'))), TreeNode('5', TreeNode('6', TreeNode('7')))) #tree3 = TreeNode('1', TreeNode('401', TreeNode('349', TreeNode('90'))), TreeNode('88')) #tree4 = TreeNode('1', TreeNode('2', TreeNode('3', TreeNode('4')), TreeNode('5', TreeNode('6', TreeNode('7')), TreeNode('8'))))
# # Your previous Plain Text content is preserved below: # # Given a node definition # interface TreeNode { # left?: TreeNode; # right?: TreeNode; # value: string; # } # #Write a function that takes a root node as input, and returns a string with the values of the tree in depth first pre-order (root, then left subtree, then right subtree), separated by spaces # # # Input 1 # 1 # /\ # 2 5 # /\ /\ # 3 4 6 7 # # Input 2 # 1 # / \ # 2 5 # / / # 3 6 # / / # 4 7 # # Input 3 # 1 # / \ # 401 88 # / # 349 # / # 90 # # Input 4 # # 1 # / # 2 # / \ # 3 5 # / / \ # 4 6 8 # / # 7 # # Output 1 -> "1 2 3 4 5 6 7" # Output 2 -> "1 2 3 4 5 6 7" # Output 3 -> "1 401 349 90 88" # Output 4 -> "1 2 3 4 5 6 7 8"
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
