Question

5 Comparing Substrings Here youll evaluate running times of algorithms whose input size is expressed using two parameters. Let T[l.n] and T[1.n] be strings of length n, over a finite alphabet (For example, T and T might be over the alphabet {A, C, G, T), and represent DNA strands.) A function Match indicates whether or not a letter of T matches a letter of T. That is, for 1 i,j Sn, Match(i,j) = 1, =0, if7h otherwise. =TLi] Fix k,1 S k Sn. For 1 S i,j s n-k+1, the score of any two length-k substrings Tii + k-1] and TLİ.j + k-1] of T and T respectively is given by k-1 Σ Match(i + l, j + 1). Algorithm Compute-Scores below computes all scores and stores them in a two-dimensional array called Score. Assume that calls to function Match take Θ (1) time and that array Score has already been created. Algorithm Compute-Scores (T[1.n), T [I.n],k) // T and T are length-n strings and 1 S kSn For i from 1 to n-k + 1 For j from 1 to n - k+1 // compute score of Tli..i+ k-1] and TUj +k-1] and store in Scoreli, j] Scoreli,jl - E Match(i+L,j +l)

  

1. What terms below describe the worst-case running time of this algorithm? Check all answers that apply. Here, a term e(f (n, k)) is correct if for any choice of k in the range [1.n], the algorithm runs in O(f(n, k)) time, and for some choice of k in the range [1..n] (where k may be expressed as a function of n), the algorithm runs in Ω(f(n, k)) time. This work is licensed under a Creative Commons Attribution- NonCommercial 4.0 International License. eos For license purposes, the author is the University of British Columbia. 2. Modify the algorithm of part 1, to improve the runtime by a factor of k. 3. What is the worst-case running time of your algorithm of part 2? Try to find as simple an expression as possible.

1st photo is the introduction. 2nd photo are the questions. Thanks in advance!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Ans .1 -> Theta left ( (n-k)^{2}k ight ) is the time complexity of given algorithm .

Theoratical proof-> Match() function is used in summation with range (0) to (k-1) so the time complexity is k

there are two loops Outer loop and inner loop

Outer loop is having range i=1 to i = (n-k+1) so total time complexity of this loop is (n-k)

Inner loop is having range j=1 to j = (n-k+1) so total time complexity of this loop is (n-k)

for every (Outer loop )i , (inner loop) j runs n-k times. And for every j Match() function is called k times

So for (n-k) times of i , j will run (n-k)*(n-k) times and for (n-k)*(n-k) j , match function will be called (n-k)*(n-k)*k times

Ans 2 ->We know this algorithm is simply computing the total matching in substring of size k

Here Score[i,j] contains matching no of elements in substring of length k starts with index i in first string and starts with index j in second string

Algorihtnm Compute-Scores

osithm Compets Scove // il Match(i.)= L sco ㎘wİ,U incrunas Scoru [i,1]s Match (id) fom i rom k to n Poy 1 11om kto nThis algorithm is using only 2 loops without any summation

First we are computing in score array total score till I,j the we are subtracting previous results before substring of length k

Its Time complexity is Θ (n2)

Ans 3-> Its worst case Time complexity is Θ (n2)

Thanks for Question

If you have any doubts Feel free to ask your queries.

Add a comment
Know the answer?
Add Answer to:
   1st photo is the introduction. 2nd photo are the questions. Thanks in advance! 5 Comparing...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1 question) Arrange the following in the order of their growth rates, from least to greatest:...

    1 question) Arrange the following in the order of their growth rates, from least to greatest: (5 pts) n3                     n2         nn        lg n     n!       n lg n              2n                     n 2 question)Show that 3n3 + n2 is big-Oh of n3. You can use either the definition of big-Oh (formal) or the limit approach. Show your work! (5 pts.) 3 question)Show that 6n2 + 20n is big-Oh of n3, but not big-Omega of n3. You can use either the definition of big-Omega...

  • Q1: Here we consider finding the length of the shortest path between all pairs of nodes...

    Q1: Here we consider finding the length of the shortest path between all pairs of nodes in an undirected, weighted graph G. For simplicity, assume that the n nodes are labeled 1; 2; : : : ; n, that the weight wij of any edge e = (i; j) is positive and that there is an edge between every pair of nodes. In this question, the goal is to solve this via dynamic programming. Note that the algorithm you will...

  • 1. (10 points) Write an efficient iterative (i.e., loop-based) function Fibonnaci(n) that returns the nth Fibonnaci...

    1. (10 points) Write an efficient iterative (i.e., loop-based) function Fibonnaci(n) that returns the nth Fibonnaci number. By definition Fibonnaci(0) is 1, Fibonnaci(1) is 1, Fibonnaci(2) is 2, Fibonnaci(3) is 3, Fibonnaci(4) is 5, and so on. Your function may only use a constant amount of memory (i.e. no auxiliary array). Argue that the running time of the function is Θ(n), i.e. the function is linear in n. 2. (10 points) Order the following functions by growth rate: N, \N,...

  • Part 3: Transposition Ciphers #can't use ord or chr functions You must implement three transposition ciphers...

    Part 3: Transposition Ciphers #can't use ord or chr functions You must implement three transposition ciphers (the "backwards" cipher, the Rail Fence cipher, and the Column Transposition cipher) where the ciphertext is created via an altered presentation of the plaintext. The algorithm for each is detailed in the function descriptions in this section. (13 points) def backwards_cipher(plaintext, key): • Parameter(s): plaintext ----- a string; the message to be encrypted key ----- an integer; the number to control this cipher •...

  • I really would appreciate some help with this assignment and include comments please as I am...

    I really would appreciate some help with this assignment and include comments please as I am in this for learning. Part I: Maximum increasing subsequence (adapted from Programming Exercise 22.2) Write a program MaxlncreasingSubseq.java that prompts the user to enter a string and displays a maximum length increasing subsequence of characters. Here are four sample runs Enter a string: zebras ers Enter a string: Welcome Welo Enter a string: mmmoooooovwwvee mov Enter a string: abqrstcxyzdefghij abcdefghij You must use dynamic...

  • Create C++ program.Convert this string to Tap Code using structures. It is very important to use structures in this program. The tap code is based on a Polybius square using a 5×5 grid of letters repr...

    Create C++ program.Convert this string to Tap Code using structures. It is very important to use structures in this program. The tap code is based on a Polybius square using a 5×5 grid of letters representing all the letters of the Latin alphabet, except for K, which is represented by C. The listener only needs to discriminate the timing of the taps to isolate letters. Each letter is communicated by tapping two numbers the first designating the row (Down) the...

  • A particular talent competition has five judges, each of whom awards a score between 0 and...

    A particular talent competition has five judges, each of whom awards a score between 0 and 10 to each performer. Fractional scores, such as 8.3, are allowed. A performer’s final score is determined by dropping the highest and the lowest score received then averaging the three remaining scores. Write a program that does the following: 1. Reads names and scores from an input file into a dynamically allocated array of structures. The first number in the input file represents the...

  • Deck of Cards Program I need help printing a flush, which is showing the top 5...

    Deck of Cards Program I need help printing a flush, which is showing the top 5 cards of the same suite. Below is the code I already have that answers other objectives, such as dealing the cards, and finding pairs. Towards the end I have attempted printing a flush, but I cannot figure it out. public class Shuffler {    /**    * The number of consecutive shuffle steps to be performed in each call    * to each sorting...

  • MATLAB EXERCISE 5 This exercise focuses on the Jacobian matrix and determinant, simulated resolved-rate control, and...

    MATLAB EXERCISE 5 This exercise focuses on the Jacobian matrix and determinant, simulated resolved-rate control, and inverse statics for the planar 3-DOF, 3R robot. (See Figures 3.6 and 3.7; the DH parameters are given in Figure 3.8.) The resolved-rate control method [9] is based on the manipulator velocity equation x = kve, where ky is the Jacobian matrix, is the vector of relative joint rates, X is the vector of commanded Cartesian velocities (both translational and rotational), and k is...

  • please answer as many questions as possible. I will “thumb up” the answers. Thanks! 1. You are on a boat, which is bobbing up and down. The boat's vertical displacement y is given by y 1.2...

    please answer as many questions as possible. I will “thumb up” the answers. Thanks! 1. You are on a boat, which is bobbing up and down. The boat's vertical displacement y is given by y 1.2 cos(t). Find the amplitude, angular frequency, phase constant, frequency, and period of the motion. (b) Where is the boat at t 1 s? (c) Find the velocity and acceleration as functions of time t. (d) Find the initial values of the position, velocity, and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT