CPSC 413 Fall 2019 — Assignment 3 Due no later than Friday, November 8, 2019, 10:30am This assignment consists of (1) one problem and (1) one bonus programming problem. The bonus programming problem will be posted as a separate part. Full answer (100%) is 10 points plus 6 bonus points. Collaboration and plagiarism You are welcome to work and discuss the assignment with other students enrolled in this course (i.e., CPSC 413 — Fall 2019). You must clearly state whom your collaborators are, if any, for each problem on the assignment. Verbal collaboration is allowed. Written collaboration is dis-allowed. No collaboration can use any form of written material. While discussing this assignment with other enrolled students, the following aids are strictly forbidden: papers, notes, notebooks, textbooks, webpages, email, twitter, facebook, sms, messages, whiteboards, blackboards, etcetera. All written work that you submit must be your own sole work. Anything else will be considered plagiarism. All collaborations must take place on an equal footing, where all parties contribute equally to the discussion. Any conversation must be ended if all parties are not contributing equally. The use of published literature is allowed. If you use any published literature (texts, articles, websites, etc) to complete your assignment, you must quote your sources. I suggest that you develop your own solutions however, without the use of any published materials. You will be asked to answer similar questions on the exams for this course and during the exams no such sources will be available. Note that no collaborations or sources are allowed for the bonus programming problem. You may read about the regulations on plagiarism in the calendar here: http://www.ucalgary.ca/pubs/calendar/current/k-2.html. If you have any doubt whether a collaboration is allowed or not, ask the lecturer before entering the collaboration. Cover page The second last page in the assignment is a cover page. Put your name and TA lab on the cover page and submit your assignment with the cover page as the first page of your submission. Use a single staple in the upper left corner to staple all of your sheets of paper together. Assignments diverging from these guidelines, including being submitted without the cover page, or submitted with incorrectly filled cover page, will be deducted 1 or more points. Submission You may turn in your assignment using the drop boxes on the ground floor in the math science building (MS), or by giving your assignment in person to one of the TAs or the instructor. You must submit your assignment on or before Friday, November 8, 2019, 10:30am. Note that 10:30am is in the morning. No late submissions will be accepted. The deadline is firm. On the assessment of your work The assessment will include an evaluation of the writing and communication style. We want the writing to be succinct, precise, unambiguous, and written with clarity. When applying and analyzing algorithms, we want to use examples and counter-examples that are among the simplest and most transparent instances that convey our message. We want the order and structure of our text to be logical. You can find information and guidelines about writing about algorithms on the D2L Discussion Board under the topic “Assignments”. 1 Problems 1. String Addition Problem (10 points) We are given a string X = x1 x2 · · · xn of length n over the alphabet {a, b, c, d} of size 4. We can add any two symbols together according to the following table. ⊕ a b c d a b b a b b c b a c c d c c d d b a b c For instance a ⊕ b = c, b ⊕ a = b, and b ⊕ d = a. Our addition operation is not commutative since for instance a⊕b 6= b⊕a. Our addition operation is neither associative since for instance (a ⊕ b) ⊕ c 6= a ⊕ (b ⊕ c). We want to know if there is a way that we can add the characters in X together so that the resulting value is c. On the input abccbdc, the answer is “Yes” because a((bc)c) (bd)c = a(cc) (bd)c = ac (bd)c = d (bd)c = d ac = d d = c. Note that we are not allowed to swap elements in the string X. String Addition Problem Input: a string X = x1 x2 . . . xn of length n over the alphabet {a, b, c, d}. Output: “Yes” if it is possible to parenthesize the string X in such a way that the string evaluates to c. “No” otherwise. 1. Give a polynomial-time (in n) dynamic programming algorithm for the String Addition Problem problem. State your algorithm clearly and succinctly in the following order: (a) Very clearly state the recurrences you are using. Justify your choice of recurrences. (b) Explain the base cases of your recurrences. (c) Explain how you compute the output of your algorithm from your recurrences. (d) Show how you implement your recursive algorithm in polynomial time using a twodimensional array A. Clearly state what each entry A[i, j] contains. (e) Argue why your algorithm is correct. (Or, if it is not correct, explain why and what may be missing.) (f) Briefly explain why your algorithm runs in time polynomial in n. (g) Using the back side of the cover page, for the input abccbdc, show the complete array A that is generated by your own algorithm. It suffices that your algorithm outputs the correct answer “Yes” or “No”. Your algorithm does not need to output the parenthesization. 2 Cover page CPSC 413 Assignment 3 Fall 2019 Name: Lab section: T01 Mon 15:00 T02 Tue 11:00 T03 Tue 14:00 T04 Mon 17:00 T05 Mon 11:00 My sources and my collaborators, if any, on the problems were: Problem 1: Bonus programming problem: No collaboration permitted On the input abccbdc, my dynamic programming algorithm produces the following array A: 4