Thanks ozo, but may I know
1) Is the assumption and procedure for proving right inequality correct?
2) Can you elaborate more on let a=1/2 and n>2m, since I can't get a clear picture from it...
Main Topics
Browse All TopicsThis is an algorithm of BruteForceStringMatch found from the book "The design and analysis of algorithm" by anany Levitin at pg105.
The description of the algorithm:
Given a string of characters called the text and a string of m characters(m<=n) called the pattern, find the starting index of substring of the text that
matches the pattern.
Followed is the pseudo code:
for i<-0 to n-m do
j <- 0
while j<m and p[j]=T[i+j]
j<-j+1
if j=m return i
return -1
The book says that for this algorithm, the order of growth in Big Theta is nm, but it doesn't give the steps of proving it.
Hence I tried to write the prove on my own, this is what I try:
Since the worst case is to make all m comparisons before shifting the pattern and this can be happen for each of the n-m+1 tries, hence is has a total of m
(n-m+1) tries
To prove m(n-m+1) belong to the order of growth in Big Theta is nm, we need to show for all n>=n0, m>=m0 that
a(mn)<=m(n-m+1)<=b(mn) where a and b are positive integers and n0, m0 are nonnegative integers.
To prove the right inequality(upper bound)
m(n-m+1)
<=m(n-m+1+(m-1)) when m>=1,n>=0
<=mn
This proved the right inequality.(with b=1, m>=1 ,n>=0)
Is the assumption and procedure for proving right inequality correct? I am not sure of it because the book only mentioned for function of one input
parameter, says t(n), to show that the order of growth in Big Theta is g(n) we need to prove a(g(n))<=t(n)<=b(g(n)) for all n>=n0.
But this question seems like involved two input parameters. Is it correct that for function of two input parameters, says t(n,m), to show that the order of
growth in Big Theta is g(n,m) we need to prove a(g(n,m))<=t(n,m)<=b(g(n,m
If it is correct, may I know how to prove the left inequality, ie. a(mn)<=m(n-m+1)?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hi,
The posted brute force algorithm has two nested loops.
The outer loop clearly counts n-m times.
By considering m as a constant, it is O(n). Suppose such algorithm running with tho different numbers n1 and n2 and constant m, causing the loop to be bounded respectively by n1-m and n2-m.
As per the notation, for constant m, the complexity is clearly Theta(n), because the loop counts exactly (n-constant) times.
The inner loop depends on two variables: the integer m and the boolean result of a comparaison. The second condition for the loop (the boolean variable) isn't a function of n (neither of m), thus defining the complexity only by m, in this case not treated as a constant.
Then the inner loop has complexity Theta(m).
This results on Theta(n) x Theta(m) = Theta(mn).
Jose
Thanks for the participation, but I am afraid that we can't prove the left equality.
if we assume a(mn)<=m(n-m+1) is true,
when n=m,
a(mn)=a(n^2)
m(n-m+1)=m(m-m+1)=m
Hence we get m>=a(n^2), but since n>=m, a(n^2)>=m, hence this is a contradiction.
Hence the left equality does not hold.
From this we know that m(n-m+1) is not belong to BigTheta(mn), because it does not belong to BigOmega(mn).
But it is true that it belongs to BigOh(mn), because the right equality still hold.
Since no comment has really answered this question exactly, I would like to grade this question as self answered. Any comment please post within 1 day, after that I will request to close this question. Thanks again.
Business Accounts
Answer for Membership
by: ozoPosted on 2007-06-03 at 09:02:55ID: 19204142
let a=1/2 and n>2m