Question: Call two strings s 1 and s 2 similar if , for each distinct character in s 1 , it is possible to replace all

Call two strings s1 and s2 similar if, for each distinct character in s1, it is possible to replace all occurrences of it by another character (possibly itself) uniquely such that, after all replacements are done to s1, we end up with s2. For example:
The strings s1= "adt" and s2="bst" are similar, because the replacements 'a'->'b','d'->'s' and 't'->'t' transform s1 into s2.
The strings s1= "adt" and s2="dcc" are not similar. The only possible replacement 'a'->'d','d'->'c' and 't'->'c' does transform s1 into s2, but is invalid because it violates uniqueness (we have two characters that get replaced with 'c').
The strings s1="aa" and s2="bc" are not similar, because to transform s1 into s2 we need to replace 'a' with two different characters, but this is not allowed.
Note that the replacements must occur independently of each other (i.e. in the second example, we don't replace each 'a' by 'd' before replacing each 'd' by 'c', as the result would be that each 'a' also gets replaced by 'c').
Your task is to implement the following function in similar.c, using the HashTable ADT to write an algorithm that determines if two strings are similar:
bool areSimilarStrings(char *s1, char *s2);
Testing
similar.c contains a main function which allows you to test your areSimilarStrings function. It accepts two strings as command-line arguments which will be passed to your function. Here are some examples of its usage, and some expected outputs:
make
...
./similar adt bst
The strings are similar
./similar adt dcc
The strings are not similar
./similar aa bc
The strings are not similar
Call two strings s 1 and s 2 similar if , for

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!