Menu

[solved]-Given Two Words W1 W2 Say W1 Subsequence W2 Letters W1 Appear W2 Order Necessarily Togethe Q38994849

Given two words, w1 and w2, we say w1 is a subsequence of w2 if all the letters in w1 appear in w2 in the same order (but not

def add_chars(w1, W2): Return a string containing the characters you need to add to wl to get w2. You may assume that wl is a

Given two words, w1 and w2, we say w1 is a subsequence of w2 if all the letters in w1 appear in w2 in the same order (but not necessarily all together). That is, you can add letters to any position in wl to get w2. For example, “sing” is a substring of “absorbing” and “cat” is a substring of “contrast”. Implement add_chars, which takes in w1 and w2, where w1 is a substring of w2. It should return a string containing the characters you need to add to w1 to get w2. Your solution must use recursion. In the example above, you need to add the characters “aborb” to “sing” to get “absorbing”, and you need to add “ontrs” to “cat” to get “contrast”. The letters in the string you return should be in the order you have to add them from left to right. If there are multiple characters in the w2 that could correspond to characters in wl, use the leftmost one. For example, add_words(“coy”, “cacophony”) should return “acphon”, not “caphon” because the first “c” in “coy” corresponds to the first “c” in “cacophony”. def add_chars(w1, W2): Return a string containing the characters you need to add to wl to get w2. You may assume that wl is a subsequence of w2. >>> add_chars(“owl”, “howl”) ‘h’ >>> add_chars(“want”, “wanton”) ‘on’ >>> add_chars(“rat”, “radiate”) ‘diae >>> add_chars(“a”, “prepare”) ‘prepre >>> add_chars(“resin”, “recursion”) ‘curo’ >>> add_chars(“fin”, “effusion”) ‘efuso’ >>> add_chars(“coy”, “cacophony”) ‘acphon’ >>> from construct_check import check >>> check(LAB_SOURCE_FILE, ‘add_chars’, [‘For’, ‘While’, ‘Set’, ‘SetComp’]) # Must use recursion True “*** YOUR CODE HERE ***” Show transcribed image text Given two words, w1 and w2, we say w1 is a subsequence of w2 if all the letters in w1 appear in w2 in the same order (but not necessarily all together). That is, you can add letters to any position in wl to get w2. For example, “sing” is a substring of “absorbing” and “cat” is a substring of “contrast”. Implement add_chars, which takes in w1 and w2, where w1 is a substring of w2. It should return a string containing the characters you need to add to w1 to get w2. Your solution must use recursion. In the example above, you need to add the characters “aborb” to “sing” to get “absorbing”, and you need to add “ontrs” to “cat” to get “contrast”. The letters in the string you return should be in the order you have to add them from left to right. If there are multiple characters in the w2 that could correspond to characters in wl, use the leftmost one. For example, add_words(“coy”, “cacophony”) should return “acphon”, not “caphon” because the first “c” in “coy” corresponds to the first “c” in “cacophony”.
def add_chars(w1, W2): Return a string containing the characters you need to add to wl to get w2. You may assume that wl is a subsequence of w2. >>> add_chars(“owl”, “howl”) ‘h’ >>> add_chars(“want”, “wanton”) ‘on’ >>> add_chars(“rat”, “radiate”) ‘diae >>> add_chars(“a”, “prepare”) ‘prepre >>> add_chars(“resin”, “recursion”) ‘curo’ >>> add_chars(“fin”, “effusion”) ‘efuso’ >>> add_chars(“coy”, “cacophony”) ‘acphon’ >>> from construct_check import check >>> check(LAB_SOURCE_FILE, ‘add_chars’, [‘For’, ‘While’, ‘Set’, ‘SetComp’]) # Must use recursion True “*** YOUR CODE HERE ***”

Expert Answer


Answer to Given two words, w1 and w2, we say w1 is a subsequence of w2 if all the letters in w1 appear in w2 in the same order (bu… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *