I am having trouble coming up with a predict function for my program.I am missing the predict function. I have coded up everything else. I have attached the assignment instruction and attached my code. I also have attched the instructors notes on the predict function,. Please come up with the predict function. Please use Java. Thanks.
Assigment:
Instructors Notes:
My Code in JAVA :
/*-----------------------------------Java implementation of Trie---------------------------------------------------------------*/
public class Trie {
//----------------------------The Alphabet Size (# of
symbols)----------------------------------------------------------//
static final int ALPHABET_SIZE = 26;
//--------------------------------The node of
Trie-------------------------------------------------------------------//
static class TrieNode
{
TrieNode[] children = new
TrieNode[ALPHABET_SIZE];
//--------------------------------------isEndOfWord is
true if the node represents the end of a
word-------------------------------//
boolean isEndOfWord;
int count;
TrieNode(){
isEndOfWord = false;
for (int i = 0; i < ALPHABET_SIZE; i++)
children[i] = null;
count = 0;
}
};
static TrieNode root;
//-------------------------------------If the key is
not present, inserts key into
trie-------------------------------------------//
//-------------------------------------If the key is
prefix of trie node,just marks leaf
node-------------------------------------//
static void insert(String key)
{
int level;
int length = key.length();
int index;
TrieNode pCrawl = root;
for (level = 0; level < length; level++)
{
index = key.charAt(level) - 'a';
if (pCrawl.children[index] == null)
pCrawl.children[index] = new TrieNode();
pCrawl.count +=1;
pCrawl = pCrawl.children[index];
}
}
//-----------------------------------------PREDICT
FUNCTION----------------------------------//
static void predict (String key, int top )
{
int level;
int length = key.length();
int index;
TrieNode pCrawl = root;
for (level = 0; level < length; level++)
{
index = key.charAt(level) - 'a';
if (pCrawl.children[index] == null)
pCrawl.children[index] = new TrieNode();
pCrawl = pCrawl.children[index];
String [3];
results [0] = the
results [1] = there
result [2] = them
for level < length; level++)
index
}
//----------------------------Marks the last node as
leaf--------------------------------//
TrieNode pCrawl1 =root;
pCrawl1.isEndOfWord = true;
}
//-------------------------Returns true if key
presents in trie, else false----------------------//
static boolean find(String key)
{
int level;
int length = key.length();
int index;
TrieNode pCrawl = root;
for (level = 0; level < length; level++)
{
index = key.charAt(level) - 'a';
if (pCrawl.children[index] == null)
return false;
pCrawl = pCrawl.children[index];
}
return pCrawl.isEndOfWord;
}
}
//-----------------------------------------------------------This is the end of the program---------------------------------------------------------------------------//