SlideShare a Scribd company logo
1 of 7
Download to read offline
Description of the project
Purpose: To implement a simple automatic word-completion system.
Task 1: Implement algorithms for DLB insertion and traversal.
Task 2: Implement an algorithm for retrieving one word prediction.
Background
Autocomplete is a commonly used feature in mobile phones, text editors, and search engines. As
a user types in letters, the system shows a list of word predictions to help the user complete the
word they are typing. The core of an efficient autocompletion system is a fast algorithm for
retrieving word predictions based on the user input. The word predictions are all the words (in a
given dictionary) that start with what the user has typed so far (i.e., the list of words for which the
user's input is a prefix).
In this assignment we will build a simple autocompletion system using a DLB trie which allows the
user to add a new word to its dictionary when none of the predictions are selected by the user.
The AutoCompleteInterface defines a Java interface for a dictionary that provides word predictions
for such an autocompletion system. Besides storing a set of words, the dictionary keeps track of a
prefix String, which starts with the empty String. You will implement methods to add one character
to and delete the last character of that prefix String. You will also implement methods that use that
prefix String for various operations, such as checking if the prefix String is one of the words in the
dictionary, retrieving the number of words that have the prefix String as a prefix, and adding the
prefix String to the dictionary.
Details
In the first part of this assignment, you will implement algorithms for:
inserting a StringBuilder object into a DLB trie by filling in the add(String word) method below. You
may want to add and call a private recursive helper method.
The DLBNode class is already defined for you in AutoComplete.java. You will use a doubly-linked
list of siblings, a child reference, and an upwards reference to the node's parent. The isWord field
of a node is true if and only if the node is at the end of a word in the dictionary. The size field
keeps track of the number of nodes with isWord==true in the subtree rooted at the node, including
the node itself. The add method should update the size field for some of the nodes that it goes
over. You will need to think about for which nodes size should be incremented.
The next set of the methods modify the prefix String maintained by the dictionary. These methods
are: advance(char c) for appending a character to the prefix String, retreat() for deleting the last
character, and reset() for resetting it back to the empty String. More details about these methods
can be found below. Your code should maintain a DLBNode currentNode reference to always
point to the DLB node at the end of the prefix String. currentNode is null when the prefix String is
"", moves over the sibling list of the root node upon the first call to advance, moves possibly
sideways then down the trie with each further call to advance, moves possibly sideways then up
the trie with retreat until resetting to null when the prefix String becomes empty, and resets to null
with reset.
The last set of methods operate on the prefix String by checking whether it is a word in the
dictionary (isWord()), adding it if not (add()), retrieving the number predictions for the prefix String
(getNumberOfPredictions), and retrieving one of the predictions (if any) (retrievePrediction).
Retrieving the number predictions should be as simple as returning the size field of the
currentNode. The add() method should increment the size field for some of the nodes (which
ones?). (Hint: you may need to climb up the trie.)
/**
* An implementation of the AutoCompleteInterface using a DLB Trie.
*/
import java.util.ArrayList;
import javax.xml.crypto.Data;
public class AutoComplete implements AutoCompleteInterface {
private DLBNode root;
private StringBuilder currentPrefix;
private DLBNode currentNode;
private static final char SENTINEL = '^';
//TODO: Add more instance variables as needed
public AutoComplete(){
root = null;
currentPrefix = new StringBuilder();
currentNode = null;
}
/**
* 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
*/
public boolean add(String word){
//TODO: implement this method
recursively with a helper method
}
/**
* appends the character c to the current prefix in O(alphabet size) time.
* This method doesn't modify the dictionary.
* @param c: the character to append
* @return true if the current prefix after appending c is a prefix to a word
* in the dictionary and false otherwise
*/
public boolean advance(char c){
//TODO: implement this method
return false;
}
/**
* removes the last character from the current prefix in O(1) time. This
* method doesn't modify the dictionary.
* @throws IllegalStateException if the current prefix is the empty string
*/
public void retreat(){
//TODO: implement this method
}
/**
* resets the current prefix to the empty string in O(1) time
*/
public void reset(){
//TODO: implement this method
}
/**
* @return true if the current prefix is a word in the dictionary and false
* otherwise. The running time is O(1).
*/
public boolean isWord(){
//TODO: implement this method
return false;
}
/**
* adds the current prefix as a word to the dictionary (if not already a word)
* The running time is O(alphabet size*length of the current prefix).
*/
public void add(){
//TODO: implement this method
}
/**
* @return the number of words in the dictionary that start with the current
* prefix (including the current prefix if it is a word). The running time is
* O(1).
*/
public int getNumberOfPredictions(){
//TODO: implement this method
return 0;
}
/**
* retrieves one word prediction for the current prefix. The running time is
* O(prediction.length())
* @return a String or null if no predictions exist for the current prefix
*/
public String retrievePrediction(){
//TODO: implement this method
return null;
}
/* ==============================
* Helper methods for debugging.
* ==============================
*/
//print the subtrie rooted at the node at the end of the start String
public void printTrie(String start){
System.out.println("==================== START: DLB Trie Starting from ""+ start + ""
====================");
if(start.equals("")){
printTrie(root, 0);
} else {
DLBNode startNode = getNode(root, start, 0);
if(startNode != null){
printTrie(startNode.child, 0);
}
}
System.out.println("==================== END: DLB Trie Starting from ""+ start + ""
====================");
}
//a helper method for printTrie
private void printTrie(DLBNode node, int depth){
if(node != null){
for(int i=0; i<depth; i++){
System.out.print(" ");
}
System.out.print(node.data);
if(node.isWord){
System.out.print(" *");
}
System.out.println(" (" + node.size + ")");
printTrie(node.child, depth+1);
printTrie(node.nextSibling, depth);
}
}
//return a pointer to the node at the end of the start String
//in O(start.length() - index)
private DLBNode getNode(DLBNode node, String start, int index){
if(start.length() == 0){
return node;
}
DLBNode result = node;
if(node != null){
if((index < start.length()-1) && (node.data == start.charAt(index))) {
result = getNode(node.child, start, index+1);
} else if((index == start.length()-1) && (node.data == start.charAt(index))) {
result = node;
} else {
result = getNode(node.nextSibling, start, index);
}
}
return result;
}
//The DLB node class
private class DLBNode{
private char data;
private int size;
private boolean isWord;
private DLBNode nextSibling;
private DLBNode previousSibling;
private DLBNode child;
private DLBNode parent;
private DLBNode(char data){
this.data = data;
size = 0;
isWord = false;
nextSibling = previousSibling = child = parent = null;
}
}
}
the below is the interface
/**
* An interface for a dictionary that provides word suggestions for an
* auto-complete system and maintains a current prefix
*/
public interface AutoCompleteInterface {
/**
* 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
*/
public boolean add(String word);
/**
* appends the character c to the current prefix in O(alphabet size) time.
* This method doesn't modify the dictionary.
* @param c: the character to append
* @return true if the current 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 current prefix in O(alphabet size)
* time. This method doesn't modify the dictionary.
* @throws IllegalStateException if the current prefix is the empty string
*/
public void retreat();
/**
* resets the current prefix to the empty string in O(1) time
*/
public void reset();
/**
* @return true if the current prefix is a word in the dictionary and false
* otherwise. The running time is O(1).
*/
public boolean isWord();
/**
* adds the current prefix as a word to the dictionary (if not already a word)
* The running time is O(alphabet size*length of the current prefix).
*/
public void add();
/**
* @return the number of words in the dictionary that start with the current
* prefix (including the current prefix if it is a word). The running time is
* O(1).
*/
public int getNumberOfPredictions();
/**
* retrieves one word prediction for the current prefix. The running time is
* O(prediction.length())
* @return a String or null if no predictions exist for the current prefix
*/
public String retrievePrediction();
}
complete the todo according the comment given on the interface and the add (string word) method
should be in the similar structure like put method
public void put(String key, Value val) {
if (key == null) throw new IllegalArgumentException("calls put() with a null key");
key = key + SENTINEL;
root = put(root, key, val, 0);
}
private Node put(Node x, String key, Value val, int pos) {
Node result = x;
if (x == null){
result = new Node();
result.letter = key.charAt(pos);
result.level = pos;
if(pos < key.length()-1){
result.child = put(result.child,key ,val ,pos +1);/*TODO: Recurse on the child node*/
} else {
result.val = val;
}
} else if(x.letter == key.charAt(pos)) {
if(pos < key.length()-1){
result.child = put(result.child,key ,val ,pos +1); /*TODO: Recurse on the child node*/
} else {
result.val = val; //update
}
} else {
result.sibling = put(result.sibling, key , val, pos); /*TODO: Recurse on the sibling node*/
}
return result;
}

More Related Content

Similar to Description of the project Purpose To implement a simple au.pdf

computer notes - Data Structures - 5
computer notes - Data Structures - 5computer notes - Data Structures - 5
computer notes - Data Structures - 5ecomputernotes
 
1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answers1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answersAkash Gawali
 
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdfAbstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdfkarymadelaneyrenne19
 
Computer notes - Josephus Problem
Computer notes - Josephus ProblemComputer notes - Josephus Problem
Computer notes - Josephus Problemecomputernotes
 
Question 1 has already been posted to Chegg and I am waiting for the.pdf
Question 1 has already been posted to Chegg and I am waiting for the.pdfQuestion 1 has already been posted to Chegg and I am waiting for the.pdf
Question 1 has already been posted to Chegg and I am waiting for the.pdfanjandavid
 
C++ Notes by Hisham Ahmed Rizvi for Class 12th Board Exams
C++ Notes by Hisham Ahmed Rizvi for Class 12th Board ExamsC++ Notes by Hisham Ahmed Rizvi for Class 12th Board Exams
C++ Notes by Hisham Ahmed Rizvi for Class 12th Board Examshishamrizvi
 
C++ Interview Question And Answer
C++ Interview Question And AnswerC++ Interview Question And Answer
C++ Interview Question And AnswerJagan Mohan Bishoyi
 
C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answerlavparmar007
 
Article link httpiveybusinessjournal.compublicationmanaging-.docx
Article link httpiveybusinessjournal.compublicationmanaging-.docxArticle link httpiveybusinessjournal.compublicationmanaging-.docx
Article link httpiveybusinessjournal.compublicationmanaging-.docxfredharris32
 
Introduction to Intermediate Java
Introduction to Intermediate JavaIntroduction to Intermediate Java
Introduction to Intermediate JavaPhilip Johnson
 
Phyton Learning extracts
Phyton Learning extracts Phyton Learning extracts
Phyton Learning extracts Pavan Babu .G
 

Similar to Description of the project Purpose To implement a simple au.pdf (20)

computer notes - Data Structures - 5
computer notes - Data Structures - 5computer notes - Data Structures - 5
computer notes - Data Structures - 5
 
1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answers1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answers
 
easyPy-Basic.pdf
easyPy-Basic.pdfeasyPy-Basic.pdf
easyPy-Basic.pdf
 
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdfAbstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
 
Computer notes - Josephus Problem
Computer notes - Josephus ProblemComputer notes - Josephus Problem
Computer notes - Josephus Problem
 
Question 1 has already been posted to Chegg and I am waiting for the.pdf
Question 1 has already been posted to Chegg and I am waiting for the.pdfQuestion 1 has already been posted to Chegg and I am waiting for the.pdf
Question 1 has already been posted to Chegg and I am waiting for the.pdf
 
C++ Notes by Hisham Ahmed Rizvi for Class 12th Board Exams
C++ Notes by Hisham Ahmed Rizvi for Class 12th Board ExamsC++ Notes by Hisham Ahmed Rizvi for Class 12th Board Exams
C++ Notes by Hisham Ahmed Rizvi for Class 12th Board Exams
 
C++ Interview Question And Answer
C++ Interview Question And AnswerC++ Interview Question And Answer
C++ Interview Question And Answer
 
C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answer
 
Article link httpiveybusinessjournal.compublicationmanaging-.docx
Article link httpiveybusinessjournal.compublicationmanaging-.docxArticle link httpiveybusinessjournal.compublicationmanaging-.docx
Article link httpiveybusinessjournal.compublicationmanaging-.docx
 
Data Structure
Data StructureData Structure
Data Structure
 
Java 8 new features
Java 8 new featuresJava 8 new features
Java 8 new features
 
LectureNotes-04-DSA
LectureNotes-04-DSALectureNotes-04-DSA
LectureNotes-04-DSA
 
Introduction to Intermediate Java
Introduction to Intermediate JavaIntroduction to Intermediate Java
Introduction to Intermediate Java
 
SQL Joins
SQL JoinsSQL Joins
SQL Joins
 
Test Presentation
Test PresentationTest Presentation
Test Presentation
 
SQL Joins
SQL JoinsSQL Joins
SQL Joins
 
Phyton Learning extracts
Phyton Learning extracts Phyton Learning extracts
Phyton Learning extracts
 
lab4_php
lab4_phplab4_php
lab4_php
 
lab4_php
lab4_phplab4_php
lab4_php
 

More from adcrates2010

Determine si las afirmaciones pertenecen a una poblacin o a.pdf
Determine si las afirmaciones pertenecen a una poblacin o a.pdfDetermine si las afirmaciones pertenecen a una poblacin o a.pdf
Determine si las afirmaciones pertenecen a una poblacin o a.pdfadcrates2010
 
Determine Gales income tax each year from through assumin.pdf
Determine Gales income tax each year from through  assumin.pdfDetermine Gales income tax each year from through  assumin.pdf
Determine Gales income tax each year from through assumin.pdfadcrates2010
 
Depo Ynetim Sistemi depo ynetim sistemi kontrol etmek ii.pdf
Depo Ynetim Sistemi depo ynetim sistemi kontrol etmek ii.pdfDepo Ynetim Sistemi depo ynetim sistemi kontrol etmek ii.pdf
Depo Ynetim Sistemi depo ynetim sistemi kontrol etmek ii.pdfadcrates2010
 
Despus de leer el artculo responda las preguntas que sigu.pdf
Despus de leer el artculo responda las preguntas que sigu.pdfDespus de leer el artculo responda las preguntas que sigu.pdf
Despus de leer el artculo responda las preguntas que sigu.pdfadcrates2010
 
Design Patterns Java An Internet Service Provider ISP no.pdf
Design Patterns Java  An Internet Service Provider ISP no.pdfDesign Patterns Java  An Internet Service Provider ISP no.pdf
Design Patterns Java An Internet Service Provider ISP no.pdfadcrates2010
 
Describe what you think the company is doing right in regard.pdf
Describe what you think the company is doing right in regard.pdfDescribe what you think the company is doing right in regard.pdf
Describe what you think the company is doing right in regard.pdfadcrates2010
 
Describe what is meant by a graded river At steady state i.pdf
Describe what is meant by a graded river At steady state i.pdfDescribe what is meant by a graded river At steady state i.pdf
Describe what is meant by a graded river At steady state i.pdfadcrates2010
 
Describe the properties of a neutron star Density Neutro.pdf
Describe the properties of a neutron star  Density Neutro.pdfDescribe the properties of a neutron star  Density Neutro.pdf
Describe the properties of a neutron star Density Neutro.pdfadcrates2010
 
Design a project document for a Ddos attack detection projec.pdf
Design a project document for a Ddos attack detection projec.pdfDesign a project document for a Ddos attack detection projec.pdf
Design a project document for a Ddos attack detection projec.pdfadcrates2010
 
Describe what a balance sheet tells about a business in your.pdf
Describe what a balance sheet tells about a business in your.pdfDescribe what a balance sheet tells about a business in your.pdf
Describe what a balance sheet tells about a business in your.pdfadcrates2010
 
Design a Data Base many to many each house can have many .pdf
Design a Data Base many to many each house can have many .pdfDesign a Data Base many to many each house can have many .pdf
Design a Data Base many to many each house can have many .pdfadcrates2010
 
Desea revisar las dependencias de tareas en su programa ante.pdf
Desea revisar las dependencias de tareas en su programa ante.pdfDesea revisar las dependencias de tareas en su programa ante.pdf
Desea revisar las dependencias de tareas en su programa ante.pdfadcrates2010
 
Desde una perspectiva muy bsica la respiracincombustin .pdf
Desde una perspectiva muy bsica la respiracincombustin .pdfDesde una perspectiva muy bsica la respiracincombustin .pdf
Desde una perspectiva muy bsica la respiracincombustin .pdfadcrates2010
 
Describe how Nanoporebased nucleic acid sequencing takes ad.pdf
Describe how Nanoporebased nucleic acid sequencing takes ad.pdfDescribe how Nanoporebased nucleic acid sequencing takes ad.pdf
Describe how Nanoporebased nucleic acid sequencing takes ad.pdfadcrates2010
 
Description Find a cybersecurity incident that has recently .pdf
Description Find a cybersecurity incident that has recently .pdfDescription Find a cybersecurity incident that has recently .pdf
Description Find a cybersecurity incident that has recently .pdfadcrates2010
 
Describe a time when you were able to achieve something that.pdf
Describe a time when you were able to achieve something that.pdfDescribe a time when you were able to achieve something that.pdf
Describe a time when you were able to achieve something that.pdfadcrates2010
 
Describe a leader with whom you are familiar You can choose.pdf
Describe a leader with whom you are familiar You can choose.pdfDescribe a leader with whom you are familiar You can choose.pdf
Describe a leader with whom you are familiar You can choose.pdfadcrates2010
 
Description 1 Imagine a young person recently graduated fr.pdf
Description 1 Imagine a young person recently graduated fr.pdfDescription 1 Imagine a young person recently graduated fr.pdf
Description 1 Imagine a young person recently graduated fr.pdfadcrates2010
 
Describe the two escalator model that economists Case and .pdf
Describe the two escalator model that economists Case and .pdfDescribe the two escalator model that economists Case and .pdf
Describe the two escalator model that economists Case and .pdfadcrates2010
 
Describir las caractersticas anatmicas craneales y poscran.pdf
Describir las caractersticas anatmicas craneales y poscran.pdfDescribir las caractersticas anatmicas craneales y poscran.pdf
Describir las caractersticas anatmicas craneales y poscran.pdfadcrates2010
 

More from adcrates2010 (20)

Determine si las afirmaciones pertenecen a una poblacin o a.pdf
Determine si las afirmaciones pertenecen a una poblacin o a.pdfDetermine si las afirmaciones pertenecen a una poblacin o a.pdf
Determine si las afirmaciones pertenecen a una poblacin o a.pdf
 
Determine Gales income tax each year from through assumin.pdf
Determine Gales income tax each year from through  assumin.pdfDetermine Gales income tax each year from through  assumin.pdf
Determine Gales income tax each year from through assumin.pdf
 
Depo Ynetim Sistemi depo ynetim sistemi kontrol etmek ii.pdf
Depo Ynetim Sistemi depo ynetim sistemi kontrol etmek ii.pdfDepo Ynetim Sistemi depo ynetim sistemi kontrol etmek ii.pdf
Depo Ynetim Sistemi depo ynetim sistemi kontrol etmek ii.pdf
 
Despus de leer el artculo responda las preguntas que sigu.pdf
Despus de leer el artculo responda las preguntas que sigu.pdfDespus de leer el artculo responda las preguntas que sigu.pdf
Despus de leer el artculo responda las preguntas que sigu.pdf
 
Design Patterns Java An Internet Service Provider ISP no.pdf
Design Patterns Java  An Internet Service Provider ISP no.pdfDesign Patterns Java  An Internet Service Provider ISP no.pdf
Design Patterns Java An Internet Service Provider ISP no.pdf
 
Describe what you think the company is doing right in regard.pdf
Describe what you think the company is doing right in regard.pdfDescribe what you think the company is doing right in regard.pdf
Describe what you think the company is doing right in regard.pdf
 
Describe what is meant by a graded river At steady state i.pdf
Describe what is meant by a graded river At steady state i.pdfDescribe what is meant by a graded river At steady state i.pdf
Describe what is meant by a graded river At steady state i.pdf
 
Describe the properties of a neutron star Density Neutro.pdf
Describe the properties of a neutron star  Density Neutro.pdfDescribe the properties of a neutron star  Density Neutro.pdf
Describe the properties of a neutron star Density Neutro.pdf
 
Design a project document for a Ddos attack detection projec.pdf
Design a project document for a Ddos attack detection projec.pdfDesign a project document for a Ddos attack detection projec.pdf
Design a project document for a Ddos attack detection projec.pdf
 
Describe what a balance sheet tells about a business in your.pdf
Describe what a balance sheet tells about a business in your.pdfDescribe what a balance sheet tells about a business in your.pdf
Describe what a balance sheet tells about a business in your.pdf
 
Design a Data Base many to many each house can have many .pdf
Design a Data Base many to many each house can have many .pdfDesign a Data Base many to many each house can have many .pdf
Design a Data Base many to many each house can have many .pdf
 
Desea revisar las dependencias de tareas en su programa ante.pdf
Desea revisar las dependencias de tareas en su programa ante.pdfDesea revisar las dependencias de tareas en su programa ante.pdf
Desea revisar las dependencias de tareas en su programa ante.pdf
 
Desde una perspectiva muy bsica la respiracincombustin .pdf
Desde una perspectiva muy bsica la respiracincombustin .pdfDesde una perspectiva muy bsica la respiracincombustin .pdf
Desde una perspectiva muy bsica la respiracincombustin .pdf
 
Describe how Nanoporebased nucleic acid sequencing takes ad.pdf
Describe how Nanoporebased nucleic acid sequencing takes ad.pdfDescribe how Nanoporebased nucleic acid sequencing takes ad.pdf
Describe how Nanoporebased nucleic acid sequencing takes ad.pdf
 
Description Find a cybersecurity incident that has recently .pdf
Description Find a cybersecurity incident that has recently .pdfDescription Find a cybersecurity incident that has recently .pdf
Description Find a cybersecurity incident that has recently .pdf
 
Describe a time when you were able to achieve something that.pdf
Describe a time when you were able to achieve something that.pdfDescribe a time when you were able to achieve something that.pdf
Describe a time when you were able to achieve something that.pdf
 
Describe a leader with whom you are familiar You can choose.pdf
Describe a leader with whom you are familiar You can choose.pdfDescribe a leader with whom you are familiar You can choose.pdf
Describe a leader with whom you are familiar You can choose.pdf
 
Description 1 Imagine a young person recently graduated fr.pdf
Description 1 Imagine a young person recently graduated fr.pdfDescription 1 Imagine a young person recently graduated fr.pdf
Description 1 Imagine a young person recently graduated fr.pdf
 
Describe the two escalator model that economists Case and .pdf
Describe the two escalator model that economists Case and .pdfDescribe the two escalator model that economists Case and .pdf
Describe the two escalator model that economists Case and .pdf
 
Describir las caractersticas anatmicas craneales y poscran.pdf
Describir las caractersticas anatmicas craneales y poscran.pdfDescribir las caractersticas anatmicas craneales y poscran.pdf
Describir las caractersticas anatmicas craneales y poscran.pdf
 

Recently uploaded

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 

Recently uploaded (20)

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 

Description of the project Purpose To implement a simple au.pdf

  • 1. Description of the project Purpose: To implement a simple automatic word-completion system. Task 1: Implement algorithms for DLB insertion and traversal. Task 2: Implement an algorithm for retrieving one word prediction. Background Autocomplete is a commonly used feature in mobile phones, text editors, and search engines. As a user types in letters, the system shows a list of word predictions to help the user complete the word they are typing. The core of an efficient autocompletion system is a fast algorithm for retrieving word predictions based on the user input. The word predictions are all the words (in a given dictionary) that start with what the user has typed so far (i.e., the list of words for which the user's input is a prefix). In this assignment we will build a simple autocompletion system using a DLB trie which allows the user to add a new word to its dictionary when none of the predictions are selected by the user. The AutoCompleteInterface defines a Java interface for a dictionary that provides word predictions for such an autocompletion system. Besides storing a set of words, the dictionary keeps track of a prefix String, which starts with the empty String. You will implement methods to add one character to and delete the last character of that prefix String. You will also implement methods that use that prefix String for various operations, such as checking if the prefix String is one of the words in the dictionary, retrieving the number of words that have the prefix String as a prefix, and adding the prefix String to the dictionary. Details In the first part of this assignment, you will implement algorithms for: inserting a StringBuilder object into a DLB trie by filling in the add(String word) method below. You may want to add and call a private recursive helper method. The DLBNode class is already defined for you in AutoComplete.java. You will use a doubly-linked list of siblings, a child reference, and an upwards reference to the node's parent. The isWord field of a node is true if and only if the node is at the end of a word in the dictionary. The size field keeps track of the number of nodes with isWord==true in the subtree rooted at the node, including the node itself. The add method should update the size field for some of the nodes that it goes over. You will need to think about for which nodes size should be incremented. The next set of the methods modify the prefix String maintained by the dictionary. These methods are: advance(char c) for appending a character to the prefix String, retreat() for deleting the last character, and reset() for resetting it back to the empty String. More details about these methods can be found below. Your code should maintain a DLBNode currentNode reference to always point to the DLB node at the end of the prefix String. currentNode is null when the prefix String is "", moves over the sibling list of the root node upon the first call to advance, moves possibly sideways then down the trie with each further call to advance, moves possibly sideways then up the trie with retreat until resetting to null when the prefix String becomes empty, and resets to null with reset. The last set of methods operate on the prefix String by checking whether it is a word in the dictionary (isWord()), adding it if not (add()), retrieving the number predictions for the prefix String (getNumberOfPredictions), and retrieving one of the predictions (if any) (retrievePrediction).
  • 2. Retrieving the number predictions should be as simple as returning the size field of the currentNode. The add() method should increment the size field for some of the nodes (which ones?). (Hint: you may need to climb up the trie.) /** * An implementation of the AutoCompleteInterface using a DLB Trie. */ import java.util.ArrayList; import javax.xml.crypto.Data; public class AutoComplete implements AutoCompleteInterface { private DLBNode root; private StringBuilder currentPrefix; private DLBNode currentNode; private static final char SENTINEL = '^'; //TODO: Add more instance variables as needed public AutoComplete(){ root = null; currentPrefix = new StringBuilder(); currentNode = null; } /** * 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 */ public boolean add(String word){ //TODO: implement this method recursively with a helper method } /** * appends the character c to the current prefix in O(alphabet size) time. * This method doesn't modify the dictionary. * @param c: the character to append * @return true if the current prefix after appending c is a prefix to a word * in the dictionary and false otherwise */ public boolean advance(char c){ //TODO: implement this method return false; } /** * removes the last character from the current prefix in O(1) time. This
  • 3. * method doesn't modify the dictionary. * @throws IllegalStateException if the current prefix is the empty string */ public void retreat(){ //TODO: implement this method } /** * resets the current prefix to the empty string in O(1) time */ public void reset(){ //TODO: implement this method } /** * @return true if the current prefix is a word in the dictionary and false * otherwise. The running time is O(1). */ public boolean isWord(){ //TODO: implement this method return false; } /** * adds the current prefix as a word to the dictionary (if not already a word) * The running time is O(alphabet size*length of the current prefix). */ public void add(){ //TODO: implement this method } /** * @return the number of words in the dictionary that start with the current * prefix (including the current prefix if it is a word). The running time is * O(1). */ public int getNumberOfPredictions(){ //TODO: implement this method return 0; } /** * retrieves one word prediction for the current prefix. The running time is * O(prediction.length()) * @return a String or null if no predictions exist for the current prefix */ public String retrievePrediction(){
  • 4. //TODO: implement this method return null; } /* ============================== * Helper methods for debugging. * ============================== */ //print the subtrie rooted at the node at the end of the start String public void printTrie(String start){ System.out.println("==================== START: DLB Trie Starting from ""+ start + "" ===================="); if(start.equals("")){ printTrie(root, 0); } else { DLBNode startNode = getNode(root, start, 0); if(startNode != null){ printTrie(startNode.child, 0); } } System.out.println("==================== END: DLB Trie Starting from ""+ start + "" ===================="); } //a helper method for printTrie private void printTrie(DLBNode node, int depth){ if(node != null){ for(int i=0; i<depth; i++){ System.out.print(" "); } System.out.print(node.data); if(node.isWord){ System.out.print(" *"); } System.out.println(" (" + node.size + ")"); printTrie(node.child, depth+1); printTrie(node.nextSibling, depth); } } //return a pointer to the node at the end of the start String //in O(start.length() - index) private DLBNode getNode(DLBNode node, String start, int index){ if(start.length() == 0){
  • 5. return node; } DLBNode result = node; if(node != null){ if((index < start.length()-1) && (node.data == start.charAt(index))) { result = getNode(node.child, start, index+1); } else if((index == start.length()-1) && (node.data == start.charAt(index))) { result = node; } else { result = getNode(node.nextSibling, start, index); } } return result; } //The DLB node class private class DLBNode{ private char data; private int size; private boolean isWord; private DLBNode nextSibling; private DLBNode previousSibling; private DLBNode child; private DLBNode parent; private DLBNode(char data){ this.data = data; size = 0; isWord = false; nextSibling = previousSibling = child = parent = null; } } } the below is the interface /** * An interface for a dictionary that provides word suggestions for an * auto-complete system and maintains a current prefix */ public interface AutoCompleteInterface { /** * 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
  • 6. */ public boolean add(String word); /** * appends the character c to the current prefix in O(alphabet size) time. * This method doesn't modify the dictionary. * @param c: the character to append * @return true if the current 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 current prefix in O(alphabet size) * time. This method doesn't modify the dictionary. * @throws IllegalStateException if the current prefix is the empty string */ public void retreat(); /** * resets the current prefix to the empty string in O(1) time */ public void reset(); /** * @return true if the current prefix is a word in the dictionary and false * otherwise. The running time is O(1). */ public boolean isWord(); /** * adds the current prefix as a word to the dictionary (if not already a word) * The running time is O(alphabet size*length of the current prefix). */ public void add(); /** * @return the number of words in the dictionary that start with the current * prefix (including the current prefix if it is a word). The running time is * O(1). */ public int getNumberOfPredictions(); /** * retrieves one word prediction for the current prefix. The running time is * O(prediction.length()) * @return a String or null if no predictions exist for the current prefix */ public String retrievePrediction();
  • 7. } complete the todo according the comment given on the interface and the add (string word) method should be in the similar structure like put method public void put(String key, Value val) { if (key == null) throw new IllegalArgumentException("calls put() with a null key"); key = key + SENTINEL; root = put(root, key, val, 0); } private Node put(Node x, String key, Value val, int pos) { Node result = x; if (x == null){ result = new Node(); result.letter = key.charAt(pos); result.level = pos; if(pos < key.length()-1){ result.child = put(result.child,key ,val ,pos +1);/*TODO: Recurse on the child node*/ } else { result.val = val; } } else if(x.letter == key.charAt(pos)) { if(pos < key.length()-1){ result.child = put(result.child,key ,val ,pos +1); /*TODO: Recurse on the child node*/ } else { result.val = val; //update } } else { result.sibling = put(result.sibling, key , val, pos); /*TODO: Recurse on the sibling node*/ } return result; }