A palindrome is a string that reads the same backwards and forwards. A complemen
ID: 3773033 • Letter: A
Question
A palindrome is a string that reads the same backwards and forwards. A complemented palindrome is one that when read backwards is the complement of the string reading forwards (the pairs A-T and G-C are considered complements). A maximal palindrome is one that is not contained in any other. For example, in the string "ATATGAGGAGGCCT" the substrings “AGGCCT” are maximal complemented palindromes.
(a) Write algorithms that determine all maximal palindromes and complemented palindromes for a given input string.
(b) What are the running times of your algorithms?
(c) Implement and test your algorithm on a DNA sequence.
Explanation / Answer
(a)
Function longest_Palindrome(strIn)
For lngCnt1 = Len(strIn) To 2 Step -1
lngCnt = lngCnt1 2
strPal = vbNullString
For lngCnt2 = lngCnt To 1 Step -1
strPal = strPal & "(" & lngCnt2 & ")"
Next
If lngCnt1 Mod 2 = 1 Then strPal = "(.)" & strPal
Set objRegex = CreateObject("vbscript.regexp")
With objRegex
.Pattern = Replace(Space(lngCnt), Chr(32), "(.)") & strPal
If .Test(strIn) Then
Set objRegM = .Execute(strIn)
Palindrome = objRegM(0)
Exit For
End If
End With
Next
End Function
(b)k if this longest matching substring is actually a palindrome which has the running time of O(n^3).
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.