Skip to content

Commit

Permalink
assignment 1
Browse files Browse the repository at this point in the history
  • Loading branch information
fxwalsh committed Oct 5, 2016
1 parent 8206250 commit 7445b8d
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 66 deletions.
41 changes: 0 additions & 41 deletions assign/book1/03.03.md

This file was deleted.

7 changes: 0 additions & 7 deletions assign/book1/04.04.md

This file was deleted.

2 changes: 1 addition & 1 deletion public-site
Submodule public-site updated from 583e9a to 0aef3c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ In this assignment you will write a java program which implements autocomplete f
- Read in a set of N strings and weights from a data source (e.g. file or URL).
- Allow the user enter a prefix string.
- Find and display the top strings in the set that contain the prefix.
- Provide full JUnit test coverage
- Provide a comprehensive testing strategy using JUnit.

This Assigment is worth 30% of your overall mark for this module.
This Assigment is worth 20% of your overall mark for this module.
5 changes: 1 addition & 4 deletions assign/book1/01.01.md → topic04/book-2/01.01.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ You would noticed the autocomplete mechanism in the Eclipse Java source code edi
Your assignment is to develop a java program that reads in a list of strings(called **terms**) and associated weights from a URL or file and stores them in a suitable data structure. The user should then be able to enter a prefix string and the program should return a list of matching phrases that start with that text. All matching phrases should be displayed and the search should be case insensitive.

## String Weighs
Most autocomplete application predict how likely it is that the user is typing each term. Each string has an associated **weight** and your program will use these to compute a list of the top matching terms, in decreasing order of weight.
Most autocomplete application predict how likely it is that the user is typing each term. For this purpose, each term has a **weight** and your program will use these to compute a list of the top matching terms, in decreasing order of weight.

The weights are calculated using various data, such as number of plays for movie streaming services, frequencies of search queries from other Google users, or the typing history of a smart phone user.
In this assignment, you will be given a list of all terms and associated weights (and the terms and weights will not change).




## Performance
The performance of autocomplete functionality is critical in many systems. For example, the Google search engine runs an autocomplete application. It also performs this computation for every keystroke typed into the search bar and for every user! Therefore application has to return a list of suggestions in a short time for it to be useful to the user. It also performs this computation for every keystroke typed into the search bar and for every user!
16 changes: 8 additions & 8 deletions assign/book1/02.02.md → topic04/book-2/02.02.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@
You will implement autocomplete in two different ways.

- **BruteForceAutocomplete.java**, a brute-force solution.
- **QuickAutocomplete.java**, will use a more complex data structure (of your own design) to improve performance.
- **QuickAutocomplete.java**, will use a more complex data structure to improve performance.

As you will know from using autocomplete, speed is important. It should be quick to return the suggested list within 50ms to be acceptable to a user.
As you will know from using autocomplete, speed is important.

##BruteForceAutocomplete.java

Write an data type BruteAutocomplete.java that implements the API shown below. Your brute-force implementation should maintain the terms and weights in a suitable implementation of **List**.
Write an data type **BruteAutoComplete.java** that implements the interface shown below. Your brute-force implementation should maintain the terms and weights in a suitable implementation of **List**.

~~~ java
public interface AutoCompleteInterface {
public interface AutoComplete{

// Returns the weight of the term, or 0.0 if no such term.
public double weightOf(String term);

// Returns a top matching term, or null if no matching term.
public String topMatch(String prefix);
public String bestMatch(String prefix);

// Returns the top k matching terms (in descending order of weight), as an
// iterable.
// If fewer than k matches, return all matching terms (in descending order
// of weight).
public Iterable<String> topMatches(String prefix, int k);
public Iterable<String> matches(String prefix, int k);
}
~~~

Expand All @@ -36,9 +36,9 @@ public interface AutoCompleteInterface {
- The topMatches() method should throw a IllegalArgumentException if k is negative.
- Each method and constructor should throw a NullPointerException if any argument is null.

This brute-force approach is easy to implement but, when N is large, the number of autocomplete queries that can be processed per second will be too small to be useful. You can use it as a reference solution and benchmark when developing a faster solution.
For the brute force solution, when N is large, the number of autocomplete queries that can be processed per second will be too small to be useful. You can use it as a reference when developing a faster solution.

Your constructor for BruteAutocomplete should be subquadratic in the number of terms, and your topMatch() and topMatches() methods should be subquadratic in the number of terms (and thus you should not use your weightOf method if it is linear time).
Your constructor for BruteAutocomplete should be *subquadratic* in the number of terms, and your topMatch() and topMatches() methods should be *subquadratic* in the number of terms (and thus you should not use your weightOf method if it is linear time).

##Autocorrect Application
Use the api to develop an end user application. This can be a simple command line interface that allows a user to access the functionality in the Autocomplete API.
38 changes: 38 additions & 0 deletions topic04/book-2/03.03.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
## Data

You are provided with the following weighed data adapted from [Wiktionary](file//:wiktionary.txt). The file contains the 10,000 most common words along with weights equal to their frequencies. You will have to write your own code that can parse the data. There is one term per line, with the weight and term separated by a tab. The terms can be arbitrary strings consisting of Unicode characters, including spaces (but not newlines).

The following code example, contained in the [class resources repo](https://github.com/fxwalsh/algorithms-2016-examples.git), uses the Scanner class to read in a text file line by line, parse the data, and print the data to the standard output:

~~~ java
File usersFile = new File("./data/userdata.txt");
Scanner inUsers = new Scanner(usersFile);
String delims = "[ ]";//each field in the file is separated(delimited) by a space.
while (inUsers.hasNextLine()) {
// get user and rating from data source
String userDetails = inUsers.nextLine();
// parse user details string
String[] userTokens = userDetails.split(delims);

// output user data to console.
if (userTokens.length == 2) {
System.out.println("UserID: " + userTokens[0] + ",First Name:" + userTokens[1]);

}else
{
inUsers.close();
throw new Exception("Invalid member length: "+userTokens.length);
}
}
inUsers.close();
~~~

The above code produces output similar to the following:

>UserID: 1,First Name:bob
>UserID: 2,First Name:jack
>UserID: 3,First Name:donald
>UserID: 4,First Name:mary

You will also need to design and implement a suitable data type(s) that will support the functionality of the program.
7 changes: 7 additions & 0 deletions topic04/book-2/04.04.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
##Testing

Approximately 20% of marks in this assignment is for the testing and test strategy. You are required to provide the following:

- Write a test specification for each class you test (at least 2 classes). The test strategy should be contained in the readme.md of your Github repository.
- JUnit test cases + a series of tests.
- For each tests you write - indicate which part of the specification you are testing.
6 changes: 3 additions & 3 deletions assign/book1/05.05.md → topic04/book-2/05.05.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ Please submit assignment as a Github or Bitbucket repository. The following are
- Sorting


All code should be internally documented and your repository should contain by a readme file that clearly and concisely explains the features of your program. General marking scheme, including above expectations, is as follows:
All code should be internally documented and your repository should contain by a readme.md file that clearly and concisely explains the features of your program. General marking scheme, including above expectations, is as follows:

>Load External Data: 10;
>Return Top Match: 10;
>Return List of Matches: 10;
>Return sorted list of k matches: 10;
>Github Repo: 10;
>FastAutoComplete: 20
>Github Repo: 10 (readme, project structure);
>FastAutoComplete: 20;
>CLI controller: 10;
>Testing: 20.
File renamed without changes
File renamed without changes
File renamed without changes.

0 comments on commit 7445b8d

Please sign in to comment.