Question: Write a function that returns the similarity score for two sequences. The similarity score for two sequences is calculated as follows: similarity_score = (string length
Write a function that returns the similarity score for two sequences. The similarity score for two sequences is calculated as follows:
similarity_score = (string length - hamming_distance) / string length
where hamming distance is a position-by-position comparison that counts the number of positions in which the corresponding characters in the string are different. Two strings with a small Hamming distance are more similar than two strings with a larger Hamming distance.
Example: first string = ACCT second string = ACCG
A C C T
| | | *
A C C G
In this example, there are 3 matching characters and 1 mismatch, so:
hamming_distance = 1 . And the similarity score for the two strings on this example would be, similarity_score = (4-1)/4 = 3/4 = 0.75
Your function MUST be named simScore
Your function should take two parameters in this order:
a string parameter for the first sequence
a string parameter for the second sequence.
Your function should return the similarity score as a double.
Your function should not print anything.
Edge Cases:
lengths of sequences are different return 0
either sequence is an empty string return 0
Examples:
Arguments and their expected return values for the simScore
| sequence1 | sequence2 | Similarity score |
| ATGC | ATGA | 0.75 |
| CCDCCD | CCDCCD | 1 |
| ATG | GAT | 0 |
| ACCDT | ACCT | 0 |
| CGT | DGGTA | 0 |
For example:
| Test | Result |
|---|---|
//2/3 match cout << simScore("AAG", "AAC"); | 0.666667 |
C++ Only
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
