SlideShare a Scribd company logo
CHAPTER 11 Coping with NP-completeness
Algorithm 11.1.4 Largest Independent Set This algorithm returns  α (G), the size of a largest independent set in  G  = ( V ,  E ). Input Parameter:  G  = ( V ,  E ) Output Parameters: None largest_independent_set ( G ) { if ( E  == Ø) return | V | else { pick first  v      V  such that  N ( v ) ≠ Ø G 1  =  G  - { v } G 2  =  G  - { v } -  N ( v ) k 1  =  largest_independent_set ( G 1 ) // assume  v  not in independent set k 2  =  largest_independent_set ( G 2 ) // assume  v  in independent set return  max ( k 1 ,  k 2  + 1) } }
Algorithm 11.1.11 3-Satisfiability This algorithm takes as an input a formula in CNF in which every clause contains at most three literals and returns true if and only if is satisfiable.
Input Parameter:  ϕ   Output Parameters: None 3_satisfiability ( ϕ ) { if ( ϕ  does not contain any clauses) return  ϕ  // ϕ  is the logical constant true or false if ( ϕ  contains a clause with one literal  a ) { ϕ  =  ϕ [ a  -> true] //  a  has to be true return 3_satisfiability( ϕ ) } if ( ϕ  contains a clause with two literals  a ,  b ) { ϕ 1  =  ϕ [ a  -> false][ b  -> true] ϕ 2  =  ϕ [ a  -> true] return 3_satisfiability( ϕ 1 )||3_satisfiability( ϕ 2 ) } if ( ϕ  contains a clause with three literals  a ,  b ,  c ) { ϕ 1  =  ϕ [ a  -> false][ b  -> false][ c  -> true] ϕ 2  =  ϕ [ a  -> false][ b  -> true] ϕ 3  =  ϕ [ a  -> true] return 3_satisfiability( ϕ 1 ) || 3_satisfiability( ϕ 2 ) || 3_satisfiability( ϕ 3 ) } }
Algorithm 11.2.1 Randomized  st-Connectivity This algorithm takes as an input a graph  G   = ( V ,  E ) and two vertices  s ,  t      V . It returns true  with probability one if there is a path from  s  to  t ; if there is no path from  s  to  t , it fails to terminate. Input Parameters:  G ,  s ,  t Output Parameters: None randomized_st_connectivity ( G ,  s ,  t ) { vertex  =  s while ( vertex  !=  t ) vertex  = random vertex from  N ( vertex ) return true }
Algorithm 11.2.4 Randomized Hamiltonian Path This algorithm takes as input a graph G and searches for a Hamiltonian path. It returns true if it finds a Hamiltonian path and false otherwise. randomized_hamiltonian_path ( G ) { v 0   = random vertex in  G i  = 0 do { N  =  N ( v i ) - { v 0 , . . . ,  v i-1 } //  N  contains those neighbors of  v i  (the current last // vertex of the path) that are not already on the path if ( N  ≠ Ø) { i  =  i  + 1 v i  = random vertex in  N } else if ( v j     N ( v i ) for some 0 =  j  <  i  - 1) ( v 0 , . . . ,  v i ) = ( v 0 , . . . ,  v j ,  v i , . . . ,  v j+1 ) else return false } while ( i  != | V | - 1) return true }
Algorithm 11.3.8 Next Fit This algorithm computes an assignment  b  of  n  items with sizes  s [1], . . . ,  s [ n ]    (0, 1] into bins and returns the number  k  of bins it used. Input Parameter:  s Output Parameters: None next_fit ( s ) { n  =  s . last k  = 1 // current bin size  = 0 //accumulated size of items in current bin for  i  = 1 to  n if ( size  +  s [ i ] = 1) { b [ i ] =  k  // enough room to add item  i  to bin  k size  =  size  +  s [ i ] } else { k  =  k  + 1 b [ i ] =  k size  =  s [ i ] } return  k }
Algorithm 11.3.13 First Fit This algorithm computes an assignment  b  of  n  items with sizes  s [1], . . . ,  s [ n ]    (0, 1] into bins and returns the number  k  of bins it used.
Input Parameter:  s Output Parameters: None first_fit ( s ) { n  =  s . last k  = 1 // number of bins used c [ k ] = 0 //  c [ i ] is the total size of items in bin  i for  i  = 1 to  n  { j  = 1 while ( c [ j ] +  s [ i ] > 1) { j  =  j  + 1 if ( j  >  k ) { // open new bin k  =  j   c [ k ] = 0 } } // add item  i  to bin  j b [ i ] =  j   c [ j ] =  c [ j ] +  s [ i ] } return  k }
Algorithm 11.3.16 First Fit Decreasing This algorithm computes an assignment  b  of  n  items with sizes  s [1], . . . ,  s [ n ]    (0, 1] into bins and returns the number  k  of bins it used. Input Parameter:  s Output Parameters: None first_fit_decreasing ( s ) { s . sort (>) // sort  s  in decreasing order return  first_fit ( s ) }
Algorithm 11.3.19 Greedy Coloring This algorithm takes as an input a graph  G  = ( V ,  E ) and constructs a coloring of the vertices of the graph such that no two adjacent vertices have the same color. Input Parameter:  G  = ( V , E ) Output Parameters: None greedy_coloring ( G ) { n  = | V | C  = {1,..., n } // set of colors for each  v      V color  v  with smallest color in  C  not used  by any vertex in  N ( v ) }
Algorithm 11.3.23 Wigderson Coloring This algorithm takes as input a 3-colorable graph  G  = ( V ,  E ) and constructs a coloring of the vertices of the graph such that no two adjacent vertices have the same color.
Input Parameter:  G  = ( V , E ) Output Parameters: None wigderson_coloring ( G ) { n  = | V | color_count  = 0 while ( V  contains a vertex of degree at least √ n ) { pick  v  of degree at least √ n G  = ( N ( v ), E ) two_color ( G , color_count ) //move on to next set of colors color_count  =  color_count  + 2  G  =  G  -  N ( v ) } greedy_coloring ( G ,  color_count )  // see new implementation below } greedy_coloring ( G , c ) { n  = | V | C  = { c ,..., c  +  n } // set of colors for each  v      V color  v  with smallest color in  C   not used by any vertex in  N ( v ) }
Algorithm 11.4.4 Vertex Cover This algorithm determines whether a graph  G  = ( V , E ) has a vertex cover of size at most  k . Input Parameter:  G  = ( V , E ) Fixed Parameter:  k Output Parameters: None vertex_cover ( G , k ) { if (( k  == 0) || ( E  == Ø)) return  E  == Ø else { pick first  e  = ( u , v ) in  E G 1   = ( V -{ u },  E -{( u , w ) |  w      V }) G 2   = ( V -{ v },  E -{( v , w ) |  w      V }) return vertex_cover( G 1 ,  k -1) || vertex_cover( G 2 ,  k -1) } }
Algorithm 11.4.7 Vertex Cover, Improved This algorithm determines whether a graph  G  = ( V , E ) has a vertex cover of size at most  k .
Input Parameter:  G  = ( V , E ) Fixed Parameter:  k Output Parameters: None improved_vertex_cover ( G , k ) { m  = 0 V ’ = Ø for each  v  in  V if ( larger_degree ( G , v , k )) m  =  m  + 1 else  // collect vertices of degree V ’ =  V ’    { v } // at most  k  in  V ’ if ( m  >  k ) return false // compute  G ’ E ’ = {( u , v ) | ( u , v )     E  and ( u , v )     V } G ’ = ( V , E ) // remove isolated vertices from  G ’ for each  v  in  V if (isolated( G ’, v )) G ’ =  G ’ - { v } if (| V ‘| > 2 k ( k  -  m ))  // in this case there cannot be  return false  // a  k  -  m  vertex cover return vertex_cover( G ’, k  -  m ) }
Algorithm 11.5.5 Queens This algorithm finds a solution to the  n -queens problem, which is stored in the array  q . Input Parameter:  n Output Parameter:  q queens ( n , q ) { do { q . random_permutation () do { swaps  = 0 // initialize counter for each  i , j     {1,...,  n } if (queen in column  i  or  j  under attack) if (swapping queens in column  i  and  j   reduces collisions) { q . swap ( i , j ) swaps  =  swaps  + 1 } } while ( swaps  > 0) } while (there are collisions in  q ) }
Local Search Heuristic This algorithm tries to improve an initial random guess by making local changes selected from a set of operations  T . The function  eval  evaluates the goodness of a solution. local_search () { c  = random element of the search space do { changed  = false for each  T      T  { c ’ =  T ( c ) Δ  =  eval ( c ) -  eval ( c ’) if ( Δ  < 0) { c  = c’ changed  = true } } } while ( changed ) output  c }
Iterated Local Search Heuristic This algorithm runs a local search heuristic repeatedly from random starting points.  T  is the set of local operations allowed. The function  eval  evaluates the goodness of a solution. iterated_local_search () { do { changed  = false c  = random element of the search space do { for each  T      T  { c ’ =  T ( c ) Δ  =  eval ( c ) -  eval ( c ’) if ( Δ  < 0) { c  = c’ changed  = true } } } while ( changed ) } while ( eval ( c ) is not acceptable) output  c }
Algorithm 11.5.7 Independent Set Search This algorithm searches for a large independent set in the input graph  G  .
Input Parameter:  G  = ( V , E ) Output Parameters: None independent_set_search () { do { I  = random subset of  V do { changed  = false c  = random element of the search space do { for each  T      T  { I ’ = I  Δ  {v}  //  Δ  as symmetric difference Δ  =  eval ( I ) -  eval ( I ’) if ( Δ  < 0) { I  =  I ’ changed  = true } } } while ( changed ) } while ( eval ( I ) is not acceptable) output  I }
Independent Set Search through Simulated Annealing Input Parameter:  G  = ( V , E ) Output Parameters: None sa_independent_set_search () { I  = random subset of  V n  = 0 do { n  =  n  + 1 T  =  T ( n ) // set current temperature for each  v      V  { I ’ =  I   Δ  { v }  //  Δ  as symmetric difference Δ  =  eval ( I ) -  eval ( I ’) if (( Δ  < 0) || ( random () <  p ( T , Δ )) { I  =  I ’ } } } while ( eval ( I)  is not acceptable) output  I }

More Related Content

What's hot

Maps&hash tables
Maps&hash tablesMaps&hash tables
Maps&hash tables
Priyanka Rana
 
Chap10alg
Chap10algChap10alg
Chap10alg
Munkhchimeg
 
Lec1
Lec1Lec1
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
Protap Mondal
 
Control System Homework Help
Control System Homework HelpControl System Homework Help
Control System Homework Help
Matlab Assignment Experts
 
Signal Processing Assignment Help
Signal Processing Assignment HelpSignal Processing Assignment Help
Signal Processing Assignment Help
Matlab Assignment Experts
 
Digital Signal Processing Assignment Help
Digital Signal Processing Assignment HelpDigital Signal Processing Assignment Help
Digital Signal Processing Assignment Help
Matlab Assignment Experts
 
Arrays
ArraysArrays
Signal Processing Assignment Help
Signal Processing Assignment HelpSignal Processing Assignment Help
Signal Processing Assignment Help
Matlab Assignment Experts
 
Mathematics notes and formula for class 12 chapter 7. integrals
Mathematics notes and formula for class 12 chapter 7. integrals Mathematics notes and formula for class 12 chapter 7. integrals
Mathematics notes and formula for class 12 chapter 7. integrals
sakhi pathak
 
Integration material
Integration material Integration material
Integration material
Surya Swaroop
 
Signals Processing Homework Help
Signals Processing Homework HelpSignals Processing Homework Help
Signals Processing Homework Help
Matlab Assignment Experts
 
Unit 3-Greedy Method
Unit 3-Greedy MethodUnit 3-Greedy Method
Unit 3-Greedy Method
DevaKumari Vijay
 
Basic_analysis.ppt
Basic_analysis.pptBasic_analysis.ppt
Basic_analysis.ppt
SoumyaJ3
 
Aaex4 group2(äž­è‹±ć€Ÿé›œ)
Aaex4 group2(äž­è‹±ć€Ÿé›œ)Aaex4 group2(äž­è‹±ć€Ÿé›œ)
Aaex4 group2(äž­è‹±ć€Ÿé›œ)
Shiang-Yun Yang
 
DSP System Homework Help
DSP System Homework HelpDSP System Homework Help
DSP System Homework Help
Matlab Assignment Experts
 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexity
Ankit Katiyar
 
Lec4
Lec4Lec4
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
Saranya Natarajan
 

What's hot (19)

Maps&hash tables
Maps&hash tablesMaps&hash tables
Maps&hash tables
 
Chap10alg
Chap10algChap10alg
Chap10alg
 
Lec1
Lec1Lec1
Lec1
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
Control System Homework Help
Control System Homework HelpControl System Homework Help
Control System Homework Help
 
Signal Processing Assignment Help
Signal Processing Assignment HelpSignal Processing Assignment Help
Signal Processing Assignment Help
 
Digital Signal Processing Assignment Help
Digital Signal Processing Assignment HelpDigital Signal Processing Assignment Help
Digital Signal Processing Assignment Help
 
Arrays
ArraysArrays
Arrays
 
Signal Processing Assignment Help
Signal Processing Assignment HelpSignal Processing Assignment Help
Signal Processing Assignment Help
 
Mathematics notes and formula for class 12 chapter 7. integrals
Mathematics notes and formula for class 12 chapter 7. integrals Mathematics notes and formula for class 12 chapter 7. integrals
Mathematics notes and formula for class 12 chapter 7. integrals
 
Integration material
Integration material Integration material
Integration material
 
Signals Processing Homework Help
Signals Processing Homework HelpSignals Processing Homework Help
Signals Processing Homework Help
 
Unit 3-Greedy Method
Unit 3-Greedy MethodUnit 3-Greedy Method
Unit 3-Greedy Method
 
Basic_analysis.ppt
Basic_analysis.pptBasic_analysis.ppt
Basic_analysis.ppt
 
Aaex4 group2(äž­è‹±ć€Ÿé›œ)
Aaex4 group2(äž­è‹±ć€Ÿé›œ)Aaex4 group2(äž­è‹±ć€Ÿé›œ)
Aaex4 group2(äž­è‹±ć€Ÿé›œ)
 
DSP System Homework Help
DSP System Homework HelpDSP System Homework Help
DSP System Homework Help
 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexity
 
Lec4
Lec4Lec4
Lec4
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
 

Viewers also liked

Ded algorithm1
Ded algorithm1Ded algorithm1
Ded algorithm1Munhchimeg
 
Cei week 1
Cei week 1Cei week 1
Cei week 1
marina1982
 
Hybrid worlds fungi final - crews
Hybrid worlds   fungi final - crewsHybrid worlds   fungi final - crews
Hybrid worlds fungi final - crews
rv media
 
Natura2000 V2 En
Natura2000 V2 EnNatura2000 V2 En
Natura2000 V2 En
atelletxea
 
Lecture4
Lecture4Lecture4
Lecture4Munhchimeg
 
Lecture913
Lecture913Lecture913
Lecture913Munhchimeg
 
Hybrid worlds - Fungi Progression - crews
Hybrid worlds -  Fungi Progression - crewsHybrid worlds -  Fungi Progression - crews
Hybrid worlds - Fungi Progression - crews
rv media
 
Barrier of packaging
Barrier of packagingBarrier of packaging
Barrier of packaging
hoangvunl
 
Cei week 2
Cei week 2Cei week 2
Cei week 2
marina1982
 
Presentatie gemeente Groningen Inkoopbeleid
Presentatie gemeente Groningen InkoopbeleidPresentatie gemeente Groningen Inkoopbeleid
Presentatie gemeente Groningen Inkoopbeleid
Johan Stuiver
 
Nings To Knols Upload
Nings To Knols UploadNings To Knols Upload
Nings To Knols Upload
guesta3ed78
 
Chap07alg
Chap07algChap07alg
Chap07alg
Munhchimeg
 
Python
PythonPython
Python
Ian Gillingham
 
Alliantiefabriek Noord Holland Duurzame Projecten
Alliantiefabriek Noord Holland Duurzame ProjectenAlliantiefabriek Noord Holland Duurzame Projecten
Alliantiefabriek Noord Holland Duurzame ProjectenJohan Stuiver
 
TLF Reunion 2011
TLF Reunion 2011TLF Reunion 2011
TLF Reunion 2011
Debbie Horres
 
Resume
ResumeResume
Resume
waelhakim
 
Don't Screw Up Your Licensing
Don't Screw Up Your LicensingDon't Screw Up Your Licensing
Don't Screw Up Your Licensing
Ansel Halliburton
 
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
brianlynch
 
Profiting In A LinkedIn Economy
Profiting In A LinkedIn EconomyProfiting In A LinkedIn Economy
Profiting In A LinkedIn Economy
removed_44c82da98a9bdb2f751ea1fb0a033ddc
 
Hybrid worlds fungi updated - crews
Hybrid worlds   fungi updated - crewsHybrid worlds   fungi updated - crews
Hybrid worlds fungi updated - crews
rv media
 

Viewers also liked (20)

Ded algorithm1
Ded algorithm1Ded algorithm1
Ded algorithm1
 
Cei week 1
Cei week 1Cei week 1
Cei week 1
 
Hybrid worlds fungi final - crews
Hybrid worlds   fungi final - crewsHybrid worlds   fungi final - crews
Hybrid worlds fungi final - crews
 
Natura2000 V2 En
Natura2000 V2 EnNatura2000 V2 En
Natura2000 V2 En
 
Lecture4
Lecture4Lecture4
Lecture4
 
Lecture913
Lecture913Lecture913
Lecture913
 
Hybrid worlds - Fungi Progression - crews
Hybrid worlds -  Fungi Progression - crewsHybrid worlds -  Fungi Progression - crews
Hybrid worlds - Fungi Progression - crews
 
Barrier of packaging
Barrier of packagingBarrier of packaging
Barrier of packaging
 
Cei week 2
Cei week 2Cei week 2
Cei week 2
 
Presentatie gemeente Groningen Inkoopbeleid
Presentatie gemeente Groningen InkoopbeleidPresentatie gemeente Groningen Inkoopbeleid
Presentatie gemeente Groningen Inkoopbeleid
 
Nings To Knols Upload
Nings To Knols UploadNings To Knols Upload
Nings To Knols Upload
 
Chap07alg
Chap07algChap07alg
Chap07alg
 
Python
PythonPython
Python
 
Alliantiefabriek Noord Holland Duurzame Projecten
Alliantiefabriek Noord Holland Duurzame ProjectenAlliantiefabriek Noord Holland Duurzame Projecten
Alliantiefabriek Noord Holland Duurzame Projecten
 
TLF Reunion 2011
TLF Reunion 2011TLF Reunion 2011
TLF Reunion 2011
 
Resume
ResumeResume
Resume
 
Don't Screw Up Your Licensing
Don't Screw Up Your LicensingDon't Screw Up Your Licensing
Don't Screw Up Your Licensing
 
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
 
Profiting In A LinkedIn Economy
Profiting In A LinkedIn EconomyProfiting In A LinkedIn Economy
Profiting In A LinkedIn Economy
 
Hybrid worlds fungi updated - crews
Hybrid worlds   fungi updated - crewsHybrid worlds   fungi updated - crews
Hybrid worlds fungi updated - crews
 

Similar to Chap11alg

Chap10alg
Chap10algChap10alg
Chap10alg
Munhchimeg
 
Chap05alg
Chap05algChap05alg
Chap05alg
Munhchimeg
 
Chap05alg
Chap05algChap05alg
Chap05alg
Munkhchimeg
 
Chap06alg
Chap06algChap06alg
Chap06alg
Munkhchimeg
 
Chap06alg
Chap06algChap06alg
Chap06alg
Munhchimeg
 
Scientific Computing II Numerical Tools & Algorithms - CEI40 - AGA
Scientific Computing II Numerical Tools & Algorithms - CEI40 - AGAScientific Computing II Numerical Tools & Algorithms - CEI40 - AGA
Scientific Computing II Numerical Tools & Algorithms - CEI40 - AGA
Ahmed Gamal Abdel Gawad
 
Cs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer keyCs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer key
appasami
 
Chap08alg
Chap08algChap08alg
Chap08alg
Munhchimeg
 
Chap08alg
Chap08algChap08alg
Chap08alg
Munkhchimeg
 
40+ examples of user defined methods in java with explanation
40+ examples of user defined methods in java with explanation40+ examples of user defined methods in java with explanation
40+ examples of user defined methods in java with explanation
Harish Gyanani
 
Crypto cs36 39
Crypto cs36 39Crypto cs36 39
Crypto cs36 39
sravanbabu
 
module4_dynamic programming_2022.pdf
module4_dynamic programming_2022.pdfmodule4_dynamic programming_2022.pdf
module4_dynamic programming_2022.pdf
Shiwani Gupta
 
Chap12alg
Chap12algChap12alg
Chap12alg
Munhchimeg
 
Chap12alg
Chap12algChap12alg
Chap12alg
Munkhchimeg
 
Chap04alg
Chap04algChap04alg
Chap04alg
Munhchimeg
 
Chap04alg
Chap04algChap04alg
Chap04alg
Munkhchimeg
 
Daa chapter11
Daa chapter11Daa chapter11
Daa chapter11
B.Kirron Reddi
 
Chap4
Chap4Chap4
Chap4
nathanurag
 
Think Like Scilab and Become a Numerical Programming Expert- Notes for Beginn...
Think Like Scilab and Become a Numerical Programming Expert- Notes for Beginn...Think Like Scilab and Become a Numerical Programming Expert- Notes for Beginn...
Think Like Scilab and Become a Numerical Programming Expert- Notes for Beginn...
ssuserd6b1fd
 
Scilab help book 2 of 2
Scilab help book 2 of 2Scilab help book 2 of 2
Scilab help book 2 of 2
Arun Umrao
 

Similar to Chap11alg (20)

Chap10alg
Chap10algChap10alg
Chap10alg
 
Chap05alg
Chap05algChap05alg
Chap05alg
 
Chap05alg
Chap05algChap05alg
Chap05alg
 
Chap06alg
Chap06algChap06alg
Chap06alg
 
Chap06alg
Chap06algChap06alg
Chap06alg
 
Scientific Computing II Numerical Tools & Algorithms - CEI40 - AGA
Scientific Computing II Numerical Tools & Algorithms - CEI40 - AGAScientific Computing II Numerical Tools & Algorithms - CEI40 - AGA
Scientific Computing II Numerical Tools & Algorithms - CEI40 - AGA
 
Cs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer keyCs6402 design and analysis of algorithms may june 2016 answer key
Cs6402 design and analysis of algorithms may june 2016 answer key
 
Chap08alg
Chap08algChap08alg
Chap08alg
 
Chap08alg
Chap08algChap08alg
Chap08alg
 
40+ examples of user defined methods in java with explanation
40+ examples of user defined methods in java with explanation40+ examples of user defined methods in java with explanation
40+ examples of user defined methods in java with explanation
 
Crypto cs36 39
Crypto cs36 39Crypto cs36 39
Crypto cs36 39
 
module4_dynamic programming_2022.pdf
module4_dynamic programming_2022.pdfmodule4_dynamic programming_2022.pdf
module4_dynamic programming_2022.pdf
 
Chap12alg
Chap12algChap12alg
Chap12alg
 
Chap12alg
Chap12algChap12alg
Chap12alg
 
Chap04alg
Chap04algChap04alg
Chap04alg
 
Chap04alg
Chap04algChap04alg
Chap04alg
 
Daa chapter11
Daa chapter11Daa chapter11
Daa chapter11
 
Chap4
Chap4Chap4
Chap4
 
Think Like Scilab and Become a Numerical Programming Expert- Notes for Beginn...
Think Like Scilab and Become a Numerical Programming Expert- Notes for Beginn...Think Like Scilab and Become a Numerical Programming Expert- Notes for Beginn...
Think Like Scilab and Become a Numerical Programming Expert- Notes for Beginn...
 
Scilab help book 2 of 2
Scilab help book 2 of 2Scilab help book 2 of 2
Scilab help book 2 of 2
 

More from Munhchimeg

Ded algorithm
Ded algorithmDed algorithm
Ded algorithmMunhchimeg
 
Tobch lecture1
Tobch lecture1Tobch lecture1
Tobch lecture1Munhchimeg
 
Tobch lecture
Tobch lectureTobch lecture
Tobch lectureMunhchimeg
 
Recursive
RecursiveRecursive
RecursiveMunhchimeg
 
Protsesor
ProtsesorProtsesor
ProtsesorMunhchimeg
 
Lecture916
Lecture916Lecture916
Lecture916Munhchimeg
 
Lecture915
Lecture915Lecture915
Lecture915Munhchimeg
 
Lecture914
Lecture914Lecture914
Lecture914Munhchimeg
 
Lecture912
Lecture912Lecture912
Lecture912Munhchimeg
 
Lecture911
Lecture911Lecture911
Lecture911Munhchimeg
 
Lecture910
Lecture910Lecture910
Lecture910Munhchimeg
 
Lecture9
Lecture9Lecture9
Lecture9Munhchimeg
 
Lecture8
Lecture8Lecture8
Lecture8Munhchimeg
 
Lecture7
Lecture7Lecture7
Lecture7Munhchimeg
 
Lecture6
Lecture6Lecture6
Lecture6Munhchimeg
 
Lecture5
Lecture5Lecture5
Lecture5Munhchimeg
 
Lecture3
Lecture3Lecture3
Lecture3Munhchimeg
 
Protsesor
ProtsesorProtsesor
ProtsesorMunhchimeg
 
Pm104 standard
Pm104 standardPm104 standard
Pm104 standardMunhchimeg
 
Pm104 2004 2005
Pm104 2004 2005Pm104 2004 2005
Pm104 2004 2005Munhchimeg
 

More from Munhchimeg (20)

Ded algorithm
Ded algorithmDed algorithm
Ded algorithm
 
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
 
Lecture912
Lecture912Lecture912
Lecture912
 
Lecture911
Lecture911Lecture911
Lecture911
 
Lecture910
Lecture910Lecture910
Lecture910
 
Lecture9
Lecture9Lecture9
Lecture9
 
Lecture8
Lecture8Lecture8
Lecture8
 
Lecture7
Lecture7Lecture7
Lecture7
 
Lecture6
Lecture6Lecture6
Lecture6
 
Lecture5
Lecture5Lecture5
Lecture5
 
Lecture3
Lecture3Lecture3
Lecture3
 
Protsesor
ProtsesorProtsesor
Protsesor
 
Pm104 standard
Pm104 standardPm104 standard
Pm104 standard
 
Pm104 2004 2005
Pm104 2004 2005Pm104 2004 2005
Pm104 2004 2005
 

Recently uploaded

9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
saastr
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
Miro Wengner
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-UniversitÀt
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
ScyllaDB
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
Edge AI and Vision Alliance
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
DianaGray10
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
Pablo GĂłmez Abajo
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
Ajin Abraham
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
AstuteBusiness
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
Safe Software
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
Fwdays
 

Recently uploaded (20)

9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
 

Chap11alg

  • 1. CHAPTER 11 Coping with NP-completeness
  • 2. Algorithm 11.1.4 Largest Independent Set This algorithm returns α (G), the size of a largest independent set in G = ( V , E ). Input Parameter: G = ( V , E ) Output Parameters: None largest_independent_set ( G ) { if ( E == Ø) return | V | else { pick first v  V such that N ( v ) ≠ Ø G 1 = G - { v } G 2 = G - { v } - N ( v ) k 1 = largest_independent_set ( G 1 ) // assume v not in independent set k 2 = largest_independent_set ( G 2 ) // assume v in independent set return max ( k 1 , k 2 + 1) } }
  • 3. Algorithm 11.1.11 3-Satisfiability This algorithm takes as an input a formula in CNF in which every clause contains at most three literals and returns true if and only if is satisfiable.
  • 4. Input Parameter: ϕ Output Parameters: None 3_satisfiability ( ϕ ) { if ( ϕ does not contain any clauses) return ϕ // ϕ is the logical constant true or false if ( ϕ contains a clause with one literal a ) { ϕ = ϕ [ a -> true] // a has to be true return 3_satisfiability( ϕ ) } if ( ϕ contains a clause with two literals a , b ) { ϕ 1 = ϕ [ a -> false][ b -> true] ϕ 2 = ϕ [ a -> true] return 3_satisfiability( ϕ 1 )||3_satisfiability( ϕ 2 ) } if ( ϕ contains a clause with three literals a , b , c ) { ϕ 1 = ϕ [ a -> false][ b -> false][ c -> true] ϕ 2 = ϕ [ a -> false][ b -> true] ϕ 3 = ϕ [ a -> true] return 3_satisfiability( ϕ 1 ) || 3_satisfiability( ϕ 2 ) || 3_satisfiability( ϕ 3 ) } }
  • 5. Algorithm 11.2.1 Randomized st-Connectivity This algorithm takes as an input a graph G = ( V , E ) and two vertices s , t  V . It returns true with probability one if there is a path from s to t ; if there is no path from s to t , it fails to terminate. Input Parameters: G , s , t Output Parameters: None randomized_st_connectivity ( G , s , t ) { vertex = s while ( vertex != t ) vertex = random vertex from N ( vertex ) return true }
  • 6. Algorithm 11.2.4 Randomized Hamiltonian Path This algorithm takes as input a graph G and searches for a Hamiltonian path. It returns true if it finds a Hamiltonian path and false otherwise. randomized_hamiltonian_path ( G ) { v 0 = random vertex in G i = 0 do { N = N ( v i ) - { v 0 , . . . , v i-1 } // N contains those neighbors of v i (the current last // vertex of the path) that are not already on the path if ( N ≠ Ø) { i = i + 1 v i = random vertex in N } else if ( v j  N ( v i ) for some 0 = j < i - 1) ( v 0 , . . . , v i ) = ( v 0 , . . . , v j , v i , . . . , v j+1 ) else return false } while ( i != | V | - 1) return true }
  • 7. Algorithm 11.3.8 Next Fit This algorithm computes an assignment b of n items with sizes s [1], . . . , s [ n ]  (0, 1] into bins and returns the number k of bins it used. Input Parameter: s Output Parameters: None next_fit ( s ) { n = s . last k = 1 // current bin size = 0 //accumulated size of items in current bin for i = 1 to n if ( size + s [ i ] = 1) { b [ i ] = k // enough room to add item i to bin k size = size + s [ i ] } else { k = k + 1 b [ i ] = k size = s [ i ] } return k }
  • 8. Algorithm 11.3.13 First Fit This algorithm computes an assignment b of n items with sizes s [1], . . . , s [ n ]  (0, 1] into bins and returns the number k of bins it used.
  • 9. Input Parameter: s Output Parameters: None first_fit ( s ) { n = s . last k = 1 // number of bins used c [ k ] = 0 // c [ i ] is the total size of items in bin i for i = 1 to n { j = 1 while ( c [ j ] + s [ i ] > 1) { j = j + 1 if ( j > k ) { // open new bin k = j c [ k ] = 0 } } // add item i to bin j b [ i ] = j c [ j ] = c [ j ] + s [ i ] } return k }
  • 10. Algorithm 11.3.16 First Fit Decreasing This algorithm computes an assignment b of n items with sizes s [1], . . . , s [ n ]  (0, 1] into bins and returns the number k of bins it used. Input Parameter: s Output Parameters: None first_fit_decreasing ( s ) { s . sort (>) // sort s in decreasing order return first_fit ( s ) }
  • 11. Algorithm 11.3.19 Greedy Coloring This algorithm takes as an input a graph G = ( V , E ) and constructs a coloring of the vertices of the graph such that no two adjacent vertices have the same color. Input Parameter: G = ( V , E ) Output Parameters: None greedy_coloring ( G ) { n = | V | C = {1,..., n } // set of colors for each v  V color v with smallest color in C not used by any vertex in N ( v ) }
  • 12. Algorithm 11.3.23 Wigderson Coloring This algorithm takes as input a 3-colorable graph G = ( V , E ) and constructs a coloring of the vertices of the graph such that no two adjacent vertices have the same color.
  • 13. Input Parameter: G = ( V , E ) Output Parameters: None wigderson_coloring ( G ) { n = | V | color_count = 0 while ( V contains a vertex of degree at least √ n ) { pick v of degree at least √ n G = ( N ( v ), E ) two_color ( G , color_count ) //move on to next set of colors color_count = color_count + 2 G = G - N ( v ) } greedy_coloring ( G , color_count ) // see new implementation below } greedy_coloring ( G , c ) { n = | V | C = { c ,..., c + n } // set of colors for each v  V color v with smallest color in C not used by any vertex in N ( v ) }
  • 14. Algorithm 11.4.4 Vertex Cover This algorithm determines whether a graph G = ( V , E ) has a vertex cover of size at most k . Input Parameter: G = ( V , E ) Fixed Parameter: k Output Parameters: None vertex_cover ( G , k ) { if (( k == 0) || ( E == Ø)) return E == Ø else { pick first e = ( u , v ) in E G 1 = ( V -{ u }, E -{( u , w ) | w  V }) G 2 = ( V -{ v }, E -{( v , w ) | w  V }) return vertex_cover( G 1 , k -1) || vertex_cover( G 2 , k -1) } }
  • 15. Algorithm 11.4.7 Vertex Cover, Improved This algorithm determines whether a graph G = ( V , E ) has a vertex cover of size at most k .
  • 16. Input Parameter: G = ( V , E ) Fixed Parameter: k Output Parameters: None improved_vertex_cover ( G , k ) { m = 0 V ’ = Ø for each v in V if ( larger_degree ( G , v , k )) m = m + 1 else // collect vertices of degree V ’ = V ’  { v } // at most k in V ’ if ( m > k ) return false // compute G ’ E ’ = {( u , v ) | ( u , v )  E and ( u , v )  V } G ’ = ( V , E ) // remove isolated vertices from G ’ for each v in V if (isolated( G ’, v )) G ’ = G ’ - { v } if (| V ‘| > 2 k ( k - m )) // in this case there cannot be return false // a k - m vertex cover return vertex_cover( G ’, k - m ) }
  • 17. Algorithm 11.5.5 Queens This algorithm finds a solution to the n -queens problem, which is stored in the array q . Input Parameter: n Output Parameter: q queens ( n , q ) { do { q . random_permutation () do { swaps = 0 // initialize counter for each i , j  {1,..., n } if (queen in column i or j under attack) if (swapping queens in column i and j reduces collisions) { q . swap ( i , j ) swaps = swaps + 1 } } while ( swaps > 0) } while (there are collisions in q ) }
  • 18. Local Search Heuristic This algorithm tries to improve an initial random guess by making local changes selected from a set of operations T . The function eval evaluates the goodness of a solution. local_search () { c = random element of the search space do { changed = false for each T  T { c ’ = T ( c ) Δ = eval ( c ) - eval ( c ’) if ( Δ < 0) { c = c’ changed = true } } } while ( changed ) output c }
  • 19. Iterated Local Search Heuristic This algorithm runs a local search heuristic repeatedly from random starting points. T is the set of local operations allowed. The function eval evaluates the goodness of a solution. iterated_local_search () { do { changed = false c = random element of the search space do { for each T  T { c ’ = T ( c ) Δ = eval ( c ) - eval ( c ’) if ( Δ < 0) { c = c’ changed = true } } } while ( changed ) } while ( eval ( c ) is not acceptable) output c }
  • 20. Algorithm 11.5.7 Independent Set Search This algorithm searches for a large independent set in the input graph G .
  • 21. Input Parameter: G = ( V , E ) Output Parameters: None independent_set_search () { do { I = random subset of V do { changed = false c = random element of the search space do { for each T  T { I ’ = I Δ {v} // Δ as symmetric difference Δ = eval ( I ) - eval ( I ’) if ( Δ < 0) { I = I ’ changed = true } } } while ( changed ) } while ( eval ( I ) is not acceptable) output I }
  • 22. Independent Set Search through Simulated Annealing Input Parameter: G = ( V , E ) Output Parameters: None sa_independent_set_search () { I = random subset of V n = 0 do { n = n + 1 T = T ( n ) // set current temperature for each v  V { I ’ = I Δ { v } // Δ as symmetric difference Δ = eval ( I ) - eval ( I ’) if (( Δ < 0) || ( random () < p ( T , Δ )) { I = I ’ } } } while ( eval ( I) is not acceptable) output I }