Google Answers Logo
View Question
 
Q: Data structure and algorithm ( Answered,   0 Comments )
Question  
Subject: Data structure and algorithm
Category: Computers > Algorithms
Asked by: math01-ga
List Price: $3.00
Posted: 16 Jul 2003 08:03 PDT
Expires: 15 Aug 2003 08:03 PDT
Question ID: 231624
Select the tightest big-O notation for the following expressions: 

a. 1 + 2 + 4 + 8 + 16 + ..... + n 

b. n * (1 + 2 + 3 + ..... + n) 

c. log(n2) + (logn)2 

d. 12 + 22 + 32 + ..... + n2
Answer  
Subject: Re: Data structure and algorithm
Answered By: elmarto-ga on 16 Jul 2003 22:59 PDT
 
Hello math01!
Here are the answers to your questions.

a) 1+2+4+8... n times can be written, using the Sigma notation, as

  n
 ___
 \
 /    2^i
 ---
 i=0

where ^ means "to the power of". Therefore, this sum would be 2^0 +
2^1 + 2^2 + 2^3 + ... = 1 + 2 + 4 + 8 + ...

as you can see in the following document (you'll need Acrobat Reader
in order to read it), this sum amounts to 2^(n+1) - 1, which is equal
to 2*(2^n)-1.

Analysis of Algorithms (see page 4)
http://www.cs.aucegypt.edu/~mudawwar/csci210/slides/Analysis.pdf

Therefore, the expression is O(2^n). Notice that the "dominant" term
in each expression is used for the big O notation. Check the following
pdf document to see which terms dominates others.

Algorith Analysis
http://courses.cs.vt.edu/~cs1704/fall02/Notes/C12.AlgorithmAnalysis.pdf


b. As you can see in the first pdf document cited above, the sum

1+2+3+...+n

amounts to n*(n+1)/2, which gives [n^2+n]/2. But you're then
multiplying this expression by n, thus arriving to [n^3+n^2]/2. As
before, the term used for the tightest big-O notation is the dominant
one; in this case, n^3. Therefore, the tightest big O notation for
this expression is O(n^3)


c.  I assume here that the expression here would be log(n^2) +
2*log(n). Please do tell me through a clarification request if I'm
wrong with this assumption. We can use here that log(n^k)=k*log(n) (k
being a constant). Therefore, log(n^2)=2*log(n), so the expression
becomes 2*log(n)+2*log(n)=4*log(n). Clearly, the big-O notation in
this case is O(log(n)).


d. I'll make a similar assumption here. I think the expression you
meant to ask about is:

1^2 + 2^2 + 3^2 + ... + n^2

Again, this sum is considered in the mentioned pdf document (it's the
second expression in page 4). This sum becomes n(n+1)(2n+1)/6 or,
equivalently,

2n^3 + 3n^2 + n,

in which the "dominant" term is n^3. The tighest big-O notation is
thus in this case O(n^3).


For more information on this subject, also see

Analysis of Algorithms: Motivation...
http://www.cs.bris.ac.uk/Teaching/Resources/COMS11101/9_Complexity.p.pdf


Google search strategy
tighest big-O notation
://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=tightest+big-O+notation

I hope this helps. If you have any doubt regarding my answer, please
request a clarification before rating it. Otherwise, I await your
rating and final comments.

Best wishes!
elmarto
Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy