Question: In class we learned Morse Code. Because it is not a prefix code, we've seen that a code can be interpreted in several different ways.

In class we learned Morse Code. Because it is not a prefix code, we've seen that a code can be interpreted in several different ways. For example, ".-.-" can be interpreted as AA, EK, RT, and so on.
We use \( s[c]\) to denote the number of strokes of a letter \( c \). Here we only consider upper case letters. The number of strokes are also provided in the parentheses after each letter. There are of course multiple ways to handwrite a letter, and here I'm using a common version appearing in many letter written templates. For some reason, for the same morse code, we prefer those interpretations with fewer strokes.
Given a Morse code \( X \)(a string consisting of . and -), we want to know, among all the possible interpretations of \( X \), which one uses the smallest number of strokes. For simplicity, assume we have a unit-cost function check \((X, i, j, c)\) that checks if the substring \( X[i .. j]\) is the Morse code for character \( c \). For example, check \(\left(X,2,5,{}^{\prime}\mathrm{B}\right.\)') checks if the second to the fifth character in \( X \) is "-..."(the Morse code for 'B').
As an example, consider \( X=\)".-.". There are many possible interpretations for \( X \) : AA (6 strokes), EK (5 strokes), RT (4 strokes), ETET (10 strokes), and so on. The fewest strokes we can get is 4.
(1)(0.5pts) What is the Morse code for word "UCR"? Is there any other interpretations of UCR's code (if there's no separator)? Please list at least three of them, and at least one of them should have length \(\leq 4\). Which of them have the fewest strokes?
(2)(1.5pts) Design an algorithm for the above task: given a Morse coding string \( X \), find the one with the fewest strokes among all possible interpretations of \( X \).(Hint: You can use \( f[i]\) to denote the fewest strokes you could get using first \( i \) elements in \( X \).)
(3)(0.5pts) What is the time complexity of your algorithm?
(4)(0.5pts) Use your algorithm to compute: what is smallest number of strokes you can get by interpreting string "--..-."? Assume you only use the following letters A (3 strokes), C (1 stroke), E (3 strokes), G (2 strokes), K (2 strokes), and T (2 strokes).
In class we learned Morse Code. Because it is not

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!