Question: The following algorithm takes a non-empty proper binary tree and prints it. You may wish to recall that a proper binary tree is a binary

 The following algorithm takes a non-empty proper binary tree and prints

The following algorithm takes a non-empty proper binary tree and prints it. You may wish to recall that a proper binary tree is a binary tree in which each node is either external or has exactly two children. The expression newlndent + indent + " "creates a new string that contains the characters in the string indent appended by the single space character and assigns it to the variable newlndent. The string indent is not modified by the assignment: the characters from it are copied over to the newly created string. Algorithm: print(tree) return printHelper(tree, tree.root(), "") Algorithm: printHelper(tree, node, indent) System.out.println(indent); System.out.println(node.getElement()); if tree.isInternal(node) then newIndent + indent + "" printHelper(tree, tree.leftChild(node), newIndent) printHelper(tree, tree.rightChild(node), newIndent) return b) What is the maximum height of a non-empty proper binary tree containing n nodes in total? Count the height of a leaf node as being 0. (2 marks) c) What is the worst-case time complexity of the above algorithm print, given that there are n nodes in the parameter tree and that each element in a node is a string of no more than 30 characters? Express your answer in terms of n in big-o notation, making the bound as tight as possible and simplifying your answer as much as possible. Briefly justify your answer and give an example tree of n=7 nodes that would exhibit the worst-case time complexity. (2 marks) d) What is the worst-case space complexity of the above algorithm print, given that there are n nodes in the parameter tree and that each element in a node is a string of no more than 30 characters? Assume that the parameters in the algorithm and its helper algorithm are passed by reference. Do not include the space already consumed by the tree in your calculation. Express your answer in terms of n in big-O notation, making the bound as tight as possible and simplifying your answer as much as possible. Briefly justify your answer and give an example tree of n=7 nodes that would exhibit the worst-case space complexity. (3 marks) The following algorithm takes a non-empty proper binary tree and prints it. You may wish to recall that a proper binary tree is a binary tree in which each node is either external or has exactly two children. The expression newlndent + indent + " "creates a new string that contains the characters in the string indent appended by the single space character and assigns it to the variable newlndent. The string indent is not modified by the assignment: the characters from it are copied over to the newly created string. Algorithm: print(tree) return printHelper(tree, tree.root(), "") Algorithm: printHelper(tree, node, indent) System.out.println(indent); System.out.println(node.getElement()); if tree.isInternal(node) then newIndent + indent + "" printHelper(tree, tree.leftChild(node), newIndent) printHelper(tree, tree.rightChild(node), newIndent) return b) What is the maximum height of a non-empty proper binary tree containing n nodes in total? Count the height of a leaf node as being 0. (2 marks) c) What is the worst-case time complexity of the above algorithm print, given that there are n nodes in the parameter tree and that each element in a node is a string of no more than 30 characters? Express your answer in terms of n in big-o notation, making the bound as tight as possible and simplifying your answer as much as possible. Briefly justify your answer and give an example tree of n=7 nodes that would exhibit the worst-case time complexity. (2 marks) d) What is the worst-case space complexity of the above algorithm print, given that there are n nodes in the parameter tree and that each element in a node is a string of no more than 30 characters? Assume that the parameters in the algorithm and its helper algorithm are passed by reference. Do not include the space already consumed by the tree in your calculation. Express your answer in terms of n in big-O notation, making the bound as tight as possible and simplifying your answer as much as possible. Briefly justify your answer and give an example tree of n=7 nodes that would exhibit the worst-case space complexity

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!