0
procedure stars(n)
     for i = 1, . . . , n do
     print “∗” i many times

Question - Using the Ω-notation, lowerbound the running time of stars to show that your upperbound is in fact asymptotically tight.

Solution - Assume for simplicity that n is even. We lowerbound the number of stars printed during iterations n/2 through n:

SEE PICTURE For CLArity

I didn't understand why they are going from n/2 to n. How do I do this Question?

lynxx
  • 544
  • 3
  • 18
  • This results directly from [the mathematical definition of big-Ω (and big-O) notation](https://en.wikipedia.org/wiki/Big_O_notation#Formal_definition). – Sneftel Mar 04 '19 at 10:14

3 Answers3

2

For Omega it does not matter from where you've started! Just one thing for the lower bound is it must be less than the sepecified sum. Solution just wants to find a tight lower bound for the sum, as the sum is in Theta(n^2) (the sum is equal to n(n+1)/2).

OmG
  • 18,337
  • 10
  • 57
  • 90
  • 1
    `it does not matter from where you've started` as long as you sum a part growing linearly with *n*. – greybeard Mar 04 '19 at 11:26
  • 1
    @greybeard yes this true. the above sum is in `Omega(n)`. You should this part of the solution too `Solution just wants to find a tight lower bound for the sum` – OmG Mar 04 '19 at 11:28
  • Would this be an acceptable solution- As there is no boolean expression which might become false and reduce the total steps/iteration, the lower bound will therefore be equal to the upper bound. In other words, the total steps would be same in lower bound and upper bound as there is no boolean expression might turn false. – lynxx Mar 04 '19 at 11:32
  • AND.. it is easier to find the upper bound which will be O(N^2) – lynxx Mar 04 '19 at 11:34
  • 1
    @lynxx: *I* would accept (use) such reasoning. Whoever tasked you to `lowerbound the running time` is likely to prefer a self-contained deduction. – greybeard Mar 04 '19 at 11:37
2

Notice that the sum is not over j/2, but over n/2. For each n/2 ≤ j ≤ n, n/2 ≤ j, so the inequality holds with the possible exception of n=2: the full sum is three, the second sum is 2 (not 2²/4 = 1: the mistake is in starting at n/2 instead of n/2 + 1.)
Choosing n/2 (+1) as the lower bound for summation just makes the sum conveniently trivial in conjunction to letting each summand equal n/2.

greybeard
  • 2,249
  • 8
  • 30
  • 66
  • Would this be an acceptable solution- As there is no boolean expression which might become false and reduce the total steps/iteration, the lower bound will therefore be equal to the upper bound. In other words, the total steps would be same in lower bound and upper bound as there is no boolean expression might turn false. AND.. it is easier to find the upper bound which will be O(N^2) – lynxx Mar 04 '19 at 11:32
1

Notice that when you are summing from n/2 to n you are summing less elements so this equation is correct.

It is done in order to simplify the expression in the end and to find a specifically lower bound.

Yonlif
  • 1,770
  • 1
  • 13
  • 31