1. Homepage
  2. Programming
  3. FIT2004 Algorithms and data structures - Assignment 2: A Fun Weekend Away and Customised Spell Checker

FIT2004 Algorithms and data structures - Assignment 2: A Fun Weekend Away and Customised Spell Checker

Engage in a Conversation
MonashFIT2004Algorithms and data structuresPythonA Fun Weekend AwayCustomised Spell Checker

FIT2004 Semester 2 2024: Assignment 2 CourseNana.COM


CourseNana.COM

PROGRAMMING CRITERIA: It is required that you implement this exercise strictly using the Python programming language (version should not be earlier than 3.5). This practical work will be marked on the time complexity, space complexity and functionality of your program, and your documentation. CourseNana.COM

Your program will be tested using automated test scripts. It is therefore critically impor- tant that you name your files and functions as specified in this document. If you do not, it will make your submission difficult to mark, and you will be penalised. CourseNana.COM

SUBMISSION REQUIREMENT: You will submit a single Python file containing all of the questions you have answered, assignment2.py. Moodle will not accept submissions of other file types. CourseNana.COM

PLAGIARISM: The assignments will be checked for plagiarism using an advanced pla- giarism detector. In previous semesters, many students were detected by the plagiarism detector and almost all got zero mark for the assignment (or even zero marks for the unit as penalty) and, as a result, the large majority of those students failed the unit. Helping others to solve the assignment is NOT ACCEPTED. Please do not share your solutions partially or completely to others. Even after the deadline, your solutions/approaches should not be shared before the grades and feedback are released by the teaching team. Using contents from the Internet, books etc without citing is plagiarism (if you use such content as part of your solution and properly cite it, it is not plagiarism; but you wouldn’t be getting any marks that are possibly assigned for that part of the task as it is not your own work). CourseNana.COM

The use of generative AI and similar tools for the completion of your assignment is not allowed in this unit! CourseNana.COM

Learning Outcomes CourseNana.COM

This assignment achieves the Learning Outcomes of: CourseNana.COM

  • Analyse general problem solving strategies and algorithmic paradigms, and apply them to solving new problems; CourseNana.COM

  • Prove correctness of programs, analyse their space and time complexities; CourseNana.COM

  • Compare and contrast various abstract data types and use them appropriately; CourseNana.COM

  • Develop and implement algorithms to solve computational problems. CourseNana.COM

    In addition, you will develop the following employability skills: Text comprehension.
    Designing test cases.
    Ability to follow specifications precisely. CourseNana.COM

    Assignment timeline CourseNana.COM

    In order to be successful in this assessment, the following steps are provided as a suggestion. This is an approach which will be useful to you both in future units, and in industry. CourseNana.COM

    Planning CourseNana.COM

  1. Read the assignment specification as soon as possible and write out a list of questions you have about it. CourseNana.COM

  2. Try to resolve these questions by viewing the FAQ on Ed, or by thinking through the problems over time. CourseNana.COM

  3. As soon as possible, start thinking about the problems in the assignment. CourseNana.COM

    It is strongly recommended that you do not write code until you have a solid feeling for how the problem works and how you will solve it. CourseNana.COM

  4. Writing down small examples and solving them by hand is an excellent tool for coming to a better understanding of the problem. CourseNana.COM

    As you are doing this, you will also get a feel for the kinds of edge cases your code will have to deal with. CourseNana.COM

  5. Write down a high-level description of the algorithm you will use. CourseNana.COM

  6. Determine the complexity of your algorithm idea, ensuring it meets the requirements. CourseNana.COM

Implementing CourseNana.COM

  1. Think of test cases that you can use to check if your algorithm works. CourseNana.COM

    Use the edge cases you found during the previous phase to inspire your test cases. It is also a good idea to generate large random test cases.
    Sharing test cases is allowed, as it is not helping solve the assignment. CourseNana.COM

  2. Code up your algorithm (remember decomposition and comments), and test it on the tests you have thought of. CourseNana.COM

  3. Try to break your code. Think of what kinds of inputs you could be presented with which your code might not be able to handle. CourseNana.COM

    Large inputs
    Small inputs
    Inputs with strange properties What if everything is the same? What if everything is different? etc... CourseNana.COM

Before submission CourseNana.COM

Make sure that the input/output format of your code matches the specification. Make sure your filenames match the specification.
Make sure your functions are named correctly and take the correct inputs.
Remove print statements and test code from the file you are going to submit. CourseNana.COM

Documentation CourseNana.COM

For this assignment (and all assignments in this unit) you are required to document and comment your code appropriately. Whilst part of the marks of each question are for documentation, there is a baseline level of documentation you must have in order for your code to receive marks. In other words: CourseNana.COM

Insufficient documentation might result in you getting 0 for the entire question for which it is insufficient. CourseNana.COM

This documentation/commenting must consist of (but is not limited to): CourseNana.COM

  • For each function, high-level description of that function. This should be a two or three sentence explanation of what this function does. CourseNana.COM

  • Your main function in the assignment should contain a generalised description of the approach your solution uses to solve the assignment task. CourseNana.COM

  • For each function, specify what the input to the function is, and what output the function produces or returns (if appropriate). CourseNana.COM

  • For each function, the appropriate Big-O or Big-Θ time and space complexity of that function, in terms of the input size. Make sure you specify what the variables involved in your complexity refer to. Remember that the complexity of a function includes the complexity of any function calls it makes. CourseNana.COM

  • Within functions, comments where appropriate. Generally speaking, you would comment complicated lines of code (which you should try to minimise) or a large block of code which performs a clear and distinct task (often blocks like this are good candidates to be their own functions!). CourseNana.COM

    A suggested function documentation layout would be as follows: CourseNana.COM

       def my_function(argv1, argv2):
           """
    
           Function description:
    
           Approach description (if main function):
    
           :Input:
               argv1:
    
               argv2:
           :Output, return or postcondition:
           :Time complexity:
    
          :Time complexity analysis:
           :Space and auxiliary space complexity:
    
          :Space and auxiliary space complexity analysis:
           """
    
           # Write your codes here.
    

    There is a documentation guide available on Moodle in the Assignment section, which contains a demonstration of how to document the code to the level required in the unit. CourseNana.COM

1 A Fun Weekend Away
(10 marks, including 2 marks for documentation)
CourseNana.COM

Given all the hard work during the semester, you and your friends decided that you should better get a weekend off after Week 12 before starting preparing for your final exams. Your plan is to do some fun activity (e.g., surfing, hiking, kayaking, mountain biking, etc.) during this weekend getaway. However, during your initial talks you quickly recognised that: CourseNana.COM

  • There are a total of n participants that want to get a weekend getaway (where n is an integer greater than 1). The participants will be denoted by P0, . . . , Pn1. CourseNana.COM

  • People have different preferences regarding which activity they would prefer to do. CourseNana.COM

  • While some people would prefer to do one activity that they already have experience on, others would prefer to try something new. CourseNana.COM

  • It would be wise to have some people with previous experience to lead each activity. CourseNana.COM

  • Everybody is fine with helping leading one activity if they have previous experience on that activity. But no one wants to be a leader for the whole weekend as everyone also wants to have some chill time. CourseNana.COM

    After some discussion you settled on the following criteria: CourseNana.COM

  • You shortlisted some m activities denoted by A0, . . . , Am1 that the participants would be assigned to. CourseNana.COM

  • Each person should be assigned to one activity they are interested in, and that person would be doing that activity for the whole weekend. CourseNana.COM

  • For each activity Aj, you need one leader for Saturday and another different leader for the Sunday. Both leaders need to have previous experience in activity Aj. You already filtered the list of activities to guarantee that for each activity Aj there are at least two participants with previous experience on it. You can assume that the number of activities is at most n/2. CourseNana.COM

    Some of your friends had a bit more free time, so they went ahead and did the heavy work of surveying the preferences of all participants and their previous experiences, and also of trying to figure out accommodation, transportation, equipment renting, etc for each activity. They have put some reservations on hold, but they got stuck with the problem of assigning the par- ticipants to the specific activities. They need urgent help to confirm if the current plan for each activity is good in the sense of having some assignment from the participants to the activities that would satisfy all criteria (and thus they can proceed with the reservations), and, if such assignment exists, how to obtain one. CourseNana.COM

    As the computer science expert in the group, you were tasked with writing a computer program to solve that task. You are given as input the following data: CourseNana.COM

    A list of lists preferences. For each person Pi and each activity Aj, preferences[i][j] would be: CourseNana.COM

  • –  equal to 0 if the person is not interested in that activity. CourseNana.COM

  • –  equal to 1 if the person is interested in that activity but has no previous experience CourseNana.COM

    on it. CourseNana.COM

  • –  equal to 2 if the person is interested in that activity and has previous experience on it. CourseNana.COM

  • –  You can assume that every person is interested in at least one activity. CourseNana.COM

    A list places. For each activity Aj, places[j] indicates how many people should be CourseNana.COM

    going to do the activity Aj if the reservations that are on hold were to be confirmed. You CourseNana.COM

    can assume that places[j] 2 for each j. And it holds that Pm1 places[j] = n. j=0 CourseNana.COM

    Your program should either find a way to partition the participants into the activities so that all the above constraints are satisfied; or correctly indicate it is impossible to partition the participants into the activities while satisfying all constraints. CourseNana.COM

    To solve this problem, you should write a function assign(preferences, places) that re- turns: CourseNana.COM

  • None (i.e., Python NoneType), if it is impossible to assign the participants into the ac- tivities while satisfying all constraints. CourseNana.COM

  • Otherwise, it returns a list of lists activities in which, for 0 j m1, activities[j] is a list identifying the indices of the participants that will be going to activity Aj. If there are multiple valid options to partition the participants into the activities while satisfying all constraints, you can return any of those valid options (but should return exactly one of them). CourseNana.COM

    1.1 Example CourseNana.COM

    Consider the following example in which the function returns one valid assignment for the specified input. CourseNana.COM

      # Example
      preferences = [[2, 1], [2, 2], [1, 1], [2, 1], [0, 2]]
      places = [2, 3]
    
      >>>  assign(preferences, places)
      [[0, 3], [1, 4, 2]]
    

    1.2 Complexity CourseNana.COM

    Your solution should have a worst-case time complexity of O (n3). CourseNana.COM

2 Customised Spell Checker
(10 marks, including 2 marks for documentation)
CourseNana.COM

Allen likes the spell checking feature in his phone but finds that it occasionally fails to align with his messaging style, particularly when he uses social media acronyms. For example, Allen may type "DM me" to mean “direct message me,” but the spell checker might suggest “AM” or “dem” for correcting "DM". CourseNana.COM

In this task, we wish to create a customised spell checker that can make correction suggestions according to users’ preference on word choice. The customisation is based on the user’s previous messages sent using the phone. CourseNana.COM

To solve this problem, you are required to create a class SpellChecker. The constructor for this class takes a file Messages.txt as a parameter. Additionally, this class has a method check(input) to check an input word and suggest possible corrections. CourseNana.COM

2.1 Input CourseNana.COM

You are provided with a file Messages.txt where each line consists of a message. A few example messages in the file are shown below. CourseNana.COM

  Oh, LOL.
  I do not understand. ELI5.
  I know how to do this, AMA.

Although Messages.txt is provided on Moodle to make it easier for verifying the correctness of your implementation, you cannot assume that the file used for testing your algorithm will be similarly small. Your program will be tested on a different and potentially much larger file. CourseNana.COM

Each line in Messages.txt should be converted into a list of words before counting their frequency. For this assignment, we assume that a word contains only alphabetic characters (“a” to “z” and “A” to “Z”) and numerical digits (“0” to “9”). Other symbols, such as spaces (“ ”), commas (“,”), periods (“.”), or question marks (“?”), should not be included in a word. Note that the spell checker is case-sensitive. CourseNana.COM

2.2 Output CourseNana.COM

The check method accepts a single word input. If input matches any word in your previous messages, check returns an empty list. Otherwise, check returns a list of at most three words that have a non-empty common prefix with input. If there are no words sharing a common prefix with input, an empty list should be returned. If there are more than three words sharing a common prefix with input, all words are ranked: CourseNana.COM

firstly by the number of characters in the common prefix shared with input (longer prefixes take precedence), CourseNana.COM

secondly by the frequency of the word in Messages.txt (higher frequencies take prece- dence), CourseNana.COM

thirdly by the ASCII value ordering following the characters from the left to right of the words (smaller ASCII value ordering take precedence). CourseNana.COM

Note that a word a has a smaller ASCII value ordering than a word b in the following cases: CourseNana.COM

  1. When two words are of the same length, say a = a1a2 ...,ak and b = b1b2 ...bk, then ai CourseNana.COM

    has a smaller ASCII value than bi for the first place i where the two words differ. CourseNana.COM

  2. Otherwise, two words have different lengths. The shorter word is padded with the null character (with ASCII value 0) at the end until two words have the same length, and then two words are compared as in the first case. CourseNana.COM

The check method returns the TOP 3 words according to the above ranking. However, the words in the output list do not need to follow any specific order. CourseNana.COM

2.3 Example CourseNana.COM

Suppose you are given a file Messages.txt as follows: CourseNana.COM

  Oh, LOL.
  I do not understand. ELI5.
  IDK. Tell me more.
  LMK if you want to go.
  If you will not go, me neither.
  I know how to do this, AMA.
  Fine, IDC.
  BTW, I will not come back home for dinner tonight.
  IDK. Tell me more.

After initialisation, your SpellChecker will have the following outputs: CourseNana.COM

  >>> myChecker = SpellChecker("Messages.txt")
  >>> myChecker.check("IDK")
  []
  >>> myChecker.check("zoo")
  []
  >>> myChecker.check("LOK")
  ["LOL", "LMK"]
  >>> myChecker.check("IDP")
  ["IDK", "IDC", "I"]
  >>> myChecker.check("Ifc")
  ["If", "I", "IDK"]

2.4 Complexity Requirements CourseNana.COM

The __init__ method of SpellChecker must run in time complexity O(T), where T is the total number of characters in Messages.txt. CourseNana.COM

Let M be the length of the string input and U be the total number of characters in the correct output that should be returned by check on that input, then check must run in time complexity O(M + U). Note that this is an output dependent complexity. For example, if there are no words match the string input, check should complete in O(M). CourseNana.COM

Important: You are NOT ALLOWED to use hash functions/tables (e.g. Python dictio- nary) or linked lists in your implementation. The list data structure of fixed size in Python1 is allowed, [ ]. CourseNana.COM

1https://docs.python.org/3/tutorial/datastructures.html CourseNana.COM

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
Monash代写,FIT2004代写,Algorithms and data structures代写,Python代写,A Fun Weekend Away代写,Customised Spell Checker代写,Monash代编,FIT2004代编,Algorithms and data structures代编,Python代编,A Fun Weekend Away代编,Customised Spell Checker代编,Monash代考,FIT2004代考,Algorithms and data structures代考,Python代考,A Fun Weekend Away代考,Customised Spell Checker代考,Monashhelp,FIT2004help,Algorithms and data structureshelp,Pythonhelp,A Fun Weekend Awayhelp,Customised Spell Checkerhelp,Monash作业代写,FIT2004作业代写,Algorithms and data structures作业代写,Python作业代写,A Fun Weekend Away作业代写,Customised Spell Checker作业代写,Monash编程代写,FIT2004编程代写,Algorithms and data structures编程代写,Python编程代写,A Fun Weekend Away编程代写,Customised Spell Checker编程代写,Monashprogramming help,FIT2004programming help,Algorithms and data structuresprogramming help,Pythonprogramming help,A Fun Weekend Awayprogramming help,Customised Spell Checkerprogramming help,Monashassignment help,FIT2004assignment help,Algorithms and data structuresassignment help,Pythonassignment help,A Fun Weekend Awayassignment help,Customised Spell Checkerassignment help,Monashsolution,FIT2004solution,Algorithms and data structuressolution,Pythonsolution,A Fun Weekend Awaysolution,Customised Spell Checkersolution,