The BST index is implemented as a stand-alone class BSTIndex, with an inner class Node. Each...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
The BST index is implemented as a stand-alone class BSTIndex, with an inner class Node. Each node within a BSTIndex tree contains 4 fields: key (of type String), data (of type MovieInfo), and left and right links to the children nodes. The BST index tree should never contain duplicate nodes; i.e. each node key needs to be unique across the tree. You will complete the implementation of the following methods and operations in class BSTIndex. All BST operations should be implemented using recursion. ⚫ [20 points] public int calcHeight() • This method should calculate and return the height of the current BSTIndex tree. We define the height of a tree (similar to our lecture slides) as the maximum depth in the tree plus 1. The height of a tree with only one node is 1, and the height of an empty tree is 0. Important: Notice that this is a public method that calls another private method calcNode- Height(Node t) and passes it a reference to the root. This is a common way of structuring BST methods such that external client code will not have direct access to the tree root. You will thus be implementing the code in the private calcNodeHeight (Node t) method. This applies to the rest of the methods in this assignment as well. [15 points] public void insert Movie (Movie Info data) This method should insert the given data element into the proper place in the BST structure. If the input file turned out to have duplicate keys (i.e. repeated short movie titles), then your insertion method should detect that and not add the new duplicated movie to the tree. [20 points] public Movie Info find Movie (String key) This method should return the data element (i.e. the MovieInfo object) of the node where the movie's shortTitle matches the given key. Return null if the movie is not found. ⚫ [20 points] public ArrayList<String> getMoviesPrefix (String prefixStr) This method should return (as an ArrayList) all movies (i.e., full title) in the tree whose • [15 points] public ArrayList<Integer> inorderTraversal () This method should traverse the tree in order and return the IDs of the movie based on the key order of the tree.) The IndexTester class is provided which will test your BSTIndex class. The IndexTester creates an empty BSTIndex object then reads the data from an input movie file, builds a MovieInfo object for each row, and inserts it into the BST index (using the insert method you implemented in BSTIndex class). At this point, the BST index will be built for all the movie entries in the file. Then, the program will ask the user to enter a string. The code for parsing the input string and deciding which operation to invoke is part of the starter code. Here's an example of how a program run might look like. Note that the data file name is passed as an argument to the program's main() method here using the command line: > java IndexTester data/movies100K.txt Inserted 10000 records. Inserted 20000 records. Inserted 30000 records. Inserted 40000 records. Inserted 50000 records. Inserted 60000 records. Inserted 70000 records. Inserted 80000 records. Inserted 90000 records. Inserted 100000 records. Index building complete. Inserted 100000 records. Elapsed time = here> seconds. Welcome to the IMDB movie search engine! - Enter search string to find a specific movie. <your_result_ - Enter search string ending with '*' to print all movies that match this prefix - Enter 'h' to print tree height. Enter 'q' to quit. Enter Option: h Height of BSTIndex tree = <your_result_here> Enter Option: Gang Movie Gang Not Found Enter Option: Gang* [Finding all movies that start with Gang..] Gang tai Gang Gangster Squad Gang Wars Gangotri <rest_of_matches_here> Enter Option: q The BST index is implemented as a stand-alone class BSTIndex, with an inner class Node. Each node within a BSTIndex tree contains 4 fields: key (of type String), data (of type MovieInfo), and left and right links to the children nodes. The BST index tree should never contain duplicate nodes; i.e. each node key needs to be unique across the tree. You will complete the implementation of the following methods and operations in class BSTIndex. All BST operations should be implemented using recursion. ⚫ [20 points] public int calcHeight() • This method should calculate and return the height of the current BSTIndex tree. We define the height of a tree (similar to our lecture slides) as the maximum depth in the tree plus 1. The height of a tree with only one node is 1, and the height of an empty tree is 0. Important: Notice that this is a public method that calls another private method calcNode- Height(Node t) and passes it a reference to the root. This is a common way of structuring BST methods such that external client code will not have direct access to the tree root. You will thus be implementing the code in the private calcNodeHeight (Node t) method. This applies to the rest of the methods in this assignment as well. [15 points] public void insert Movie (Movie Info data) This method should insert the given data element into the proper place in the BST structure. If the input file turned out to have duplicate keys (i.e. repeated short movie titles), then your insertion method should detect that and not add the new duplicated movie to the tree. [20 points] public Movie Info find Movie (String key) This method should return the data element (i.e. the MovieInfo object) of the node where the movie's shortTitle matches the given key. Return null if the movie is not found. ⚫ [20 points] public ArrayList<String> getMoviesPrefix (String prefixStr) This method should return (as an ArrayList) all movies (i.e., full title) in the tree whose • [15 points] public ArrayList<Integer> inorderTraversal () This method should traverse the tree in order and return the IDs of the movie based on the key order of the tree.) The IndexTester class is provided which will test your BSTIndex class. The IndexTester creates an empty BSTIndex object then reads the data from an input movie file, builds a MovieInfo object for each row, and inserts it into the BST index (using the insert method you implemented in BSTIndex class). At this point, the BST index will be built for all the movie entries in the file. Then, the program will ask the user to enter a string. The code for parsing the input string and deciding which operation to invoke is part of the starter code. Here's an example of how a program run might look like. Note that the data file name is passed as an argument to the program's main() method here using the command line: > java IndexTester data/movies100K.txt Inserted 10000 records. Inserted 20000 records. Inserted 30000 records. Inserted 40000 records. Inserted 50000 records. Inserted 60000 records. Inserted 70000 records. Inserted 80000 records. Inserted 90000 records. Inserted 100000 records. Index building complete. Inserted 100000 records. Elapsed time = here> seconds. Welcome to the IMDB movie search engine! - Enter search string to find a specific movie. <your_result_ - Enter search string ending with '*' to print all movies that match this prefix - Enter 'h' to print tree height. Enter 'q' to quit. Enter Option: h Height of BSTIndex tree = <your_result_here> Enter Option: Gang Movie Gang Not Found Enter Option: Gang* [Finding all movies that start with Gang..] Gang tai Gang Gangster Squad Gang Wars Gangotri <rest_of_matches_here> Enter Option: q
Expert Answer:
Answer rating: 100% (QA)
Heres a breakdown of the functionalities mentioned in the image BSTIndex is a class that represents a Binary Search Tree A Binary Search Tree BST is a tree data structure where each node has at most t... View the full answer
Related Book For
Practical Introduction To Data Structures And Algorithm Analysis Java Edition
ISBN: 9780136609117
1st Edition
Authors: Clifford A. Shaffer
Posted Date:
Students also viewed these programming questions
-
answer the question clearly You are building a flight-control system for which a convincing safety case must be made. Would you assign the tasks of safety requirements engineering, test case...
-
Accounting Today identified top accounting firms in 10 geographic regions across the United States. All 10 regions reported growth in 2016. The Southeast and Gulf Coast regions reported growths of...
-
Perfect Ponds Inc. (PPI) is a backyard pond design and installation company. PPI was incorporated during 2017, with an unlimited number of common shares, and 50,000 preferred shares with a $3...
-
Consider the interconnection of LTI system as shown in figure (a) Express the overall impulse response in terms of h1 (n), h2 (n), h3 (n), and h4 (n). (b) Determine h(n) when (c) Determine the...
-
Discuss the use of fuels and their classifications.
-
Explain two types of team-building activities described in this chapter.
-
What is the difference between a stack and a queue data structure?
-
Kate Jackson, a new staff accountant, is confused because of the complexities involving accounting standard setting. Specifically, she is confused by the number of bodies issuing financial reporting...
-
Chemco Incorporated manufacturers a single product that passes through four sequential processes. Accounting and production data for August for Department 3 are as follows: Work in Process, August 1...
-
It is understood that every bank has an asset/liability management committee (ALCO). What are their responsibility and why is it important that a bank utilize their ALCO?
-
How do businesses strategically leverage synergies across diverse business units, functions, and geographies to achieve enhanced operational efficiencies, economies of scale, and competitive...
-
Discuss the analysis aspects related to the costs, paybacks, and benefits of: a. A new system being developed and viewed as a capital investment b. A project viewed as a budgeted expense that...
-
Two pounds of flour cost $1.20. How much flour do you get per dollar? Round your answer to the nearest hundredth, if necessary.
-
AE 433 Consider a single stage of a compressor. At the radial location r= 0.75 m, the rotor rotational speed is 2500 rpm, To = 350 K, C1z = C2 = 150 m/s, a = 35, Bz = 10, where subscripts 1and 2...
-
Logarithmic differentiation Take the logarithm of both sides of the following equation. Then apply the rules for logarithms to simplify the right-han side. x3 e4x y = x +1 { y = [(x^3 e^(4x) ) /...
-
In Exercises 1-2, rewrite each verbal statement as an equation. Then decide whether the statement is true or false. Justify your answer. 1. The logarithm of the difference of two numbers is equal to...
-
Implement a priority queue class based on the max-heap class implementation of Figure 5.19. The following methods should be supported for manipulating the priority queue: void enqueue(int ObjectID,...
-
What fraction of the values in a matrix must be zero for the sparse matrix representation of Section 12.2 to be more space efficient than the standard two-dimensional matrix representation when data...
-
Most programming languages have a built-in integer data type. Normally this representation has a fixed size, thus placing a limit on how large a value can be stored in an integer variable. Describe a...
-
Perform the indicated operations, if defined, for the following vectors and matrices. \(\mathbf{A}\left(\mathbf{B A}+\mathbf{v} \mathbf{w}^{T} ight)\) -2 1 -3 1 1 A = 1 -3 2 1 32 B = V= W = 0 0 4 5
-
Perform the indicated operations, if defined, for the following vectors and matrices. \(\left(\mathbf{A}^{2}+\mathbf{B}^{T} \mathbf{B} ight) \mathbf{W}\) -2 1 -3 1 1 A = 1 -3 2 1 32 B = V= W = 0 0 4 5
-
Perform the indicated operations, if defined, for the following vectors and matrices. \(\mathbf{v}^{T} \mathbf{B} \mathbf{w}\) -2 1 -3 1 1 A = 1 -3 2 1 32 B = V= W = 0 0 4 5
Study smarter with the SolutionInn App