Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please I need help with this question. Thank you so much! 3. [Binary Search Trees, 60 points] Consider two binary search trees that contain the

Please I need help with this question. Thank you so much!

image text in transcribed

3. [Binary Search Trees, 60 points] Consider two binary search trees that contain the same set of unique keys, possibly in different orders. a. Devise and analyze an efficient algorithm that will transform any given binary search tree into any other binary search tree (with the same keys) using only ZIG and ZAG rotations The provided BST.h, and BST.cpp files contain a BST class, implementing a binary search tree, and a Rotation class, which stores a rotation. Implement a new derived class of BST, MyBST, which extends the binary search tree with a transform method, which implements your algorithm from part (a) You should also implement a main function, which receives two files, T1.txt and T2.txt (you may assume that these will be the names of the input files), containing one integer per line, to be inserted in order into two binary search trees. The transform method should receive the BSTs generated from T1 and T2, and return a vector of rotations required to transform T1 into T2, which is then printed out. You may not modify BST.h and BST.cpp, but you may add methods to MyBST.cpp as you see fit (and add a MyBST.h file) b. Assuming that the required rotations are a ZIG rotation on pivot-3, followed by a ZAG rotation on pivot-8, your output should be as follows ZIG on 3 ZAG on8 To get full credit your solution must work on any two binary search trees that contain exactly the same set of keys

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions