SlideShare a Scribd company logo
1 of 10
CHAPTER 10 P and NP
Algorithm 10.2.2 Crossword Puzzle This algorithm solves a crossword puzzle, represented by a Boolean matrix  D [ i , j ], 1 =  i,j  =  n  , and a finite set of words  W   ⊆  Σ * .  Σ  is the alphabet, and  D [ i , j ] is true if the square is blank and false if it is blocked. We construct the solution in a new matrix  S [ i , j ], 1 =  i,j  =  n . The algorithm returns true if the crossword can be solved. Input Parameters:  D ,  W Output Parameters: None puzzle ( D , W ) { for  i  = 1 to  n for  j  = 1 to  n if ( D [ i , j ]) S [ i , j ] =  guess ( Σ ) else S [ i , j ] = blocked for each word  w  in  S if ( w      W ) return false return true }
Algorithm 10.2.15 Graph  k -coloring This algorithm finds a  k -coloring of  G  = ( V , E ), if there is one, and stores it in the array  c  . The algorithm returns true if a coloring is found. Input Parameters:  G  = ( V , E ),  k Output Parameters: None graph_coloring ( G , k ) { for each  v  in  V c [ v ] =  guess ({1,2,..., k }) for each  v  in  V for each  w  in  N ( v ) if ( c [ w ] ==  c [ v ]) return false return true }
Algorithm 10.2.19 Hamiltonian Cycle This algorithm finds a Hamiltonian cycle in  G  = ( V , E ) if there is one and returns true in that case.
Input Parameter:  G  = ( V , E ) Output Parameters: None hamiltonian_cycle ( G ) { n  = | V | for  i  = 1 to  n visited [ i ] = false for  i  = 1 to  n  { c [ i ] =  guess ( V ) visited [ c [ i ]] = true } c [0] =  c [ n ] // first node is the same as last // check that only edges of  G  are used for  i  = 0 to  n  - 1 if (( c [ i ], c [ i  + 1])     E ) return false // check that all vertices have been visited for  i  = 1 to  n if (!( visited [ i ])) return false return true }
Algorithm 10.2.22 TSP This algorithm finds a Hamiltonian cycle in  G  = ( V ,  E ,  weight ) of total weight at most  w  if there is one and returns true in that case. Input Parameters:  G  = ( V ,  E ,  weight ),  w Output Parameters: None tsp ( G , w ) { n  = | V | for  i  = 1 to  n c [ i ] =  guess ( V ) c [0] =  c [ n ] ...
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Example 10.2.26 graph_coloring ( G , k ) { for each  v  in  V c [ v ] = 0 for each  v  in  V  { c [ v ] =  guess ({1,2,..., k }) for each  w  in  N ( v ) if ( c [ w ] ==  c [ v ]) return false } return true }
Algorithm 10.3.18 Satisfiability Witness This algorithm takes as input a CNF formula  ϕ   on variables x 1 ,...,x n , and either returns a satisfying assignment for  ϕ  in the array  x  or false if there is no such assignment. It assumes that we have an algorithm  A  that decides whether a formula is satisfiable or not.
Input Parameter:   ϕ   Output Parameter:  x satisfiability_witness ( ϕ ,  x ) { if (!(A( ϕ )) return false for  i  = 1 to  n  { ψ  =  ϕ [ x i   -> true] if (A( ϕ )) { x [ i ] = true ϕ   =  ψ } else { x[i] = false ϕ   =  ϕ [ x i   -> false] } } return true }

More Related Content

What's hot

What's hot (16)

All pair shortest path
All pair shortest pathAll pair shortest path
All pair shortest path
 
Unit 03
Unit 03Unit 03
Unit 03
 
Unit 02
Unit 02Unit 02
Unit 02
 
Unit 04
Unit 04Unit 04
Unit 04
 
ikh323-05
ikh323-05ikh323-05
ikh323-05
 
Chap05alg
Chap05algChap05alg
Chap05alg
 
[Question Paper] Applied Mathematics – I (Revised Course) [April / 2014]
[Question Paper] Applied Mathematics – I (Revised Course) [April / 2014][Question Paper] Applied Mathematics – I (Revised Course) [April / 2014]
[Question Paper] Applied Mathematics – I (Revised Course) [April / 2014]
 
Appendix b 2
Appendix b 2Appendix b 2
Appendix b 2
 
Appendix b 2
Appendix b 2Appendix b 2
Appendix b 2
 
DSP System Assignment Help
DSP System Assignment HelpDSP System Assignment Help
DSP System Assignment Help
 
Arrays
ArraysArrays
Arrays
 
Tensor Train data format for uncertainty quantification
Tensor Train data format for uncertainty quantificationTensor Train data format for uncertainty quantification
Tensor Train data format for uncertainty quantification
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplication
 
Green Theorem
Green TheoremGreen Theorem
Green Theorem
 
PC Test 2 study guide 2011
PC Test 2 study guide 2011PC Test 2 study guide 2011
PC Test 2 study guide 2011
 
report
reportreport
report
 

Viewers also liked

Gagasan perda perlindungan anak kota bandung, juli 2011
Gagasan perda perlindungan anak kota bandung, juli 2011Gagasan perda perlindungan anak kota bandung, juli 2011
Gagasan perda perlindungan anak kota bandung, juli 2011Zamzam Muzaki Sm
 
Berenschot persetatie Succesvol Aanbesteden 051010
Berenschot persetatie Succesvol Aanbesteden 051010Berenschot persetatie Succesvol Aanbesteden 051010
Berenschot persetatie Succesvol Aanbesteden 051010Johan Stuiver
 
CUEB Presentation
CUEB PresentationCUEB Presentation
CUEB Presentationbrianlynch
 
Homelessness and Housing – Moving from Policy to Action - Frank Murtagh
Homelessness and Housing – Moving from Policy to Action - Frank MurtaghHomelessness and Housing – Moving from Policy to Action - Frank Murtagh
Homelessness and Housing – Moving from Policy to Action - Frank Murtaghbrianlynch
 
Pirates v. Mercenaries: Purely Private Transnational Violence at the Margins ...
Pirates v. Mercenaries: Purely Private Transnational Violence at the Margins ...Pirates v. Mercenaries: Purely Private Transnational Violence at the Margins ...
Pirates v. Mercenaries: Purely Private Transnational Violence at the Margins ...Ansel Halliburton
 
Pm104 2004 2005
Pm104 2004 2005Pm104 2004 2005
Pm104 2004 2005Munhchimeg
 
Housing First: Ending Homelessness and Supporting Recovery - Dr Sam Tsemberis
Housing First: Ending Homelessness and Supporting Recovery - Dr Sam TsemberisHousing First: Ending Homelessness and Supporting Recovery - Dr Sam Tsemberis
Housing First: Ending Homelessness and Supporting Recovery - Dr Sam Tsemberisbrianlynch
 
Program Edukacyjny W Fabryce Emalii Oskara Schindlera
Program Edukacyjny W Fabryce Emalii Oskara SchindleraProgram Edukacyjny W Fabryce Emalii Oskara Schindlera
Program Edukacyjny W Fabryce Emalii Oskara Schindleraguestbdec7c
 
Hybrid worlds fungi updated - crews
Hybrid worlds   fungi updated - crewsHybrid worlds   fungi updated - crews
Hybrid worlds fungi updated - crewsrv media
 
(Application pdf object) 50 str
(Application pdf object) 50 str(Application pdf object) 50 str
(Application pdf object) 50 strABC
 
データ集 トマ・ピケティ『21 世紀の資本』
データ集 トマ・ピケティ『21 世紀の資本』データ集 トマ・ピケティ『21 世紀の資本』
データ集 トマ・ピケティ『21 世紀の資本』shinya Jingushi
 

Viewers also liked (19)

Lecture8
Lecture8Lecture8
Lecture8
 
Gagasan perda perlindungan anak kota bandung, juli 2011
Gagasan perda perlindungan anak kota bandung, juli 2011Gagasan perda perlindungan anak kota bandung, juli 2011
Gagasan perda perlindungan anak kota bandung, juli 2011
 
Berenschot persetatie Succesvol Aanbesteden 051010
Berenschot persetatie Succesvol Aanbesteden 051010Berenschot persetatie Succesvol Aanbesteden 051010
Berenschot persetatie Succesvol Aanbesteden 051010
 
CUEB Presentation
CUEB PresentationCUEB Presentation
CUEB Presentation
 
Homelessness and Housing – Moving from Policy to Action - Frank Murtagh
Homelessness and Housing – Moving from Policy to Action - Frank MurtaghHomelessness and Housing – Moving from Policy to Action - Frank Murtagh
Homelessness and Housing – Moving from Policy to Action - Frank Murtagh
 
Lecture911
Lecture911Lecture911
Lecture911
 
Pirates v. Mercenaries: Purely Private Transnational Violence at the Margins ...
Pirates v. Mercenaries: Purely Private Transnational Violence at the Margins ...Pirates v. Mercenaries: Purely Private Transnational Violence at the Margins ...
Pirates v. Mercenaries: Purely Private Transnational Violence at the Margins ...
 
Pm104 2004 2005
Pm104 2004 2005Pm104 2004 2005
Pm104 2004 2005
 
Housing First: Ending Homelessness and Supporting Recovery - Dr Sam Tsemberis
Housing First: Ending Homelessness and Supporting Recovery - Dr Sam TsemberisHousing First: Ending Homelessness and Supporting Recovery - Dr Sam Tsemberis
Housing First: Ending Homelessness and Supporting Recovery - Dr Sam Tsemberis
 
Program Edukacyjny W Fabryce Emalii Oskara Schindlera
Program Edukacyjny W Fabryce Emalii Oskara SchindleraProgram Edukacyjny W Fabryce Emalii Oskara Schindlera
Program Edukacyjny W Fabryce Emalii Oskara Schindlera
 
Lecture913
Lecture913Lecture913
Lecture913
 
Lecture916
Lecture916Lecture916
Lecture916
 
Hybrid worlds fungi updated - crews
Hybrid worlds   fungi updated - crewsHybrid worlds   fungi updated - crews
Hybrid worlds fungi updated - crews
 
(Application pdf object) 50 str
(Application pdf object) 50 str(Application pdf object) 50 str
(Application pdf object) 50 str
 
Chap08alg
Chap08algChap08alg
Chap08alg
 
Lecture5
Lecture5Lecture5
Lecture5
 
データ集 トマ・ピケティ『21 世紀の資本』
データ集 トマ・ピケティ『21 世紀の資本』データ集 トマ・ピケティ『21 世紀の資本』
データ集 トマ・ピケティ『21 世紀の資本』
 
Lecture910
Lecture910Lecture910
Lecture910
 
Ded algorithm
Ded algorithmDed algorithm
Ded algorithm
 

Similar to Chap10alg

Complexity Classes and the Graph Isomorphism Problem
Complexity Classes and the Graph Isomorphism ProblemComplexity Classes and the Graph Isomorphism Problem
Complexity Classes and the Graph Isomorphism Problemcseiitgn
 
Important Cuts and (p,q)-clustering
Important Cuts and (p,q)-clusteringImportant Cuts and (p,q)-clustering
Important Cuts and (p,q)-clusteringASPAK2014
 
module4_dynamic programming_2022.pdf
module4_dynamic programming_2022.pdfmodule4_dynamic programming_2022.pdf
module4_dynamic programming_2022.pdfShiwani Gupta
 
Bellman ford
Bellman fordBellman ford
Bellman fordKiran K
 
sublabel accurate convex relaxation of vectorial multilabel energies
sublabel accurate convex relaxation of vectorial multilabel energiessublabel accurate convex relaxation of vectorial multilabel energies
sublabel accurate convex relaxation of vectorial multilabel energiesFujimoto Keisuke
 
Tensor Completion for PDEs with uncertain coefficients and Bayesian Update te...
Tensor Completion for PDEs with uncertain coefficients and Bayesian Update te...Tensor Completion for PDEs with uncertain coefficients and Bayesian Update te...
Tensor Completion for PDEs with uncertain coefficients and Bayesian Update te...Alexander Litvinenko
 
Quantum Machine Learning and QEM for Gaussian mixture models (Alessandro Luongo)
Quantum Machine Learning and QEM for Gaussian mixture models (Alessandro Luongo)Quantum Machine Learning and QEM for Gaussian mixture models (Alessandro Luongo)
Quantum Machine Learning and QEM for Gaussian mixture models (Alessandro Luongo)MeetupDataScienceRoma
 
Problem Solving with Algorithms and Data Structure - Graphs
Problem Solving with Algorithms and Data Structure - GraphsProblem Solving with Algorithms and Data Structure - Graphs
Problem Solving with Algorithms and Data Structure - GraphsYi-Lung Tsai
 
Class1
 Class1 Class1
Class1issbp
 

Similar to Chap10alg (20)

Chap11alg
Chap11algChap11alg
Chap11alg
 
CostFunctions.pdf
CostFunctions.pdfCostFunctions.pdf
CostFunctions.pdf
 
Complexity Classes and the Graph Isomorphism Problem
Complexity Classes and the Graph Isomorphism ProblemComplexity Classes and the Graph Isomorphism Problem
Complexity Classes and the Graph Isomorphism Problem
 
G03201034038
G03201034038G03201034038
G03201034038
 
Important Cuts and (p,q)-clustering
Important Cuts and (p,q)-clusteringImportant Cuts and (p,q)-clustering
Important Cuts and (p,q)-clustering
 
module4_dynamic programming_2022.pdf
module4_dynamic programming_2022.pdfmodule4_dynamic programming_2022.pdf
module4_dynamic programming_2022.pdf
 
Hay hay
Hay hayHay hay
Hay hay
 
Unit 3-Greedy Method
Unit 3-Greedy MethodUnit 3-Greedy Method
Unit 3-Greedy Method
 
Bellman ford
Bellman fordBellman ford
Bellman ford
 
Chap06alg
Chap06algChap06alg
Chap06alg
 
Chap06alg
Chap06algChap06alg
Chap06alg
 
Np cooks theorem
Np cooks theoremNp cooks theorem
Np cooks theorem
 
Chap04alg
Chap04algChap04alg
Chap04alg
 
Chap04alg
Chap04algChap04alg
Chap04alg
 
sublabel accurate convex relaxation of vectorial multilabel energies
sublabel accurate convex relaxation of vectorial multilabel energiessublabel accurate convex relaxation of vectorial multilabel energies
sublabel accurate convex relaxation of vectorial multilabel energies
 
m.tech final
m.tech finalm.tech final
m.tech final
 
Tensor Completion for PDEs with uncertain coefficients and Bayesian Update te...
Tensor Completion for PDEs with uncertain coefficients and Bayesian Update te...Tensor Completion for PDEs with uncertain coefficients and Bayesian Update te...
Tensor Completion for PDEs with uncertain coefficients and Bayesian Update te...
 
Quantum Machine Learning and QEM for Gaussian mixture models (Alessandro Luongo)
Quantum Machine Learning and QEM for Gaussian mixture models (Alessandro Luongo)Quantum Machine Learning and QEM for Gaussian mixture models (Alessandro Luongo)
Quantum Machine Learning and QEM for Gaussian mixture models (Alessandro Luongo)
 
Problem Solving with Algorithms and Data Structure - Graphs
Problem Solving with Algorithms and Data Structure - GraphsProblem Solving with Algorithms and Data Structure - Graphs
Problem Solving with Algorithms and Data Structure - Graphs
 
Class1
 Class1 Class1
Class1
 

More from Munhchimeg (20)

Ded algorithm1
Ded algorithm1Ded algorithm1
Ded algorithm1
 
Tobch lecture1
Tobch lecture1Tobch lecture1
Tobch lecture1
 
Tobch lecture
Tobch lectureTobch lecture
Tobch lecture
 
Recursive
RecursiveRecursive
Recursive
 
Protsesor
ProtsesorProtsesor
Protsesor
 
Lecture916
Lecture916Lecture916
Lecture916
 
Lecture915
Lecture915Lecture915
Lecture915
 
Lecture914
Lecture914Lecture914
Lecture914
 
Lecture913
Lecture913Lecture913
Lecture913
 
Lecture912
Lecture912Lecture912
Lecture912
 
Lecture911
Lecture911Lecture911
Lecture911
 
Lecture9
Lecture9Lecture9
Lecture9
 
Lecture8
Lecture8Lecture8
Lecture8
 
Lecture7
Lecture7Lecture7
Lecture7
 
Lecture6
Lecture6Lecture6
Lecture6
 
Lecture4
Lecture4Lecture4
Lecture4
 
Lecture3
Lecture3Lecture3
Lecture3
 
Protsesor
ProtsesorProtsesor
Protsesor
 
Pm104 standard
Pm104 standardPm104 standard
Pm104 standard
 
Lecture915
Lecture915Lecture915
Lecture915
 

Recently uploaded

Call Girl Nashik Amaira 7001305949 Independent Escort Service Nashik
Call Girl Nashik Amaira 7001305949 Independent Escort Service NashikCall Girl Nashik Amaira 7001305949 Independent Escort Service Nashik
Call Girl Nashik Amaira 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Kolkata Call Girl Airport Kolkata 👉 8250192130 ❣️💯 Available With Room 24×7
Kolkata Call Girl Airport Kolkata 👉 8250192130 ❣️💯 Available With Room 24×7Kolkata Call Girl Airport Kolkata 👉 8250192130 ❣️💯 Available With Room 24×7
Kolkata Call Girl Airport Kolkata 👉 8250192130 ❣️💯 Available With Room 24×7Riya Pathan
 
VIP Call Girls Nagpur Megha Call 7001035870 Meet With Nagpur Escorts
VIP Call Girls Nagpur Megha Call 7001035870 Meet With Nagpur EscortsVIP Call Girls Nagpur Megha Call 7001035870 Meet With Nagpur Escorts
VIP Call Girls Nagpur Megha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Air-Hostess Call Girls Shobhabazar | 8250192130 At Low Cost Cash Payment Booking
Air-Hostess Call Girls Shobhabazar | 8250192130 At Low Cost Cash Payment BookingAir-Hostess Call Girls Shobhabazar | 8250192130 At Low Cost Cash Payment Booking
Air-Hostess Call Girls Shobhabazar | 8250192130 At Low Cost Cash Payment BookingRiya Pathan
 
Independent Hatiara Escorts ✔ 8250192130 ✔ Full Night With Room Online Bookin...
Independent Hatiara Escorts ✔ 8250192130 ✔ Full Night With Room Online Bookin...Independent Hatiara Escorts ✔ 8250192130 ✔ Full Night With Room Online Bookin...
Independent Hatiara Escorts ✔ 8250192130 ✔ Full Night With Room Online Bookin...Riya Pathan
 
Call Girl Nashik Saloni 7001305949 Independent Escort Service Nashik
Call Girl Nashik Saloni 7001305949 Independent Escort Service NashikCall Girl Nashik Saloni 7001305949 Independent Escort Service Nashik
Call Girl Nashik Saloni 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
College Call Girl in Rajiv Chowk Delhi 9634446618 Short 1500 Night 6000 Best ...
College Call Girl in Rajiv Chowk Delhi 9634446618 Short 1500 Night 6000 Best ...College Call Girl in Rajiv Chowk Delhi 9634446618 Short 1500 Night 6000 Best ...
College Call Girl in Rajiv Chowk Delhi 9634446618 Short 1500 Night 6000 Best ...perfect solution
 
Contact:- 8860008073 Call Girls in Karnal Escort Service Available at Afforda...
Contact:- 8860008073 Call Girls in Karnal Escort Service Available at Afforda...Contact:- 8860008073 Call Girls in Karnal Escort Service Available at Afforda...
Contact:- 8860008073 Call Girls in Karnal Escort Service Available at Afforda...Apsara Of India
 
Low Rate Call Girls Ajmer Anika 8250192130 Independent Escort Service Ajmer
Low Rate Call Girls Ajmer Anika 8250192130 Independent Escort Service AjmerLow Rate Call Girls Ajmer Anika 8250192130 Independent Escort Service Ajmer
Low Rate Call Girls Ajmer Anika 8250192130 Independent Escort Service AjmerRiya Pathan
 
Dakshineswar Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Se...
Dakshineswar Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Se...Dakshineswar Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Se...
Dakshineswar Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Se...aamir
 
VIP Call Girls Service Banjara Hills Hyderabad Call +91-8250192130
VIP Call Girls Service Banjara Hills Hyderabad Call +91-8250192130VIP Call Girls Service Banjara Hills Hyderabad Call +91-8250192130
VIP Call Girls Service Banjara Hills Hyderabad Call +91-8250192130Suhani Kapoor
 
Book Call Girls in Panchpota - 8250192130 | 24x7 Service Available Near Me
Book Call Girls in Panchpota - 8250192130 | 24x7 Service Available Near MeBook Call Girls in Panchpota - 8250192130 | 24x7 Service Available Near Me
Book Call Girls in Panchpota - 8250192130 | 24x7 Service Available Near Meanamikaraghav4
 
VIP Call Girl Kolhapur Aashi 8250192130 Independent Escort Service Kolhapur
VIP Call Girl Kolhapur Aashi 8250192130 Independent Escort Service KolhapurVIP Call Girl Kolhapur Aashi 8250192130 Independent Escort Service Kolhapur
VIP Call Girl Kolhapur Aashi 8250192130 Independent Escort Service KolhapurRiya Pathan
 
(DIVYA) Dhanori Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(DIVYA) Dhanori Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(DIVYA) Dhanori Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(DIVYA) Dhanori Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
College Call Girls New Alipore - For 7001035870 Cheap & Best with original Ph...
College Call Girls New Alipore - For 7001035870 Cheap & Best with original Ph...College Call Girls New Alipore - For 7001035870 Cheap & Best with original Ph...
College Call Girls New Alipore - For 7001035870 Cheap & Best with original Ph...anamikaraghav4
 
Housewife Call Girls Sonagachi - 8250192130 Booking and charges genuine rate ...
Housewife Call Girls Sonagachi - 8250192130 Booking and charges genuine rate ...Housewife Call Girls Sonagachi - 8250192130 Booking and charges genuine rate ...
Housewife Call Girls Sonagachi - 8250192130 Booking and charges genuine rate ...Riya Pathan
 
Independent Joka Escorts ✔ 8250192130 ✔ Full Night With Room Online Booking 2...
Independent Joka Escorts ✔ 8250192130 ✔ Full Night With Room Online Booking 2...Independent Joka Escorts ✔ 8250192130 ✔ Full Night With Room Online Booking 2...
Independent Joka Escorts ✔ 8250192130 ✔ Full Night With Room Online Booking 2...noor ahmed
 
Nayabad Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Sex At ...
Nayabad Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Sex At ...Nayabad Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Sex At ...
Nayabad Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Sex At ...aamir
 
(Dipika) Call Girls in Bangur ! 8250192130 ₹2999 Only and Free Hotel Delivery...
(Dipika) Call Girls in Bangur ! 8250192130 ₹2999 Only and Free Hotel Delivery...(Dipika) Call Girls in Bangur ! 8250192130 ₹2999 Only and Free Hotel Delivery...
(Dipika) Call Girls in Bangur ! 8250192130 ₹2999 Only and Free Hotel Delivery...Riya Pathan
 

Recently uploaded (20)

Call Girl Nashik Amaira 7001305949 Independent Escort Service Nashik
Call Girl Nashik Amaira 7001305949 Independent Escort Service NashikCall Girl Nashik Amaira 7001305949 Independent Escort Service Nashik
Call Girl Nashik Amaira 7001305949 Independent Escort Service Nashik
 
Kolkata Call Girl Airport Kolkata 👉 8250192130 ❣️💯 Available With Room 24×7
Kolkata Call Girl Airport Kolkata 👉 8250192130 ❣️💯 Available With Room 24×7Kolkata Call Girl Airport Kolkata 👉 8250192130 ❣️💯 Available With Room 24×7
Kolkata Call Girl Airport Kolkata 👉 8250192130 ❣️💯 Available With Room 24×7
 
VIP Call Girls Nagpur Megha Call 7001035870 Meet With Nagpur Escorts
VIP Call Girls Nagpur Megha Call 7001035870 Meet With Nagpur EscortsVIP Call Girls Nagpur Megha Call 7001035870 Meet With Nagpur Escorts
VIP Call Girls Nagpur Megha Call 7001035870 Meet With Nagpur Escorts
 
Air-Hostess Call Girls Shobhabazar | 8250192130 At Low Cost Cash Payment Booking
Air-Hostess Call Girls Shobhabazar | 8250192130 At Low Cost Cash Payment BookingAir-Hostess Call Girls Shobhabazar | 8250192130 At Low Cost Cash Payment Booking
Air-Hostess Call Girls Shobhabazar | 8250192130 At Low Cost Cash Payment Booking
 
Independent Hatiara Escorts ✔ 8250192130 ✔ Full Night With Room Online Bookin...
Independent Hatiara Escorts ✔ 8250192130 ✔ Full Night With Room Online Bookin...Independent Hatiara Escorts ✔ 8250192130 ✔ Full Night With Room Online Bookin...
Independent Hatiara Escorts ✔ 8250192130 ✔ Full Night With Room Online Bookin...
 
Call Girls Chirag Delhi Delhi WhatsApp Number 9711199171
Call Girls Chirag Delhi Delhi WhatsApp Number 9711199171Call Girls Chirag Delhi Delhi WhatsApp Number 9711199171
Call Girls Chirag Delhi Delhi WhatsApp Number 9711199171
 
Call Girl Nashik Saloni 7001305949 Independent Escort Service Nashik
Call Girl Nashik Saloni 7001305949 Independent Escort Service NashikCall Girl Nashik Saloni 7001305949 Independent Escort Service Nashik
Call Girl Nashik Saloni 7001305949 Independent Escort Service Nashik
 
College Call Girl in Rajiv Chowk Delhi 9634446618 Short 1500 Night 6000 Best ...
College Call Girl in Rajiv Chowk Delhi 9634446618 Short 1500 Night 6000 Best ...College Call Girl in Rajiv Chowk Delhi 9634446618 Short 1500 Night 6000 Best ...
College Call Girl in Rajiv Chowk Delhi 9634446618 Short 1500 Night 6000 Best ...
 
Contact:- 8860008073 Call Girls in Karnal Escort Service Available at Afforda...
Contact:- 8860008073 Call Girls in Karnal Escort Service Available at Afforda...Contact:- 8860008073 Call Girls in Karnal Escort Service Available at Afforda...
Contact:- 8860008073 Call Girls in Karnal Escort Service Available at Afforda...
 
Low Rate Call Girls Ajmer Anika 8250192130 Independent Escort Service Ajmer
Low Rate Call Girls Ajmer Anika 8250192130 Independent Escort Service AjmerLow Rate Call Girls Ajmer Anika 8250192130 Independent Escort Service Ajmer
Low Rate Call Girls Ajmer Anika 8250192130 Independent Escort Service Ajmer
 
Dakshineswar Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Se...
Dakshineswar Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Se...Dakshineswar Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Se...
Dakshineswar Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Se...
 
VIP Call Girls Service Banjara Hills Hyderabad Call +91-8250192130
VIP Call Girls Service Banjara Hills Hyderabad Call +91-8250192130VIP Call Girls Service Banjara Hills Hyderabad Call +91-8250192130
VIP Call Girls Service Banjara Hills Hyderabad Call +91-8250192130
 
Book Call Girls in Panchpota - 8250192130 | 24x7 Service Available Near Me
Book Call Girls in Panchpota - 8250192130 | 24x7 Service Available Near MeBook Call Girls in Panchpota - 8250192130 | 24x7 Service Available Near Me
Book Call Girls in Panchpota - 8250192130 | 24x7 Service Available Near Me
 
VIP Call Girl Kolhapur Aashi 8250192130 Independent Escort Service Kolhapur
VIP Call Girl Kolhapur Aashi 8250192130 Independent Escort Service KolhapurVIP Call Girl Kolhapur Aashi 8250192130 Independent Escort Service Kolhapur
VIP Call Girl Kolhapur Aashi 8250192130 Independent Escort Service Kolhapur
 
(DIVYA) Dhanori Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(DIVYA) Dhanori Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(DIVYA) Dhanori Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(DIVYA) Dhanori Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
College Call Girls New Alipore - For 7001035870 Cheap & Best with original Ph...
College Call Girls New Alipore - For 7001035870 Cheap & Best with original Ph...College Call Girls New Alipore - For 7001035870 Cheap & Best with original Ph...
College Call Girls New Alipore - For 7001035870 Cheap & Best with original Ph...
 
Housewife Call Girls Sonagachi - 8250192130 Booking and charges genuine rate ...
Housewife Call Girls Sonagachi - 8250192130 Booking and charges genuine rate ...Housewife Call Girls Sonagachi - 8250192130 Booking and charges genuine rate ...
Housewife Call Girls Sonagachi - 8250192130 Booking and charges genuine rate ...
 
Independent Joka Escorts ✔ 8250192130 ✔ Full Night With Room Online Booking 2...
Independent Joka Escorts ✔ 8250192130 ✔ Full Night With Room Online Booking 2...Independent Joka Escorts ✔ 8250192130 ✔ Full Night With Room Online Booking 2...
Independent Joka Escorts ✔ 8250192130 ✔ Full Night With Room Online Booking 2...
 
Nayabad Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Sex At ...
Nayabad Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Sex At ...Nayabad Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Sex At ...
Nayabad Call Girls ✔ 8005736733 ✔ Hot Model With Sexy Bhabi Ready For Sex At ...
 
(Dipika) Call Girls in Bangur ! 8250192130 ₹2999 Only and Free Hotel Delivery...
(Dipika) Call Girls in Bangur ! 8250192130 ₹2999 Only and Free Hotel Delivery...(Dipika) Call Girls in Bangur ! 8250192130 ₹2999 Only and Free Hotel Delivery...
(Dipika) Call Girls in Bangur ! 8250192130 ₹2999 Only and Free Hotel Delivery...
 

Chap10alg

  • 1. CHAPTER 10 P and NP
  • 2. Algorithm 10.2.2 Crossword Puzzle This algorithm solves a crossword puzzle, represented by a Boolean matrix D [ i , j ], 1 = i,j = n , and a finite set of words W ⊆ Σ * . Σ is the alphabet, and D [ i , j ] is true if the square is blank and false if it is blocked. We construct the solution in a new matrix S [ i , j ], 1 = i,j = n . The algorithm returns true if the crossword can be solved. Input Parameters: D , W Output Parameters: None puzzle ( D , W ) { for i = 1 to n for j = 1 to n if ( D [ i , j ]) S [ i , j ] = guess ( Σ ) else S [ i , j ] = blocked for each word w in S if ( w  W ) return false return true }
  • 3. Algorithm 10.2.15 Graph k -coloring This algorithm finds a k -coloring of G = ( V , E ), if there is one, and stores it in the array c . The algorithm returns true if a coloring is found. Input Parameters: G = ( V , E ), k Output Parameters: None graph_coloring ( G , k ) { for each v in V c [ v ] = guess ({1,2,..., k }) for each v in V for each w in N ( v ) if ( c [ w ] == c [ v ]) return false return true }
  • 4. Algorithm 10.2.19 Hamiltonian Cycle This algorithm finds a Hamiltonian cycle in G = ( V , E ) if there is one and returns true in that case.
  • 5. Input Parameter: G = ( V , E ) Output Parameters: None hamiltonian_cycle ( G ) { n = | V | for i = 1 to n visited [ i ] = false for i = 1 to n { c [ i ] = guess ( V ) visited [ c [ i ]] = true } c [0] = c [ n ] // first node is the same as last // check that only edges of G are used for i = 0 to n - 1 if (( c [ i ], c [ i + 1])  E ) return false // check that all vertices have been visited for i = 1 to n if (!( visited [ i ])) return false return true }
  • 6. Algorithm 10.2.22 TSP This algorithm finds a Hamiltonian cycle in G = ( V , E , weight ) of total weight at most w if there is one and returns true in that case. Input Parameters: G = ( V , E , weight ), w Output Parameters: None tsp ( G , w ) { n = | V | for i = 1 to n c [ i ] = guess ( V ) c [0] = c [ n ] ...
  • 7.
  • 8. Example 10.2.26 graph_coloring ( G , k ) { for each v in V c [ v ] = 0 for each v in V { c [ v ] = guess ({1,2,..., k }) for each w in N ( v ) if ( c [ w ] == c [ v ]) return false } return true }
  • 9. Algorithm 10.3.18 Satisfiability Witness This algorithm takes as input a CNF formula ϕ on variables x 1 ,...,x n , and either returns a satisfying assignment for ϕ in the array x or false if there is no such assignment. It assumes that we have an algorithm A that decides whether a formula is satisfiable or not.
  • 10. Input Parameter: ϕ Output Parameter: x satisfiability_witness ( ϕ , x ) { if (!(A( ϕ )) return false for i = 1 to n { ψ = ϕ [ x i -> true] if (A( ϕ )) { x [ i ] = true ϕ = ψ } else { x[i] = false ϕ = ϕ [ x i -> false] } } return true }