Can anyone help me come up with a solution to this problem I found in my textbook please?
imgur: the simple image sharer
Thanks!
Can anyone help me come up with a solution to this problem I found in my textbook please?
imgur: the simple image sharer
Thanks!
Start with any algorithm that gives the correct answer. Figure out where inefficiency arises and alter the algorithm to reduce it. Depending on the definition your book gives for "efficient", this may require several attempts until you get an efficient algorithm.
Example: If the length of a is smaller than the length of b, have the algorithm return the result when the sequences are swapped. Then, find the longest subsequence of $\displaystyle a$ that is also a subsequence of $\displaystyle b$. Then, proceed to add digits to the sequence $\displaystyle a$ until $\displaystyle b$ is a subsequence in its entirety.
This algorithm is not well defined, but it gives a basic idea of the process. It is probably extremely inefficient, since finding the longest subsequence of $\displaystyle a$ that is also a subsequence of $\displaystyle b$ requires checking all possible subsequences of one of the two and comparing it to the other.