Question: PART OF WORDPATH CLASS while (!queue.isEmpty()) { Node node = queue.poll(); ui.sendMessage(Polled); System.out.println(DEQUEUE: + node.word); 10 Add code to WordPath so it displays a

PART OF WORDPATH CLASS

while (!queue.isEmpty()) {

Node node = queue.poll();

ui.sendMessage("Polled");

System.out.println("DEQUEUE: " + node.word);

PART OF WORDPATH CLASS while (!queue.isEmpty()) { Node node = queue.poll(); ui.sendMessage("Polled");

10 Add code to WordPath so it displays a message about how many times it polls the queue (Poll is expensive because you have the check the entire dictionary for neighbors. Add a class Nodecomparator that implements Comparator using your Comparator (Check the documentation. this constructor also requires an initial capacity Use 1000.) How many words does it dequeue now? 11 Now switch to using your Heap using your Comparator It should run the same. Switch back to PriorityQueue for the next part 12 Unfortunately, you will also notice that the solution for "snow" to "rain" is LONGER than before Here is how to fix this Implement the remove method in Heap When WordPath solve dequeues a node and looks at all elements of the dictionary for neighbors it SHOULD look at next nodes which have next .previous set already. If distanceTostart node)+1 distanceTostart (next) then setting next.previous node will give next a shorter path back to start. First, remove next from the heap then change next previous and finally put it back into the heap solve should now find the same length solution for snow to rain but de queue far fewer words than the prog solve Switch back to Heap and make sure it still works right

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 Databases Questions!