+ 4

[ASSIGNMENT] Shortest common supersequence

Given X and Y two strings code a program finding their shortest commpn supersequence C so that X and Y can be obtained from C only by supressing letters and C's size is as low as possible. Ie abcdf + bde => abcdef or abcdfe but not efdcba (you can recreate the two strings just by suppressing letters) Test (the result can be different in some cases but needs to be as small) ("abcbdab","bdcaba"),"abdcabdab ("123456","abcdef"),"123456abcdef" (or any variation like 1a2b3c4def56") ("gatctga","atct"),"

4th May 2018, 8:31 PM
VcC
VcC - avatar
25 Answers
5th May 2018, 11:23 AM
LukArToDo
LukArToDo - avatar
5th May 2018, 3:04 AM
John Wells
John Wells - avatar
+ 6
I believe (UPD: I'm sure now) that this should work as a solution for such task: https://code.sololearn.com/cjAavVl4mZrC/?ref=app It is based on the previous one for the related task (https://www.sololearn.com/Discuss/1254598/?ref=app): https://code.sololearn.com/cpsKMKAAHnS3/?ref=app It demonstrate the same complexity by time and memory, however I assume that a better one based on dynamic programming with memoization can be found for both tasks...
5th May 2018, 1:28 AM
Nevfy
+ 3
Still struggling on the dynamic programming version, but here is my oneliner recursive solution. https://code.sololearn.com/cWl0szMe2gAZ/#py
5th May 2018, 9:10 AM
VcC
VcC - avatar
+ 3
VcC my program does solve your test cases, if you don't enter two strings. Just hit submit at the prompt without typing anything.
5th May 2018, 11:54 AM
John Wells
John Wells - avatar
+ 1
@JPM7 You can also try the second one from @VcC challenges on about this topic: https://www.sololearn.com/Discuss/1254598/?ref=app @VcC Will we also get a longer example to test the performance of solutions?
5th May 2018, 12:34 AM
Nevfy
+ 1
~ swim ~ You should be able to make X and Y out of C just by removing characters
5th May 2018, 4:47 AM
VcC
VcC - avatar
+ 1
Not saying this is not an interesting challenge but not the one i proposed :-)
5th May 2018, 7:52 AM
VcC
VcC - avatar
+ 1
@JPM7 Not exactly about the topic, but good reading anyway. The first one can be applied for 3SUM challenge: https://www.sololearn.com/learn/5461/ If I remember it well @VcC has such solution published.
6th May 2018, 10:59 PM
Nevfy
+ 1
Since nobody else didn't want to demonstrate the solution based on dynamic programming with memoization approach, I have done it by my own: https://code.sololearn.com/cBB5qa7mEtXz/?ref=app It is based on the previous one for the related task (https://www.sololearn.com/Discuss/1254598/?ref=app). See this code for realization of this approach for the previous task: https://code.sololearn.com/c7W8OV49STkF/?ref=app Its time and memory complexities should be both equal to O(N*M), where M and N - lengths of input strings. However, I'm not the expert in a field, so feel free to test it and inform me about any bugs that you have met!
7th May 2018, 4:55 AM
Nevfy
+ 1
Nevfy my code includes a dynamic programming solution https://code.sololearn.com/csH8yT3oNfBJ/?ref=app
7th May 2018, 5:18 AM
VcC
VcC - avatar
+ 1
@VcC Oh, I see. I think you added it after I saw it the last time, so I didn't mention this fact. Sorry. Nevertheless, this is a code, which solves your previous challenge (longest common substring), but not this one. However, it is easy to convert. ;-)
7th May 2018, 5:23 AM
Nevfy
0
John Wells JPM7 Can you use the suggested test cases ?
5th May 2018, 4:48 AM
VcC
VcC - avatar
0
Louis No see what i told to ~swim
5th May 2018, 4:51 AM
VcC
VcC - avatar
0
~ swim ~ youe solution does not seem to solve the problem i proposed...
5th May 2018, 6:31 AM
VcC
VcC - avatar
0
Letters look to be in the wrong order.
5th May 2018, 7:13 AM
VcC
VcC - avatar
0
Note: fast methods to do this are used to process genetic codes and recognize common patterns in genes.
5th May 2018, 10:48 AM
VcC
VcC - avatar