MaveRick12
BAN USER- 0of 0 votes
AnswersHow to perform string matching using suffix tree? (code)
- MaveRick12 in United States| Report Duplicate | Flag | PURGE
void Partition(int data[], int size1, int low, int high)
{
int p = -1;
int q = size1;
for (int i = 0; i < q;)
{
if (data[i] < low)
{
swap(data[i], data[++p]);
++i;
}
else if (data[i] > high)
swap(data[i], data[--q]);
else ++i;
}
}
//low=5 and high=5
read floyd cycle detection algo.
- MaveRick12 February 11, 2014This solution takes O(nlogn)+O(n) time.
int main()
{
int n,i,j,t,k;
cin>>n;
int a[n];
for(i=0;i<n;i++) cin>>a[i];
sort(a,a+n);
cin>>k;
i=0;j=n-1;
while(i<j)
{
t=a[i]+a[j];
if(t==k)
{cout<<a[i]<<" "<<a[j];return 0;}
else if(t<k) i++;
else j--;
}
}
We can also solve this in O(n) time by Hashing.
{i=0;j=n-1;
while(i<=j)
{
if(a[i]==2&&a[j]==1)
{swap(a[i],a[j]);i++;j--;}
else if(a[i]==1) i++;
else if(a[j]==2) j--;
}
}
Black Box Testing is a software testing method in which the internal structure/ design/ implementation of the item being tested is NOT known to the tester and vice versa for White Box
- MaveRick12 February 10, 2014
What is 'pre' here?
- MaveRick12 February 12, 2014