Question: Hello Chegg Experts, I do not know why lately you have not responded to my questions I have already asked a number of questions and
Hello Chegg Experts, I do not know why lately you have not responded to my questions I have already asked a number of questions and have not received any answers at all In the first month of subscribing with you, I really enjoyed it I want to continue to be a subscriber with you, and it depends only on you !!
I have a question here in JAVA On the subject of list and efficiency
The restaurants are closed and can only be bought at Take Away. Suppose that in every restaurant you can buy only its flagship dish in this way. That is, only one dose. Of course it is possible that several restaurants will offer the same dish.
Joss decided to bring food for the family. He organized the various restaurants in his neighborhood on a doubly linked list, according to their addresses, with each restaurant represented as one link in the list. Each link is an object in the RestaurantNodeTwo class. The object in the class has different attributes, but we are only interested in the food_ attribute which is of the String type, and two other attributes that point to the next link next_ and the previous link prev_ which are of the RestaurantNodeTwo type.
In the question below, we will mark the limbs of the list as strings that are in the vertebrae when separated by commas, inside curly brackets.
For example, we {{Pizza "," Falafel ", Steak", "Salad"} mark the list below (the first string on the left, "Pizza", is the string in the object at the top of the head_ list, and the first string on the right, "Salad", is the string in the object At the end of the list, tail_):
Given the department RestaurantNodeTwo which represents one link in the two-way list.
In the class there is a constructor that gets a string, and builds a link that in its food_ field will be the string received as a parameter, and in the fields that point to the next link and the previous link will be null. The other fields in the squad do not interest us in this question.
Methods of the RestaurantNodeTwo Department:
GetFood, getNext, getPrev retrieval methods
Update methods setFood, setNext, setPrev
Given the RestaurantListTwo department which represents a two-way list.
The class has two attributes that indicate objects from the RestaurantNodeTwo class:
head_ which indicates the beginning of the list and tail_ which indicates the end.
The class also has an empty constructor, which builds an empty list, where both head_ and tail_ indicate null.
Assume that the class also has a method that adds values to the list. You do not have to worry about that.
Joss wants to buy two certain dishes, and looks for them among the different restaurants. He does not want to go far, so is looking for two restaurants at the shortest distance on the list that have the foods he wants to buy.
You must add to the RestaurantListTwo class a method that gets two x and y strings. The strings represent the names of the foods that Joss is looking for. The method should return the minimum distance in terms of links between these two strings (regardless of the order between them, who appears first and who later) in the two-way list on which the method operates. It can be assumed that the strings x and y are not equal to each other. If one (or both) of the strings are not in the list, the value Integer.MAX_VALUE (the maximum possible integer) will be returned.
For example,
If the list list is this:
{"Pizza", "Falafel", Steak "," Salad "," Falafel "," Schnitzel "," Shawarma "," Pasta "," Hamburger "}
If the x and y strings are: "x =" Falafel ", y =" Hamburger "
The string "Falafel" is listed in Squads 2 and 5
The string "Hamburger" is listed in Squad 9
Therefore the minimum distance between "Falafel" and "Hamburger" in the list is 4 (between Squadron 5 and Squadron 9).
The method will return 4
If the strings x and y are: "x =" Hamburger ", y =" French Fries "
The method will return Integer.MAX_VALUE (because the string "French Fries" is not in the list)
The signature of the method is:
public int findMinDiff (String x, String y)
pay attention:
The method you write should be as effective as possible, both in terms of time complexity and place complexity. An answer that is not efficient enough means that it will be more complicated than the one required to solve the problem will get only a few points.
What are the running time complications and place complications of the method you wrote? Explain your answer.
Do not forget to document what you wrote!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
