225_35_NP-complete

# 225_35_NP-complete -...

This preview shows pages 1–8. Sign up to view the full content.

1 How many key comparisons does this algorithm do for  finding the min and the max of n=2k data items: 1. for (i=0; i < n; i+=2)      if (A[i] > A[i+1]) swap(A[i], A[i+1]) Then use a linear scan (like in MaxSort) to 2. Find the min of  A[0], A[2], A[4], … , A[n-2] 3. Find the max of A[1], A[3], A[5], … A[n-1]

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 Old final Exam Question Answer true or false and justify your answer: Since it takes at least n-1 key comparisons to find the min  of n data items and it takes at least n-1 key comparisons  to find the max of n data items, it takes at least 2n-2 key  comparisons to find both the min and the max.
3 Final exam tutorial: Wednesday Dec. 7 at 12:00pm,  Elliott 061. 8 old final exams are available from our class web page.   Solutions to written exercises are posted (#5 available  soon) on connex. Ask me at the tutorial if you have questions about the  programming exercises.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
4
5 Introduction to NP-completeness All the algorithms we have studied so far run in polynomial time  [O(n c ) for some constant c]. There are lots of other interesting and important problems for  which we do not have polynomial time solutions.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
6 Table 1: Comparing polynomial and exponential time complexity. Assume a problem of size one takes 0.000001 seconds (1 microsecond). Size n 10 20 30 40 50 60 n 0.00001 second 0.00002 second 0.00003 second 0.00004 second 0.00005 second 0.00006 second n 2 0.0001 second 0.0004 second 0.0009 second 0.0016 second 0.0025 second 0.0036 second n 3 0.001 second 0.008 second 0.027 second 0.064 second 0.125 second 0.216 second n 5 0.1 second 3.2 second 24.3 second 1.7 minutes 5.2 minutes 13.2 minutes 2 n 0.001 second 1.0 second 17.9 minutes 12.7 days 35.7 years 366 centuries 3 n 0.059 second 58 minutes 6.5 years 3855 centuries 2*10 8 centuries 1.3*10 13 centuries (from M. R. Garey and D. S. Johnson, Computers and Intractability: A Guide to the Theory of NP-completeness , W. H. Freeman, New York, 1979.)
7 Time Complexity function With present computer With computer 100 times faster With computer 1000 times faster n N1 100 N1 1000 N1 n 2 N2 10 N2

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 01/15/2012 for the course CSC 225 taught by Professor Valerieking during the Spring '10 term at University of Victoria.

### Page1 / 32

225_35_NP-complete -...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online