The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 304 Weeks Ago, 5 Days Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
For Intro to Python Class
Â
DNA molecules consist of a sequence of the four nucleotide bases: adenine, thymine, cytosine, and guanine. The nucleotide bases are often abbreviated by their first letter, ATCG) so that DNA is represented as a string of these four letters. A DNA string can be millions of bases long.
One important problem on DNA strings is substring matching, which is the task of checking whether a shorter substring is contained within a longer string. Obviously, finding a substring in a long string has many interesting applications, but here we will focus on DNA sequences.
Python strings already provide an s.find(substring) method that returns the index in s at which substring first appears. If the substring does not appear, the method returns -1. For example: "ATCGCGTACT".find("CGCG") returns 2, but "ATCGCGTACT".find("CGAT") returns -1.Â
(a) Without using the existing find method of Python strings, write a function find(s, substring).
that does the same thing as the find method. If the substring appears in s, the method should return its index, otherwise it should return -1. Write the function in the file problem2.py.Â
(b) Without using the existing find method, write a function find_multi(s, substring).
that returns a list of the indices of all occurrences of the substring. If the substring is not found, the function can return an empty list. Make sure your function can handle overlapping substrings. For example:Â
find_multi("ATGCGCGAT", "GCG") should return [2,4].
Add the function in the file problem2.py.Â
(c) In the worst case, how many character comparisons are required by your algorithm in part (a)? Does the algorithm in part (b) need to make more comparisons? The answer does not need to be exact. Add your answer as a comment at the top of problem2.py.
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly