Question: Has to be done in ipython, please assist with all question but mainly the complexity of the algorithm and meassuring the worst - case performance.
Has to be done in ipython, please assist with all question but mainly the complexity of the algorithm and meassuring the worstcase performance. i believe that the magic command timeit is required for this.
Introduction:
DNA strands are composed of sequences of chemical units known as bases, designated by the letters A C G or T These letters represent the bases' chemical names, allowing DNA sequences to be represented as strings, such as 'CAGTATGGCCA'. This representation enables us to manipulate DNA sequences in Python as ordinary strings. Typically, DNA strands are extensive, often comprising millions of bases, though the examples we use here will be much shorter. Our objective is to identify the longest common substring between two character sequences. A substring requires that the characters appear consecutively in both sequences.
For instance, is a subsequence of TATCCG but is not a substring. Conversely, ATC is a substring of TATCCG because the sequence A T C is contiguous in the longer sequence. It s crucial to grasp this distinction!
This analysis is vital for identifying similar genetic structures or sequences within DNA, such as genes or other chromosomal configurations.
Our goal is to create a function that determines the longest common substring between two character strings, referred to as 'left' and 'right'. While our examples will simulate DNA sequences containing only the characters A C G T the function should be applicable to any valid character string. For this task, you are to adopt a brute force or exhaustive search strategy and develop the function progressively, as detailed in the subsequent steps.
Question a :
Develop and test a Python function named 'common pair'. This function should verify if any pair of consecutive characters in the string 'left' matches with any pair in 'right'. It should return the first matching pair of characters if found, or an empty string if no matches are detected.
Question b :
Craft and evaluate a new Python function titled 'common substring', which uses the parameters 'left' and 'right' as in part a but also incorporates an additional integer parameter 'length'. This function should ascertain whether any substring consisting of 'length' characters from 'left' matches with any substring of the same length in 'right'. The function should return the first found matching substring of 'length' characters, or an empty string if no match exists.
Question c :
Develop and validate a function named 'longest common substring', utilising the parameters 'left' and 'right' as described in part a This function is tasked with identifying the longest contiguous matching segment between 'left' and 'right'. It should return the longest common substring found, or an empty string if no such substring exists.
Question d :
Discuss if you anticipate variations in the best case and worst case complexities for the 'longest common substring function'. Evaluate the worst case complexity of your function. It might be useful to denote the lengths of left L and right R To prevent confusion with lowercase letters, uppercase letters have been used in this context. Apply either Big Theta notation or Big Oh notation appropriately.
Question e i :
Evaluate the actual worst case performance of the function 'longest common substring' for a range of suitable inputs. You will need to make a number of measurements to see how the timing varies as L or R increases. Consider this reminder: basic arithmetic operations such as and can be leveraged with strings to construct extensive string representations efficiently.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
