Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stephenhandley/16941506cf6d2c5732b7 to your computer and use it in GitHub Desktop.
Save stephenhandley/16941506cf6d2c5732b7 to your computer and use it in GitHub Desktop.
Potential bug with FrequentWordsWithMismatches pseudocode in "Finding Hidden Messages in DNA" book
FrequentWordsWithMismatches(Text, k, d)
FrequentPatterns ← an empty set
Neighborhoods ← an empty list
for i ← 0 to |Text| − k
add Neighbors(Text(i, k), d) to Neighborhoods
form an array NeighborhoodArray holding all strings in Neighborhoods
for i ← 0 to |Neighborhoods| − 1
Pattern ← NeighborhoodArray(i)
Index(i) ← PatternToNumber(Pattern)
Count(i) ← 1
SortedIndex ← Sort(Index)
for i ← 0 to |Neighborhoods| − 1
if SortedIndex(i) = SortedIndex(i + 1)
Count(i + 1) ← Count(i) + 1
maxCount ← maximum value in array Count
for i ← 0 to |Neighborhoods| − 1
if Count(i) = maxCount
Pattern ← NumberToPattern(SortedIndex(i), k)
add Pattern to FrequentPatterns
return FrequentPatterns
FrequentWordsWithMismatches(Text, k, d)
FrequentPatterns ← an empty set
Neighborhoods ← an empty list
for i ← 0 to |Text| − k
add Neighbors(Text(i, k), d) to Neighborhoods
form an array NeighborhoodArray holding all strings in Neighborhoods
for i ← 0 to |NeighborhoodArray| − 1
Pattern ← NeighborhoodArray(i)
Index(i) ← PatternToNumber(Pattern)
Count(i) ← 1
SortedIndex ← Sort(Index)
for i ← 0 to |NeighborhoodArray| − 1
if SortedIndex(i) = SortedIndex(i + 1)
Count(i + 1) ← Count(i) + 1
maxCount ← maximum value in array Count
for i ← 0 to |NeighborhoodArray| − 1
if Count(i) = maxCount
Pattern ← NumberToPattern(SortedIndex(i), k)
add Pattern to FrequentPatterns
return FrequentPatterns
@OmarLaham
Copy link

Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment