# design problem

Discussion in 'C' started by nizzy, Mar 8, 2010.

1. ### nizzyNew Member

Joined:
Mar 8, 2010
Messages:
1
0
Trophy Points:
0
[FONT=&quot]You are given two strings. Write an algorithm that creates a third string such that it contains both the given strings and it should be the smallest possible string. There is no condition regarding order of occurrence of given strings in the third string. Implement your algorithm in C++ using classes.[/FONT]
[FONT=&quot]For Example: [/FONT]
[FONT=&quot]a)[FONT=&quot] [/FONT][/FONT][FONT=&quot]S1=”hello” [/FONT]
[FONT=&quot]S2 = “loot”[/FONT]
[FONT=&quot]S3= “helloot” [/FONT]
[FONT=&quot]S3 = “helloloot” //Incorrect as S3 is not the smallest possible string[/FONT]
[FONT=&quot]b)[FONT=&quot] [/FONT][/FONT][FONT=&quot]S1= “hello”[/FONT]
[FONT=&quot]S2 = “Delhi”[/FONT]
[FONT=&quot]S3 = “helloDelhi” or “Delhihello”[/FONT]
[FONT=&quot]Expectations:[/FONT]
[FONT=&quot]a.[FONT=&quot] [/FONT][/FONT][FONT=&quot]Write the algorithm to concatenate two given strings. [/FONT]
[FONT=&quot]b.[FONT=&quot] [/FONT][/FONT][FONT=&quot]Modify your algorithm so that it creates the third possible string.[/FONT]
[FONT=&quot]c.[FONT=&quot] [/FONT][/FONT][FONT=&quot]Implement your algorithm in C++.[/FONT]
[FONT=&quot]d.[FONT=&quot] [/FONT][/FONT][FONT=&quot]Make a comparison of above two algorithms on the basis of time and space complexity.[/FONT]
[FONT=&quot]e.[FONT=&quot] [/FONT][/FONT][FONT=&quot]Can this problem be solved using iteration and recursion? Which one you will prefer and why? [/FONT]
[FONT=&quot] [/FONT]

Joined:
Nov 24, 2009
Messages:
387