Question: BackgroundThe binary tree is one of the most common and important data structures in Computer Science. It isdefined recursively in terms of itself and therefore,

BackgroundThe binary tree is one of the most common and important data structures in Computer Science. It isdefined recursively in terms of itself and therefore, many of the algorithms that manipulate binary treesare recursive as well. For this assignment, you will implement several shorter recursive algorithms or theirnon-recursive versions to answer problems that are based on the binary tree.Problem 0Review the basic template for the binary tree given on Blackboard under Assignments -> Assignment 3(Binary Trees). This will serve as the framework for the following problems.Problem 1(18 marks)The inorder traversal of a binary tree can be implemented non-recursively without the help of a stack. Itis called the Morris Traversal and is based on the idea of a threaded binary tree. Take some time toresearch the Morris Traversal and then complete the following three tasks.a)(4 marks) Demonstrate on paper how the Morris Traversal works on a complete binary tree witha depth of 3.b)(2 marks) State one key advantage of the Morris Traversal over the standard inorder traversalseen in class.c) Implement the Morris Traversal (10 marks) and verify its results with the standard inordertraversal (2 marks). Make sure that the original binary tree is reinstated after the Morris Traversalis performed.
Problem 2(21 marks)We know from class that a unique binary tree can be built from an inorder traversal paired with either apre- or postorder traversal. A binary search tree, on the other hand, requires only a pre- or postordertraversal since the inorder traversal is implicit. Keeping this in mind, complete the following four tasks.a)(4 marks) Show on paper that if the preorder traversal, stored in an array, is correctly formulated,the unique binary search tree can be built by inserting the items of the preorder traversal oneafter the other into an initially empty binary search tree.b)(2 marks) Give an example of a preorder traversal that is incorrectly formulated.c)(2 marks) Using the big-Oh notation, state with justification the time complexity to build thebinary search tree in part a) from a preorder traversal with n items.d) Implement (10 marks) and test (3 marks) an alternate way to build the binary search tree given apreorder traversal that only requires O(n) time. If the binary search tree cannot be built, outputa message.

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!