We say that the string x = x1x2 ... xn is a subsequence of the string y = y1y2 ... ym in the usual way: and there are indices such that, . The goal is a greedy strategy to test in O(n+m) time whether x is a subsequence of y (no code is required)
(a) Describe the greedy choice
(b) Justify the correctness of your greedy choice.
X can be non contigous subsequence of Y if all the characters of X appears in Y and in that order.
Below is the C++ code I hope that i have provided sufficient comments for your better understanding
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s,t;
int len1,len2,i,j;
//Take input from user
cout<<"Enter 1st string : ";
cin>>s;
cout<<"Enter 2nd string : ";
cin>>t;
//store length of both the strings
len1=s.size();
len2=t.size();
//i will keep track of current index for string s
//j will keep track of current index for string t
i=0;j=0;
while(i<len1&&j<len2)
{
//character in "t" is matched with "s"
//move forward in "t" to check for its next character
//move forward by incrementing "j"
if(s[i]==t[j])
{
j++;
}
//move forward in s whether character is matched or not
i++;
}
//We reached end of string "t"
//means all the characters are found in "s"
if(j==len2)
{
cout<<t<<" is non contigous substring of
"<<s;
}
else
{
cout<<t<<" is not non contigous substring of
"<<s;
}
return 0;
}
Below is the screenshot of output-
Here since both the strings are to be travelled atmost once and the strings are of length m and n hence time complexity =O (m+n)
b) Since we are travelling both the strings without skipping any character hence we will always obtain the correct solution that is whether the string is a subsequence of other string or not.
Hope i have answered your question satisfactorily.Leave doubts in
comment section if any.
We say that the string x = x1x2 ... xn is a subsequence of the string...
are order statistics from same distribution . Sample size is 3. Define and Finding marginal density of . We were unable to transcribe this imageplz) = 1 We were unable to transcribe this imageWe were unable to transcribe this imageWe were unable to transcribe this imageWe were unable to transcribe this image
(6) . We pick samples randomly from the population which distributes uniformly between the interval of. . Answer the following questions regarding the median of the samples Show that the distribution which follows has the distribution as shown below. Find the expected value of . Show = . When , show that is the consistent estimator of . We were unable to transcribe this imageWe were unable to transcribe this imageWe were unable to transcribe this imagen = 2m...
are order statistics from same distribution . Sample size is 3. Define and Finding joint density of and . We were unable to transcribe this imageplz) = 1 We were unable to transcribe this imageWe were unable to transcribe this imageWe were unable to transcribe this imageWe were unable to transcribe this imageWe were unable to transcribe this image
If X is a Poisson random variable with parameter ?, show that the Tchebyshev’s inequality will indicate P(0 < X < 21) >1–
For , let be the order statistics of independent draws from . (1) Find the PDF of . (2) Compute . We were unable to transcribe this imageWe were unable to transcribe this image(2n+1 Unif -1,1 We were unable to transcribe this imageWe were unable to transcribe this image
0Let X1, ....., Xn be iid Random variable from a Uniform distribution with pdf given by . (1) Is the 2-dimensional statistics T1(X) = (X(1), X(n)) a complete sufficient statistics? Justify your answer (2) Is the one-dimensional statistic a complete sufficient statistic? Justify your answer We were unable to transcribe this imageWe were unable to transcribe this imageWe were unable to transcribe this image
There are 30 people that donated to a church. The amount each person donated has probability density function Find out the probability that exactly 5 people donated between 20 and 30. ,(1)-(*(50-r), (50-x), ifo ifo < x < 50 otherwise TA
Give algorithms for generating random variables from the following distributions. b. 1-2 if 0<<1
Let be the distribution function defined by Let be the Lebesgue-Stieltjes measure asociated to . Determine the measurements of the fpllowing sets: We were unable to transcribe this imageF(x) = 0 if 1+r if 2+x? if 19 if I <-1 -1 <r <0 0<r<2 > 2 We were unable to transcribe this imageWe were unable to transcribe this imageWe were unable to transcribe this imageWe were unable to transcribe this image(-1, 0]υ (1,2) 10, ) U (1, 2 (1 :...
Using the result of exercise 7(see question 7 below), give algorithms for generating random variables from the following distributions. b. 1-2 if 0<<1 7. (The Composition Method) Suppose it is relatively easy to generate random variables from any of the distributions F,,-I, . . . , n. How could we generate a random variable having the distribution function 12 i-1 where p,, -1.... . n, are nonnegative numbers whose sum is 1?