Professional Documents
Culture Documents
Intro 2
Intro 2
Introduction - II
Classification of Problems
Polynomial (P) Problems
Are solvable in polynomial time
Non-Deterministic Polynomial (NP) Problems
This class of problems has solutions that are verifiable in polynomial
time.
NP-Hard
At least as hard as the hardest problems in NP
Polynomial time reducible to problems
NP-Complete
Is in NP Hard and in NP
• The class of questions for which an answer can be verified in polynomial time
is called NP
Insertion Sort
• Input
– A sequence of number (a1,…,an)
• Output
– A permutation (reordering) (b1,…,bn) of input sequence such that b1 ≤ b2 ≤
… ≤bn
Insertion Sort…
Insertion Sort…
Insertion Sort…
?
• Loop Invariant
– Initialization
– Maintenance
– Termination
Merge
Merge…
Merge…
Merge…
Merge…
Merge Sort
Merge Sort…
Analysis
Analysis…