Question: Please help me to implement these methods, I already finished the reset and isWord, and I attach the screenshot of the interface. The size for

Please help me to implement these methods, I already finished the reset and isWord, and I attach the screenshot of the interface. The size for this project is measure how many words can be formed using this letter as the prefix.
import java.util.ArrayList;
public class AutoComplete implements AutoCompleteInterface {
private DLBNode root; //root of the DLB Trie
private StringBuilder currentPrefix; //running prefix
private DLBNode currentNode; //current DLBNode
//TODO: Add more instance variables as needed
public AutoComplete(){
this.root = null;
this.currentPrefix = new StringBuilder();
this.currentNode = null;
this.counter =0;
}
@Override
public boolean add(String word){
// TODO Auto-generated method stub
}
@Override
public boolean advance(char c){
// TODO Auto-generated method stub
}
@Override
public void retreat(){
// TODO Auto-generated method stub
}
@Override
public void reset(){
// TODO Auto-generated method stub
currentPrefix.setLength(0);
currentNode = null;
}
@Override
public boolean isWord(){
return currentNode != null && currentNode.isWord;
}
@Override
public void add(){
// TODO Auto-generated method stub
}
@Override
public int getNumberOfPredictions(){
// TODO Auto-generated method stub
if (currentNode == null){
return 0;
}
return currentNode.size;
}
@Override
public String retrievePrediction(){
// TODO Auto-generated method stub
}
@Override
public ArrayList retrievePredictions(){
// TODO Auto-generated method stub
}
private void collect(DLBNode x, ArrayList arr, StringBuilder scout){
// TODO Auto-generated method stub
}
@Override
public boolean delete(String word){
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'delete'");
}
//The DLBNode class
private class DLBNode{
private char data; //letter inside the node
private int size;//number of words in the subtrie rooted at node
private boolean isWord; //true if the node is at the end of a word
private DLBNode nextSibling; //doubly-linked list of siblings
private DLBNode previousSibling;
private DLBNode child; // child reference
private DLBNode parent; //parent reference
private DLBNode(char data){//constructor
this.data = data;
size =0;
isWord = false;
}
}
```
* Adds a word to the dictionary in O(alphabet size*word.length()) time
* @param word the String to be added to the dictionary
* @return true if add is successful, false if word already exists
* @throws IllegalArgumentException if word is the empty string or null
*/
public boolean add(String word);
/**
* Appends a character to the running prefix in O(alphabet size) time.
* This method doesn't modify the dictionary.
* @param c: the character to append
* @return true if the running prefix after appending c is a prefix to a word
* in the dictionary and false otherwise
*/
public boolean advance(char c);
/**
* Removes the last character from the running prefix in O(alphabet size)
* time. This method doesn't modify the dictionary.
* @throws IllegalStateException if the running prefix is the empty string
*/
public void retreat();
/**
* Resets the current prefix to the empty string in O(1) time
*/
public void reset();
/**
* Checks if the running prefix is a word in the dictionary in 0(1) time.
* @return true if the running prefix is a word in the dictionary and false
* otherwise.
*/
public boolean isWord();
``````
/**
* Adds the running prefix as a word to the dictionary (if not already a word)
* The running time is 0(alphabet size*length of the running prefix).
*/
public void add();
/**
* Retrieves the number of dictionary words that start with the running prefix in 0(1) time.
* @return the number of dictionary words that start with the running
* prefix (including the running prefix if it is a word).
*/
8 public int getNumberOfPredictions();
/**
* Retrieves one dictionary word that starts with the running prefix. The running time is
* O(length of the returned word)
* @return a String or null if no predictions exist for the running prefix
*/
public String retrievePrediction();
/**
* Retrieves a lexicographically sorted list of all dictionary words that start with the running
* O(length of the returned words)
* @return an ArrayList of sorted word predictions or null if no predictions exist for t
*/
public ArrayList retrievePredictions();
/**
* EXTRA CREDIT: Deletes a word from the dictionary in O(alphabet size*word.length()) time.
* @param word the String to be deleted from the dictionary
* @return true if delete is successful, false if word doesn't exist
* @throws IllegalArgumentException if word is the empty s
Please help me to implement these methods, I

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