Question

Suppose a problem can be solved by an algorithm in O(n2) as well as another algorithm...

  1. Suppose a problem can be solved by an algorithm in O(n2) as well as another algorithm in O(2n). Will one algorithm always outperform the other?
  1. Give an example of a polynomial problem. Give an example of a nonpolynomial problem. Give an example of an NP problem that as yet has not been shown to be a polynomial problem.
  1. If the time complexity of algorithm X is greater than that of algorithm Y, is algorithm X necessarily harder to understand than algorithm Y? Explain your answer.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

These O(n2) and O(2n) are asymptotic time complexitites i.e for larger values of inputs how an algorithm performs.n being the no. of inputs here O(2n) will always perform better and an the efficiency of algorithm depends upon how it is performing on larger inputs rather than smaller inputs.So ,yes O(2n) is much better than O(n2).

An algorithm is polynomial if for some k>0, its running time on inputs of size n is O(nk) i.e maybe linear,quadratic and more.

Example-All Pair Shortest Path Problem(Floyd Warshall Algorithm) is a Polynomial time problem .

An algorithm is non polynomial if it takes some exponential time to run for inputs i.e maybe 2n.

Example-Travelling Salesman Problem

Sudoku is a game which is an example of NP problem which is not yet shown to be a polynomial problem

The time complexity of an algorithm is the total amount of time required by an algorithm to complete its execution.Every code takes time to execute.Time taken by the the lines of code written to execute is known as time complexity of the code.Lesser the time complexity of code,more efficiently the code runs i.e takes less time to run.So it's not like if the time complexity is less then the algorithm is easier to understand.It just effects execution time.There is no co-relation between time complexity of a problem and its understandibility.

Add a comment
Know the answer?
Add Answer to:
Suppose a problem can be solved by an algorithm in O(n2) as well as another algorithm...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT