SlideShare a Scribd company logo
1 of 35
Teori
P, NP, NP-Hard dan NP-Complete
Tenia Wahyuningrum
16/405316/SPA/00573
Universitas Gadjah Mada Yogyakarta
Fakultas Matematika dan Ilmu Pengetahuan Alam
Program Studi Ilmu Komputer
Introducing…
Good!
It’s Polynomialsolution!
The time requirement of the algorithm varies
What is P?
 Polynomial Time
 The worst-case time complexity is limited
by the polynomial function of its input size.
 The class of problems where the solution
can discovered “quickly”
 In time polynomial in the size of the input
What is P? (cont.)
Example
Sorting  T(n) = O(n2), T(n) = O(n log n)
Searching  T(n) = O(n), T(n) = lO(log n)
Matrix multiplication  T(n) = O(n3), T(n) = O(n2.83)
Pproblems
 P Problems are the set of all decision
issues that can be solved by algorithms
with polynomial time requirements.
 More specifically, they are problems that
can be solved in time O(nk) for some
constant k, where n is the size of the input
to the problem.
 The key is that n is the size of input.
What is the complexity of primality
testing?
public static boolean isPrime(int n){
boolean answer = (n>1)? true: false;
for(int i = 2; i*i <= n; ++i)
{
System.out.printf("%dn", i);
if(n%i == 0)
{
answer = false;
break;
}
}
return answer;
}
This loops until the square root of n
So this should be
But what is the input size?
How many bits does it take to
represent the number n?
log(n) = k
What is
Naïve primality testing is
exponential!!
Intractable and tractable
 An issue is said to be intractable if it is
not possible to be solved by a polynomial-
time algorithm.
 Conversely, the problem is said to be
tractable if a polynomial algorithm can
solve it.
Is this tractable?
Multiplication of the chain matrix
A1 A2  …  An
By means of a brute force attack and divide conquer
T(n), Non Polynom
But, by using dynamic programming
 T(n)= O(n3), Polynom
*Multiplication of the chain matrix is ​​tractable
Is there an intractable
issue?
It’s a halting problem
by Alan Turing, 1963
Example
 Take x integers less than ten multiply hold
x by itself until the result is more than 100
 If x= 9, then the program will stop in step 2
 If x=4, then the program will stop in step 3
 But, if x=1, then the program will never stop
* Halting problem
How about
Travelling Salesman Problem?
Time
complexity = O(n!).
There is no polynomial time solution to solve it!
What is NP?
 Nondeterministic Polynomial time
 The class of problems where the solution
can verified “quickly”
 In time polynomial in the size of the input
What is NP? (cont.)
Example
 TSP,
 integer knapsack problem,
 graph coloring,
 Hamilton Circuit,
 partition problem,
 integer linear programming
NPtheory
 In discussing the theory of NP, we only
limit the decision problem.
 Decision issue is a problem whose
solution is only "yes" or "no" answer.
Example:
 Given an integer x. Determine whether the element x is
in the table?
 Given an integer x. Determine whether x is prime
number?
NPproblems
a
b
cd
e
NPproblems
TSOP = minimum weight
TSDP = total weight<x
a
b
cd
e
a+ b+c+d+e = minimum weight
a+ b+c+d+e < x
 Traveling Salesman Optimization
Problem (TSOP) is a matter of
determining a tour with a minimum total of
minimum weights. (*TSP is commonly known).
 Traveling Salesman Decision Problem
(TSDP) is a matter of determining whether
there is a tour with the total weight of the
sides not exceeding the value x.
 Example: if the problem Traveling
Salesman Optimization Problem (TSOP)
minimum tour is 20,
 Then the answer to the problem of
Traveling Salesman Decision Problem
(TSDP) is "yes" if x >= 20, and "no" if x
<20.
*jokes
NP hard problem
 Class of decision problems which are at
least as hard as the hardest problems in
NP.
 Problems that are NP-hard do not have
to be elements of NP; indeed, they may
not even be decidable.
22
Is P = NP?
 Any problem in P is also in NP:
 P  NP
 The big (and open question) is whether NP  P
or P = NP
 i.e., if it is always easy to check a solution, should it
also be easy to find a solution?
 Most computer scientists believe that this is false
but we do not have a proof …
P
NP
23
NP-Completeness (informally)
 NP-complete problems are
 defined as the hardest problems in NP
 Most practical problems turn out to be either
P or NP-complete.
 Study NP-complete problems …
P
NP
NP-complete
24
Reductions
• Reduction is a way of saying that one problem is “easier”
than another.
• We say that problem A is easier than problem B,
(i.e., we write “A  B”)
if we can solve A using the algorithm that solves B.
• Idea: transform the inputs of A to inputs of B
f Problem B
  yes
no
yes
no
Problem A
25
Polynomial Reductions
 Given two problems A, B, we say that A is
polynomially reducible to B (A p B) if:
 There exists a function f that converts the input
of A to inputs of B in polynomial time
 A(i) = YES  B(f(i)) = YES
26
NP-Completeness (formally)
 A problem B is NP-complete if:
 (1) B  NP
 (2) A p B for all A  NP
 If B satisfies only property (2) we say that B is NP-hard
 No polynomial time algorithm has been discovered for an NP-
Complete problem
 No one has ever proven that no polynomial time algorithm can
exist for any NP-Complete problem
P
NP
NP-complete
27
Implications of Reduction
- If A p B and B  P, then A  P
- if A p B and A  P, then B  P
f Problem B
  yes
no
yes
no
Problem A
28
Proving Polynomial Time
1. Use a polynomial time reduction algorithm to
transform A into B
2. Run a known polynomial time algorithm for B
3. Use the answer for B as the answer for A
Polynomial time algorithm to decide A
f Polynomial time
algorithm to decide B
  yes
no
yes
no
30
Proving NP-Completeness In Practice
• Prove that the problem B is in NP
– A randomly generated string can be checked in
polynomial time to determine if it represents a
solution
• Show that one known NP-Complete problem can
be transformed to B in polynomial time
– No need to check that all NP-Complete problems
are reducible to B
31
Revisit “Is P = NP?”
Theorem: If any NP-Complete problem can be
solved in polynomial time  then P = NP.
P
NP
NP-complete
32
P & NP-Complete Problems
 Shortest simple path
 Given a graph G = (V, E) find a shortest path from a
source to all other vertices
 Polynomial solution: O(VE)
 Longest simple path
 Given a graph G = (V, E) find a longest path from a
source to all other vertices
 NP-complete
33
P & NP-Complete Problems
• Euler tour
– G = (V, E) a connected, directed graph find a cycle
that traverses each edge of G exactly once (may visit
a vertex multiple times)
– Polynomial solution O(E)
• Hamiltonian cycle
– G = (V, E) a connected, directed graph find a cycle
that visits each vertex of G exactly once
– NP-complete
34
NP-naming convention
 NP-complete - means problems that are
'complete' in NP, i.e. the most difficult to
solve in NP
 NP-hard - stands for 'at least' as hard as
NP (but not necessarily in NP);
 NP-easy - stands for 'at most' as hard as
NP (but not necessarily in NP);
 NP-equivalent - means equally difficult as
NP, (but not necessarily in NP);
35
Examples NP-complete and
NP-hard problems
NP-complete
NP-hard
Thank you

More Related Content

What's hot

Algorithm chapter 10
Algorithm chapter 10Algorithm chapter 10
Algorithm chapter 10chidabdu
 
Np completeness
Np completenessNp completeness
Np completenessRajendran
 
lecture 27
lecture 27lecture 27
lecture 27sajinsc
 
Np Completeness
Np CompletenessNp Completeness
Np CompletenessRajan Shah
 
Introduction to NP Completeness
Introduction to NP CompletenessIntroduction to NP Completeness
Introduction to NP CompletenessGene Moo Lee
 
A comprehensive view on P vs NP
A comprehensive view on P vs NPA comprehensive view on P vs NP
A comprehensive view on P vs NPAbhay Pai
 
lecture 29
lecture 29lecture 29
lecture 29sajinsc
 
P, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardP, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardAnimesh Chaturvedi
 
NP Complete Problems
NP Complete ProblemsNP Complete Problems
NP Complete ProblemsNikhil Joshi
 
Algorithm Design and Complexity - Course 6
Algorithm Design and Complexity - Course 6Algorithm Design and Complexity - Course 6
Algorithm Design and Complexity - Course 6Traian Rebedea
 
Algorithm_NP-Completeness Proof
Algorithm_NP-Completeness ProofAlgorithm_NP-Completeness Proof
Algorithm_NP-Completeness ProofIm Rafid
 
Computability - Tractable, Intractable and Non-computable Function
Computability - Tractable, Intractable and Non-computable FunctionComputability - Tractable, Intractable and Non-computable Function
Computability - Tractable, Intractable and Non-computable FunctionReggie Niccolo Santos
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic NotationsNagendraK18
 

What's hot (20)

Algorithm chapter 10
Algorithm chapter 10Algorithm chapter 10
Algorithm chapter 10
 
P vs NP
P vs NP P vs NP
P vs NP
 
Np completeness
Np completenessNp completeness
Np completeness
 
lecture 27
lecture 27lecture 27
lecture 27
 
Np completeness
Np completenessNp completeness
Np completeness
 
Np Completeness
Np CompletenessNp Completeness
Np Completeness
 
Introduction to NP Completeness
Introduction to NP CompletenessIntroduction to NP Completeness
Introduction to NP Completeness
 
np complete
np completenp complete
np complete
 
A comprehensive view on P vs NP
A comprehensive view on P vs NPA comprehensive view on P vs NP
A comprehensive view on P vs NP
 
lecture 29
lecture 29lecture 29
lecture 29
 
Daa notes 3
Daa notes 3Daa notes 3
Daa notes 3
 
NP Complete Problems in Graph Theory
NP Complete Problems in Graph TheoryNP Complete Problems in Graph Theory
NP Complete Problems in Graph Theory
 
P, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardP, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-Hard
 
Np hard
Np hardNp hard
Np hard
 
NP Complete Problems
NP Complete ProblemsNP Complete Problems
NP Complete Problems
 
Algorithm Design and Complexity - Course 6
Algorithm Design and Complexity - Course 6Algorithm Design and Complexity - Course 6
Algorithm Design and Complexity - Course 6
 
NP completeness
NP completenessNP completeness
NP completeness
 
Algorithm_NP-Completeness Proof
Algorithm_NP-Completeness ProofAlgorithm_NP-Completeness Proof
Algorithm_NP-Completeness Proof
 
Computability - Tractable, Intractable and Non-computable Function
Computability - Tractable, Intractable and Non-computable FunctionComputability - Tractable, Intractable and Non-computable Function
Computability - Tractable, Intractable and Non-computable Function
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 

Similar to Teori pnp

NP-Completeness-myppt.pptx
NP-Completeness-myppt.pptxNP-Completeness-myppt.pptx
NP-Completeness-myppt.pptxSanchayKedia2
 
Basic_concepts_NP_Hard_NP_Complete.pdf
Basic_concepts_NP_Hard_NP_Complete.pdfBasic_concepts_NP_Hard_NP_Complete.pdf
Basic_concepts_NP_Hard_NP_Complete.pdfArivukkarasu Dhanapal
 
UNIT-V.pdf daa unit material 5 th unit ppt
UNIT-V.pdf daa unit material 5 th unit pptUNIT-V.pdf daa unit material 5 th unit ppt
UNIT-V.pdf daa unit material 5 th unit pptJyoReddy9
 
Analysis and design of algorithms part 4
Analysis and design of algorithms part 4Analysis and design of algorithms part 4
Analysis and design of algorithms part 4Deepak John
 
Skiena algorithm 2007 lecture19 introduction to np complete
Skiena algorithm 2007 lecture19 introduction to np completeSkiena algorithm 2007 lecture19 introduction to np complete
Skiena algorithm 2007 lecture19 introduction to np completezukun
 
Bt0080 fundamentals of algorithms2
Bt0080 fundamentals of algorithms2Bt0080 fundamentals of algorithms2
Bt0080 fundamentals of algorithms2Techglyphs
 
P, NP and NP-Complete, Theory of NP-Completeness V2
P, NP and NP-Complete, Theory of NP-Completeness V2P, NP and NP-Complete, Theory of NP-Completeness V2
P, NP and NP-Complete, Theory of NP-Completeness V2S.Shayan Daneshvar
 
A Stochastic Limit Approach To The SAT Problem
A Stochastic Limit Approach To The SAT ProblemA Stochastic Limit Approach To The SAT Problem
A Stochastic Limit Approach To The SAT ProblemValerie Felton
 
Design and Analysis of Algorithms Exam Help
Design and Analysis of Algorithms Exam HelpDesign and Analysis of Algorithms Exam Help
Design and Analysis of Algorithms Exam HelpProgramming Exam Help
 

Similar to Teori pnp (20)

DAA.pdf
DAA.pdfDAA.pdf
DAA.pdf
 
DAA.pdf
DAA.pdfDAA.pdf
DAA.pdf
 
NP-Completeness-myppt.pptx
NP-Completeness-myppt.pptxNP-Completeness-myppt.pptx
NP-Completeness-myppt.pptx
 
Internship
InternshipInternship
Internship
 
AA ppt9107
AA ppt9107AA ppt9107
AA ppt9107
 
Basic_concepts_NP_Hard_NP_Complete.pdf
Basic_concepts_NP_Hard_NP_Complete.pdfBasic_concepts_NP_Hard_NP_Complete.pdf
Basic_concepts_NP_Hard_NP_Complete.pdf
 
UNIT-V.pdf daa unit material 5 th unit ppt
UNIT-V.pdf daa unit material 5 th unit pptUNIT-V.pdf daa unit material 5 th unit ppt
UNIT-V.pdf daa unit material 5 th unit ppt
 
class23.ppt
class23.pptclass23.ppt
class23.ppt
 
lect5-1.ppt
lect5-1.pptlect5-1.ppt
lect5-1.ppt
 
Introduction
IntroductionIntroduction
Introduction
 
UNIT -IV DAA.pdf
UNIT  -IV DAA.pdfUNIT  -IV DAA.pdf
UNIT -IV DAA.pdf
 
UNIT-V.ppt
UNIT-V.pptUNIT-V.ppt
UNIT-V.ppt
 
Analysis and design of algorithms part 4
Analysis and design of algorithms part 4Analysis and design of algorithms part 4
Analysis and design of algorithms part 4
 
Skiena algorithm 2007 lecture19 introduction to np complete
Skiena algorithm 2007 lecture19 introduction to np completeSkiena algorithm 2007 lecture19 introduction to np complete
Skiena algorithm 2007 lecture19 introduction to np complete
 
CSE680-17NP-Complete.pptx
CSE680-17NP-Complete.pptxCSE680-17NP-Complete.pptx
CSE680-17NP-Complete.pptx
 
Bt0080 fundamentals of algorithms2
Bt0080 fundamentals of algorithms2Bt0080 fundamentals of algorithms2
Bt0080 fundamentals of algorithms2
 
P, NP and NP-Complete, Theory of NP-Completeness V2
P, NP and NP-Complete, Theory of NP-Completeness V2P, NP and NP-Complete, Theory of NP-Completeness V2
P, NP and NP-Complete, Theory of NP-Completeness V2
 
Np completeness
Np completeness Np completeness
Np completeness
 
A Stochastic Limit Approach To The SAT Problem
A Stochastic Limit Approach To The SAT ProblemA Stochastic Limit Approach To The SAT Problem
A Stochastic Limit Approach To The SAT Problem
 
Design and Analysis of Algorithms Exam Help
Design and Analysis of Algorithms Exam HelpDesign and Analysis of Algorithms Exam Help
Design and Analysis of Algorithms Exam Help
 

More from Tenia Wahyuningrum (20)

Measuring User Experience
Measuring User ExperienceMeasuring User Experience
Measuring User Experience
 
Populasi dan sampel dalam penelitian HCI
Populasi dan sampel dalam penelitian HCIPopulasi dan sampel dalam penelitian HCI
Populasi dan sampel dalam penelitian HCI
 
10th heuristic evaluation
10th heuristic evaluation10th heuristic evaluation
10th heuristic evaluation
 
Good vs bad design
Good vs bad designGood vs bad design
Good vs bad design
 
Media sosial untuk pembelajaran
Media sosial untuk pembelajaranMedia sosial untuk pembelajaran
Media sosial untuk pembelajaran
 
4th human factors (2)
4th human factors (2)4th human factors (2)
4th human factors (2)
 
Human factors
Human factorsHuman factors
Human factors
 
Historical Context of HCI
Historical Context of HCIHistorical Context of HCI
Historical Context of HCI
 
Trends in Human Computer Interaction
Trends in Human Computer InteractionTrends in Human Computer Interaction
Trends in Human Computer Interaction
 
Good data, for better life
Good data, for better lifeGood data, for better life
Good data, for better life
 
Plagiarisme
PlagiarismePlagiarisme
Plagiarisme
 
Struktur data &amp; computer trends 2015 2016
Struktur data &amp; computer trends 2015 2016Struktur data &amp; computer trends 2015 2016
Struktur data &amp; computer trends 2015 2016
 
Pengujian hipotesis
Pengujian hipotesisPengujian hipotesis
Pengujian hipotesis
 
Research method
Research methodResearch method
Research method
 
Basic research
Basic researchBasic research
Basic research
 
Pengenalan android
Pengenalan androidPengenalan android
Pengenalan android
 
Mobile programming pendahuluan
Mobile programming pendahuluanMobile programming pendahuluan
Mobile programming pendahuluan
 
Pertemuan 1
Pertemuan 1Pertemuan 1
Pertemuan 1
 
Public speaking
Public speakingPublic speaking
Public speaking
 
Perangkat lunak basis data
Perangkat lunak basis dataPerangkat lunak basis data
Perangkat lunak basis data
 

Recently uploaded

Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...
High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...
High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...Call girls in Ahmedabad High profile
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 

Recently uploaded (20)

Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...
High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...
High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 

Teori pnp

  • 1. Teori P, NP, NP-Hard dan NP-Complete Tenia Wahyuningrum 16/405316/SPA/00573 Universitas Gadjah Mada Yogyakarta Fakultas Matematika dan Ilmu Pengetahuan Alam Program Studi Ilmu Komputer
  • 2. Introducing… Good! It’s Polynomialsolution! The time requirement of the algorithm varies
  • 3. What is P?  Polynomial Time  The worst-case time complexity is limited by the polynomial function of its input size.  The class of problems where the solution can discovered “quickly”  In time polynomial in the size of the input
  • 4. What is P? (cont.) Example Sorting  T(n) = O(n2), T(n) = O(n log n) Searching  T(n) = O(n), T(n) = lO(log n) Matrix multiplication  T(n) = O(n3), T(n) = O(n2.83)
  • 5. Pproblems  P Problems are the set of all decision issues that can be solved by algorithms with polynomial time requirements.  More specifically, they are problems that can be solved in time O(nk) for some constant k, where n is the size of the input to the problem.  The key is that n is the size of input.
  • 6. What is the complexity of primality testing? public static boolean isPrime(int n){ boolean answer = (n>1)? true: false; for(int i = 2; i*i <= n; ++i) { System.out.printf("%dn", i); if(n%i == 0) { answer = false; break; } } return answer; } This loops until the square root of n So this should be But what is the input size? How many bits does it take to represent the number n? log(n) = k What is Naïve primality testing is exponential!!
  • 7. Intractable and tractable  An issue is said to be intractable if it is not possible to be solved by a polynomial- time algorithm.  Conversely, the problem is said to be tractable if a polynomial algorithm can solve it.
  • 8. Is this tractable? Multiplication of the chain matrix A1 A2  …  An By means of a brute force attack and divide conquer T(n), Non Polynom But, by using dynamic programming  T(n)= O(n3), Polynom *Multiplication of the chain matrix is ​​tractable
  • 9. Is there an intractable issue? It’s a halting problem by Alan Turing, 1963
  • 10. Example  Take x integers less than ten multiply hold x by itself until the result is more than 100  If x= 9, then the program will stop in step 2  If x=4, then the program will stop in step 3  But, if x=1, then the program will never stop * Halting problem
  • 11. How about Travelling Salesman Problem? Time complexity = O(n!). There is no polynomial time solution to solve it!
  • 12. What is NP?  Nondeterministic Polynomial time  The class of problems where the solution can verified “quickly”  In time polynomial in the size of the input
  • 13. What is NP? (cont.) Example  TSP,  integer knapsack problem,  graph coloring,  Hamilton Circuit,  partition problem,  integer linear programming
  • 14. NPtheory  In discussing the theory of NP, we only limit the decision problem.  Decision issue is a problem whose solution is only "yes" or "no" answer.
  • 15. Example:  Given an integer x. Determine whether the element x is in the table?  Given an integer x. Determine whether x is prime number?
  • 17. NPproblems TSOP = minimum weight TSDP = total weight<x a b cd e a+ b+c+d+e = minimum weight a+ b+c+d+e < x
  • 18.  Traveling Salesman Optimization Problem (TSOP) is a matter of determining a tour with a minimum total of minimum weights. (*TSP is commonly known).  Traveling Salesman Decision Problem (TSDP) is a matter of determining whether there is a tour with the total weight of the sides not exceeding the value x.
  • 19.  Example: if the problem Traveling Salesman Optimization Problem (TSOP) minimum tour is 20,  Then the answer to the problem of Traveling Salesman Decision Problem (TSDP) is "yes" if x >= 20, and "no" if x <20.
  • 21. NP hard problem  Class of decision problems which are at least as hard as the hardest problems in NP.  Problems that are NP-hard do not have to be elements of NP; indeed, they may not even be decidable.
  • 22. 22 Is P = NP?  Any problem in P is also in NP:  P  NP  The big (and open question) is whether NP  P or P = NP  i.e., if it is always easy to check a solution, should it also be easy to find a solution?  Most computer scientists believe that this is false but we do not have a proof … P NP
  • 23. 23 NP-Completeness (informally)  NP-complete problems are  defined as the hardest problems in NP  Most practical problems turn out to be either P or NP-complete.  Study NP-complete problems … P NP NP-complete
  • 24. 24 Reductions • Reduction is a way of saying that one problem is “easier” than another. • We say that problem A is easier than problem B, (i.e., we write “A  B”) if we can solve A using the algorithm that solves B. • Idea: transform the inputs of A to inputs of B f Problem B   yes no yes no Problem A
  • 25. 25 Polynomial Reductions  Given two problems A, B, we say that A is polynomially reducible to B (A p B) if:  There exists a function f that converts the input of A to inputs of B in polynomial time  A(i) = YES  B(f(i)) = YES
  • 26. 26 NP-Completeness (formally)  A problem B is NP-complete if:  (1) B  NP  (2) A p B for all A  NP  If B satisfies only property (2) we say that B is NP-hard  No polynomial time algorithm has been discovered for an NP- Complete problem  No one has ever proven that no polynomial time algorithm can exist for any NP-Complete problem P NP NP-complete
  • 27. 27 Implications of Reduction - If A p B and B  P, then A  P - if A p B and A  P, then B  P f Problem B   yes no yes no Problem A
  • 28. 28 Proving Polynomial Time 1. Use a polynomial time reduction algorithm to transform A into B 2. Run a known polynomial time algorithm for B 3. Use the answer for B as the answer for A Polynomial time algorithm to decide A f Polynomial time algorithm to decide B   yes no yes no
  • 29. 30 Proving NP-Completeness In Practice • Prove that the problem B is in NP – A randomly generated string can be checked in polynomial time to determine if it represents a solution • Show that one known NP-Complete problem can be transformed to B in polynomial time – No need to check that all NP-Complete problems are reducible to B
  • 30. 31 Revisit “Is P = NP?” Theorem: If any NP-Complete problem can be solved in polynomial time  then P = NP. P NP NP-complete
  • 31. 32 P & NP-Complete Problems  Shortest simple path  Given a graph G = (V, E) find a shortest path from a source to all other vertices  Polynomial solution: O(VE)  Longest simple path  Given a graph G = (V, E) find a longest path from a source to all other vertices  NP-complete
  • 32. 33 P & NP-Complete Problems • Euler tour – G = (V, E) a connected, directed graph find a cycle that traverses each edge of G exactly once (may visit a vertex multiple times) – Polynomial solution O(E) • Hamiltonian cycle – G = (V, E) a connected, directed graph find a cycle that visits each vertex of G exactly once – NP-complete
  • 33. 34 NP-naming convention  NP-complete - means problems that are 'complete' in NP, i.e. the most difficult to solve in NP  NP-hard - stands for 'at least' as hard as NP (but not necessarily in NP);  NP-easy - stands for 'at most' as hard as NP (but not necessarily in NP);  NP-equivalent - means equally difficult as NP, (but not necessarily in NP);
  • 34. 35 Examples NP-complete and NP-hard problems NP-complete NP-hard