Question: C++ program using Karp-Rabin Algorithm. The Karp-Rabin algorithm looks like this: hash_s=hash(s) hash_t=hash(t[0..length(s)-1]) for i in 0length(t)-length(s) if hash_s == hash_t then brute-force compare s
C++ program using Karp-Rabin Algorithm.

The Karp-Rabin algorithm looks like this:
hash_s=hash(s) hash_t=hash(t[0..length(s)-1]) for i in 0length(t)-length(s) if hash_s == hash_t then brute-force compare s and the substring if they match print( string found starting at location i) end if hash_t=roll(hash_t,t[i],t[i+length(s)]) rof
The function roll(h,p,s) computes the rolling hash of the next substring given the hash of the existing substring, h, with the prefix p removed and the suffix, s, appended.
Please use this as test data which will be read from the text file:
ATTGGTAAATACGGCTGTACGGTGCCGACTAAGCGGAATAGCCTACCACGTTACGGTATCTTCTTGCAAGTGTATTCTCGCACCTTAATTGTATCGGGAAGTAGGTTATGATGATAGAGACCCCCCCGGCACAAAACTTTCGGTAAGTGGAGCGCCCGACTGGCCGCCGGGATCAGAACGAACGATGCCCAGGGGCCGGCGGGCGATGAGCGACTTCGACGACCCAGGCTACGAATTCCCTGCCGACCCATTCTTGATGAAAAGCCCTGCTTCGGGACTGTCTGAAAATCTGTTTTTAGGGCACTTTGTCTCTTTCAAGGCAGTCCCTGGCGTGCTATCCGCATGGACATATCGCCATGACGACGATTGACCAGAGCAGCCTCAAAGTGGCAAATTCCTAACAGGCACCTACTTAGATGCGACGAGTAAAGCGCCGGGAAAGGTAACATGAACGGTTGAAAAATACAACGAGATACCGGGAGGGAAACTAGCAGATGCTCGGACATAGCACTCTGGGTCGCCGGAGGTGCCAAGTTAAAGCGCAACCAAGACTGGATCTGCCATCTCCTAAAGGGGAGCTGCTACCTACACATACTGTTCTCGTTGGATCGACCTTGCGTATATCCTGGGATCCACTACTTTGAATCACAGGAGCTACCCCTCGTATGGCTGATTGGCGGCCACCGTTTCCCGACAGACTGTCTGCTACGTTAGGTTACTAAATGACCGACAGCTAGACCGGGAGGTCAATTTTGGATTTCTATAGTCATCAACCACTGCGGTTGGCATCCCATAACCCGGCGCACTATGCTGCACACGAGGACTGTCAATAGCTTCGGCCACGCAGGCTAACGGCTCGAGGCATGGGTAAGGTTGCTCGAGCCGGCGCCACACCAGCTCTTACTCCATATCAGCCGGCGCGACCACAGGGAGGGCCAAAAGCGTGCGAAACATGCATCTACTCTCTCTACTCGCCGTCAAGCCAATTGTAGGACGGCAAATCGACATCTATGATCTTTGATCGAGCTA
As usual, your program will prompt for the name of an input file and the read and process the data contained in this file. The file contains two sequences of characters The first is the target sequence, T, the second is the search sequence S Read both strings and find all occurrences of sequence S in sequence T using the Karp-Rabin algorithm. For each matched sequence, print the location of the first matched character in T. For example, if the test data looked like this: ACGTACGTACCAGTA AC The output should be: 0,4, 8 Notes: 1. 2. 3. The sequence T is no longer than 5000 characters The sequence S is no longer than 10 characters The alphabet used in both sequences consists of the letters, A, C, G and T; the DNA base sequences Choose an appropriate modulus, m, for the hash function. Try to make your hash computation as efficient as possible. 4. 5
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
