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 ;
@Override
public boolean addString word
TODO Autogenerated method stub
@Override
public boolean advancechar c
TODO Autogenerated method stub
@Override
public void retreat
TODO Autogenerated method stub
@Override
public void reset
TODO Autogenerated method stub
currentPrefix.setLength;
currentNode null;
@Override
public boolean isWord
return currentNode null && currentNode.isWord;
@Override
public void add
TODO Autogenerated method stub
@Override
public int getNumberOfPredictions
TODO Autogenerated method stub
if currentNode null
return ;
return currentNode.size;
@Override
public String retrievePrediction
TODO Autogenerated method stub
@Override
public ArrayList retrievePredictions
TODO Autogenerated method stub
private void collectDLBNode x ArrayList arr, StringBuilder scout
TODO Autogenerated method stub
@Override
public boolean deleteString word
TODO Autogenerated method stub
throw new UnsupportedOperationExceptionUnimplemented 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; doublylinked list of siblings
private DLBNode previousSibling;
private DLBNode child; child reference
private DLBNode parent; parent reference
private DLBNodechar dataconstructor
this.data data;
size ;
isWord false;
Adds a word to the dictionary in Oalphabet sizewordlength 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 addString word;
Appends a character to the running prefix in Oalphabet 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 advancechar c;
Removes the last character from the running prefix in Oalphabet 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 time
public void reset;
Checks if the running prefix is a word in the dictionary in 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 alphabet sizelength of the running prefix
public void add;
Retrieves the number of dictionary words that start with the running prefix in time.
@return the number of dictionary words that start with the running
prefix including the running prefix if it is a word
public int getNumberOfPredictions;
Retrieves one dictionary word that starts with the running prefix. The running time is
Olength 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
Olength 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 Oalphabet sizewordlength 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
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
