Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN JAVA: Functions allowed in algorithm: left and right rotations on T1 find (key) getInOrder() getPreOrder() Node class Driver Class Given: private static final int

IN JAVA:

image text in transcribed

Functions allowed in algorithm:

left and right rotations on T1

find (key)

getInOrder()

getPreOrder()

Node class

Driver Class Given:

private static final int LabNo = 1; private static final Random rng = new Random(190718); private static boolean testProblem(int[][] testCase) { int[] arr1 = testCase[0]; int[] arr2 = testCase[1]; // --- Build tree --- BST tree1 = new BST(); BST tree2 = new BST(); for (int i = 0; i Problem You are given two non-empty binary search tree Tand T. Ty and T, store the same keys. The structure of both trees, however, is different. Implement an algorithm that uses rotations on T to make it equivalent to Tg. That is, both trees should have identical structure. Note that you are only allowed to use rotations and only on Ti; you are not allowed to modify the trees in any other way. There is no strict overall runtime for this assignment. You should still try to keep it as low as possible. Very slow implementations will still result in a loss of points. Implementation You are given two files (which you can download from canvas): Lab1.java and BST.java. The file Lab1.java generates test cases, performs the tests, and outputs the results. The file BST.java partially implements a binary search tree and contains the function problem; implement your solution in that function. Do not make any changes outside of that function; such changes will be undone. Do not output anything to the terminal. The class BST also contains the functions rotatel, rotater, find, as well as functions for in- and pre-order. Feel free to use these functions in your implementation The program already implemented in the file Lab1.java randomly generates test cases. The seed of the random number generator is set to ensure the same test cases whenever to program is executed. Note that the purpose of the tests is for you to avoid major mistakes. Passing all given tests does not imply that your algorithm is correct, especially that is has the expected runtime

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Database Horse Betting The Road To Absolute Horse Racing 2

Authors: NAKAGAWA,YUKIO

1st Edition

B0CFZN219G, 979-8856410593

More Books

Students also viewed these Databases questions

Question

=+ What are the information and consultation requirements?

Answered: 1 week ago

Question

=+ Should the MNE belong (why, why not)?

Answered: 1 week ago