MCD4710 - Introduction to Algorithms and ProgrammingAssignment 2 (10%)

qq1703105484

             Due: Thursday, May 5, 2022, 11:55 pm - Week 10             

Objectives

The objectives of this assignment are:

  • To gain experience in designing algorithms for a given problem description and implementing those algorithms in Python.
  • To demonstrate your understanding on:
    • Implementing problem solving strategies
    • Recognizing the relationship between a problem description and program design
    • Decomposing code into functions in Python.

Submission Procedure

Your assignment will not be accepted unless it meets these requirements:

  1. Your name and student ID must be included at the start of every file in your submission.
  2. Save your file(s) into a zip file called YourStudentID.zip
  3. Submit your zip file containing your entire submission to Moodle.

Late Submission

Late submission will have 5% deduction of the total assignment marks per day (including weekends). Assignments submitted 7 days after the due date will not be accepted.

Important Notes

  • Please ensure that you have read and understood the university’s procedure on plagiarism and collusion available at https://www.monashcollege.edu.au/__data/assets/pdf_file/0005/1266845/Student-Academic-Integrity- Diplomas-Procedure.pdf . You will be required to agree to these policies when you submit your assignment.
  • Your code will be checked against other students’ work and code available online by advanced plagiarism detection systems. Make sure your work is your own. Do not take the risk.
  • Your program will be checked against a number of test cases. Do not forget to include comments in your code explaining your algorithm. If your implementation has bugs, you may still get some marks based on how close your algorithm is to the correct algorithm. This is made difficult if code is poorly documented.
  • Where it would simplify the problem you may not use built-in Python functions or libraries (e.g. using

list.sort() or sorted()). Remember that this is an assignment focusing on algorithms and programming.

Assignment code interview

Each student will be interviewed during a lab session regarding their submission to gauge your personal understanding of your Assignment code. The purpose of this is to ensure that you have completed the code yourself and that you understand the code submitted. Your assignment mark will be scaled according to the responses provided.

Interview Rubric

0

The student cannot answer even the simplest of questions. There is no sign of preparation.

They probably have not seen the code before.

0.25

There is some evidence the student has seen the code.

The answer to a least one question contained some correct points.

However, it is clear they cannot engage in a knowledgeable discussion about the code.

0.5

The student seems underprepared.

Answers are long-winded and only partly correct.

They seem to be trying to work out the code as they read it.

They seem to be trying to remember something they were told but now can’t remember. However, they clearly know something about the code.

With prompting, they fail to improve on a partial or incorrect answer.

0.75

The student seems reasonably well prepared.

Questions are answered correctly for the most part but the speed and/or confidence they are answered with is not 100%.

With prompting, they can add a partially correct answer or correct an incorrect answer.

1

The student is fully prepared.

All questions were answered quickly and confidently.

It is absolutely clear that the student has performed all of the coding themselves.

Marking Criteria

This assignment contributes to 10% of your final mark. Task 1 – Find grandparents: 5 marks

Task 2 – Find siblings: 5 marks Task 3 – Find cousins: 5 marks

Task 4 – Find direct ancestors: 7 marks Task 5 – Find cousin degree: 7 marks Programming practice – 2 marks

  • Decomposition (1 mark)
  • Variable names and code Documentation (1 mark) Total: 31 marks

Family Trees (Part 1 & 2)

In this assignment we create a Python module to implement some basic family tree software, where users can look up various relationships that exist in the database. We represent each entry in a family tree database as a list of three strings [name, father, mother], where name is a person’s name, father is the name of their father, and mother is the name of their mother. Where a particular relationship is unknown, the value None is used.


For example, consider the following family tree:

The relationships shown in this tree are represented using the following database in Python (note that this database is just for the purposes of illustration, and your module must work for other family tree databases as well):

>>> duck_tree = [['Fergus McDuck', None, None],

...          ['Downy ODrake', None, None],

...          ['Quackmore Duck', None, None],

...          ['Donald Duck','Quackmore Duck','Hortense McDuck'],

...          ['Della Duck', 'Quackmore Duck', 'Hortense McDuck'],

...          ['Hortense McDuck', 'Fergus McDuck', 'Downy ODrake'],

...          ['Scrooge McDuck', 'Fergus McDuck', 'Downy ODrake'],

...          ['Huey Duck', None, 'Della Duck'],

...          ['Dewey Duck', None, 'Della Duck'],

...          ['Louie Duck', None, 'Della Duck']]

Again, this is just one limited example of a family tree database. A larger database, hobbit-family.txt,  has also been provided for you separately to read in and test your functions. As run-through examples, this assignment will use both the duck tree database and the hobbit-family database. But it is important  to remember that your functions should work on any family tree that is represented in the manner described. Consider creating your own examples to test your functions on.

The hobbit-family.txt test file has been compiled using the family tree information at http://lotrproject.com/hobbits.php.

All character names used in the file are by J.R.R. Tolkein.

Complex Relationship Lookups

In this assignment, you will write more complex functions for returning more complex relationship (compared to the functions you wrote for assignment 1) information from a family tree database.

Task 1

Implement a function grandparent(person, family) with the following specification. Input: A person's name (person) and a family tree database (family) as specified above.

Output: A list containing the names of all grandparent of person that are stored in the database.

For example:

>>> hobbits = read_family('hobbit-family.txt')

>>> sorted(grandparent('Frodo Baggins', hobbits))

['Fosco Baggins', 'Gorbadoc Brandybuck', 'Mirabella Took', 'Ruby Bolger']

>>> sorted(grandparent('Doderic Brandybuck', hobbits)) ['Saradas Brandybuck']

>>> sorted(grandparent('Hilda Bracegirdle', hobbits)) []

Task 2

Implement a function siblings(person, family) with the following specification. Input: A person's name (person) and a family tree database (family) as specified above.

Output: A list containing the names of all siblings (including stepsiblings) of person that are stored in the database.

For example:

>>> hobbits = read_family('hobbit-family.txt')

>>> sorted(siblings('Frodo Baggins', hobbits)) []

>>> sorted(siblings('Daisy Baggins', hobbits)) []

>>> sorted(siblings('Drogo Baggins', hobbits)) ['Dora Baggins', 'Dudo Baggins']

>>> sorted(siblings('Dudo Baggins', hobbits)) ['Dora Baggins', 'Drogo Baggins']

Task 3

Implement a function cousins(person, family) with the following specification. Input: A person's name (person) and a family tree database (family) as specified above.

Output: A list containing the names of all first cousins of person that are stored in the database.

For example:

>>> hobbits = read_family('hobbit-family.txt')

>>> sorted(cousins('Frodo Baggins', hobbits))

['Daisy Baggins', 'Merimac Brandybuck', 'Milo Burrows', 'Saradoc Brandybuck', 'Seredic Brandybuck']

Task 4

Implement a function direct_ancestor(p1, p2, family) with the following specification. Input: Two names (p1, p2) and a family tree database (family).

Output: One of the following three string outputs (where p1 and p2 are the given input strings, and n

is a non-negative integer):

"p1 is a direct ancestor of p2, n generations apart." "p2 is a direct ancestor of p1, n generations apart." "p1 is not a direct ancestor or descendant of p2."

For example:

>>> hobbits = read_family('hobbit-family.txt')

>>> direct_ancestor('Frodo Baggins', 'Frodo Baggins', hobbits)

'Frodo Baggins is a direct ancestor of Frodo Baggins, 0 generations apart.'

>>> direct_ancestor('Frodo Baggins', 'Gormadoc Brandybuck', hobbits)

'Gormadoc Brandybuck is a direct ancestor of Frodo Baggins, 5 generations apart.'

Include a paragraph on problem, challenges, and overall approach, as docstrings in your code.

Task 5

Implement a function cousin_degree(p1, p2, family) with the following specification. Input: Two names (p1, p2) and a family tree database (family).

Output: A number representing the minimum distance cousin relationship between p1 and p2, as follows:

  • 0 if p1 and p2 are siblings
  • 1 if p1 and p2 are cousins
  • n if p1 and p2 are nth cousins, as defined at

https://www.familysearch.org/blog/en/cousin-chart/

  • 1 if p1 and p2 have no cousin or sibling relationship For example:

>>> hobbits = read_family("hobbit-family.txt")

>>> cousin_degree('Minto Burrows', 'Myrtle Burrows', hobbits) 0

>>> cousin_degree('Estella Bolger', 'Meriadoc Brandybuck', hobbits) 3

>>> cousin_degree('Frodo Baggins', 'Bilbo Baggins', hobbits)

-1

Include a paragraph on problem, challenges, and overall approach, as docstrings in your code.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值