当前位置:天才代写 > 作业代写,留学生作业代写-北美、澳洲、英国等靠谱代写 > Exercise代写 练习代写 String Search代写

Exercise代写 练习代写 String Search代写

2020-08-27 11:43 星期四 所属: 作业代写,留学生作业代写-北美、澳洲、英国等靠谱代写 浏览:1374

Exercise代写

Exercise 6 – Karp‐Rabin String Search

Exercise代写 For this exercise, you are to implement the Karp‐Rabin string search algorithm. Due by the end of your Week‐9 laboratory class.

Exercise代写
Exercise代写

 Due by the end of your Week‐9 laboratory class. (2 marks)

 This exercise is to be done before or during your week 9 laboratory class. Exercise代写

When you complete the exercise show your work to your lab tutor to have your work marked. The marking is based mainly on correct implementation and code readability. You should implement your code in one file (e.g. ex6.cpp, ex6.c, ex6.java). Make sure your program has a header comment block containing the name of the exercise, your name and your student login (e.g. jfk01). You may implement your solution in C, C++, Java or Python.

For this exercise, you are to implement the Karp‐Rabin string search algorithm.Exercise代写

Your program should prompt for the name of an input file and then read and process the data contained in the file.

The file contains two sequences of characters on separate lines of test. 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.Exercise代写

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. The sequence T is no longer than 5000characters
  2. The sequence S is no longer than 10characters
  3. The alphabet used in both sequences consists of the letters, A, C, G and T; the DNA base sequences.
  4. Choose an appropriate modulus, m, for the hash
  5. Try to make your hash computation as efficient as

When you are finished, test your program using the provided text file named “ex6.txt” and show your code and the output to your lab tutor to receive your mark.Exercise代写

$ submit -u login -c CSCI203 –a ex6 filename

where ‘login‘ is your UNIX login ID and ‘filename’ is the name of your file.

If you are unable to attend your lab class and demonstrate your work on time due to circumstances beyond your control (e.g. sickness), contact your lecturer to request an extension.

Pseudo Code Exercise代写

define the number of chars in the input alphabet d (e.g. 256) 

define a suitable prime number q (e.g. 101)

main()

           try to open input file,

           print error & exit if the file is not found

           read the text T

           read the search pattern S and close the file

           // make sure you can access the chars with an            index (e.g. T[i])

           get the length of T and S => n, m


           //calculate the hash factor 

           h = pow(d, m-1)


           hash_s = hash(S,m) 

           hash_t = hash(T,m])

 
            for (i = 0; i < n-m; i++)

            if hash_s == hash_t then

             compare S and the substring of T to confirm

             if match print(“String found at location:                         “ i)

           end if

           // cal next rolling hash key

           hash_t = roll( hash_t, t[i], t[i+m], h ) 

      end for

end main


// Rolling hash fn: Calculates hash value for next substring int roll (int ht, int c1, int c2, int h)

  // Remove leading char and add trailing char to hash value 

   ht = ( d * (ht - c1*h) + c2 )% q;

   f ht is neg add q 

   return ht


 end roll()


// return d exp e mod q 

int pow(int d,int e)

   int p=1;

   for (int i = 0; i < e; i++) 

       p = (p*d)%q;

     return p; 

end pow()


// returns rolling hash hey of str 

int hash( str, int m )

   int h=0;

   for (int i = 0; i < m; i++) 

      h = ((d*h)+ str[i]) % q;

   return h; 

end hash()
Exercise代写
Exercise代写

更多其他:app代写  assignment代写 C++代写 CS代写 程序代写 程式代写 算法代写 经济代写 统计代写 统计作业代写 编程代写 英国代写 计算机代写 金融代写

合作平台:天才代写 幽灵代写  写手招聘 Essay代写

 

天才代写-代写联系方式