SlideShare uma empresa Scribd logo
1 de 11
CHAPTER 5 Divide and Conquer
Algorithm 5.1.4 Tiling a Deficient Board with Trominoes This algorithm constructs a tiling by trominoes of a deficient  n × n  board where  n  is a power of 2.
Input Parameters:  n , a power of 2 (the board size); the location  L  of the missing square Output Parameters: None tile ( n , L ) { if ( n  == 2) { // the board is a right tromino  T tile with  T return } divide the board into four  n /2 ×  n /2 subboards place one tromino as in Figure 5.1.4(b) // each of the 1 × 1 squares in this tromino  // is considered as missing let  m 1 , m 2 , m 3 , m 4  be the locations of the missing squares tile( n /2, m 1 ) tile( n /2, m 2 ) tile( n /2, m 3 ) tile( n /2, m 4 ) }
Algorithm 5.2.2 Merge This algorithm receives as input indexes  i ,  m , and  j , and an array  a , where  a [ i ], ... ,  a [ m ] and  a [ m  +1], ... ,  a [ j ] are each sorted in nondecreasing order. These two nondecreasing subarrays are merged into a single nondecreasing array.
Input Parameters:  a , i , m , j Output Parameter:  a merge ( a , i , m , j ) { p  =  i  // index in  a [ i ], ... ,  a [ m ] q  =  m  + 1 // index in  a [ m  + 1], ... ,  a [ j ] r  =  i  // index in a local array  c while ( p  ≤  m  &&  q  ≤  j ) { // copy smaller value to  c if ( a [ p ] ≤  a [ q ]) { c [ r ] =  a [ p ] p  =  p  + 1 } else { c [ r ] =  a [ q ] q  =  q  + 1 } r  =  r  + 1 } ...
... // copy remainder, if any, of first subarray to  c while ( p  ≤  m ) { c [ r ] =  a [ p ] p  =  p  + 1 r  =  r  + 1 } // copy remainder, if any, of second subarray to  c while ( q  ≤  j ) { c [ r ] =  a [ q ] q  =  q  + 1 r  =  r  + 1 } // copy  c  back to  a for  r  =  i  to  j a [ r ] =  c [ r ] }
Algorithm 5.2.3 Mergesort This algorithm sorts the array  a [ i ], ... ,  a [ j ] in nondecreasing order. It uses the merge algorithm (Algorithm 5.2.2). Input Parameters:  a , i , j Output Parameter:  a mergesort ( a , i , j ) { // if only one element, just return if ( i  ==  j ) return // divide a into two nearly equal parts m  = ( i  +  j )/2 // sort each half mergesort ( a , i , m ) mergesort ( a , m  + 1, j ) // merge the two sorted halves merge ( a , i , m , j ) }
Algorithm 5.3.2 Finding the Distance Between a Closest Pair of Points This algorithm finds the distance between a closest pair of points. The input is an array  p [1], ... ,  p [ n ] of  n  = 2 points. If  p  is a point,  p . x   is the  x - coordinate of  p , and  p . y   is the  y -coordinate of  p . The function  merge  is Algorithm 5.2.2 and  mergesort  is Algorithm 5.2.3. The function  merge  uses as the key the  y -coordinate of the point. The function  mergesort  uses as the key either the  x - or  y -coordinate of the point; the comments indicate which. The function  dist ( p , q ) returns the Euclidean distance between points  p  and  q .
Input Parameters:  p Output Parameter: None closest_pair ( p ) { n  =  p . last mergesort ( p ,1, n ) // sort by x-coordinate return  rec_cl_pair ( p ,1, n ) } //  rec_cl_pair  assumes that input is sorted by  x -coordinate. // At termination, the input is sorted by  y -coordinate. rec_cl_pair ( p , i , j ) { if ( j  -  i  < 3) { mergesort ( p , i , j ) // sort by  y -coordinate // find the distance delta between a closest pair delta  =  dist ( p [ i ], p [ i  + 1]) if ( j  -  i  == 1) // two points return delta // three points if ( dist ( p [ i  + 1], p [ i  + 2]) <  delta ) delta  =  dist ( p [ i  + 1], p [ i  + 2])  if ( dist ( p [ i ], p [ i  + 2]) <  delta ) delta  =  dist ( p [ i ], p [ i  + 2])  return  delta } ...
... k  = ( i  +  j )/ 2 l  =  p [ k ]. x deltaL  =  rec_cl_pair ( p , i , k ) deltaR  =  rec_cl_pair ( p , k  + 1, j ) delta  =  min ( deltaL , deltaR ) //  p [ i ], ... ,  p [ k ] is now sorted by  y -coordinate, and //  p [ k  + 1], ... ,  p [ j ] is now sorted by  y -coordinate. merge ( p , i , k , j ) //  p [ i ], ... ,  p [ j ] is now sorted by  y -coordinate. // store points in the vertical strip in  v . t  = 0 for  k  =  i  to  j if ( p [ k ]. x  > l -  delta  &&  p [ k ]. x  < l +  delta ) { t  =  t  + 1 v [ t ] =  p [ k ] } // look for closer pairs in the strip by comparing // each point in the strip to the next 7 points. for  k  = 1 to  t  - 1 for  s  =  k  + 1 to  min ( t , k  + 7) delta  =  min ( delta , dist ( v [ k ], v [ s ])) return  delta }
Algorithm 5.4.1 Matrix Product This algorithm computes the product  C  of the  n × n  matrices  A  and  B  directly from the definition of the matrix product. Input Parameters:  A , B Output Parameter:  C matrix_product ( A , B , C ) { n  =  A . last for  i  = 1 to  n for  j  = 1 to  n  { C [ i ][ j ] = 0 for  k  = 1 to  n C [ i ][ j ] =  C [ i ][ j ] +  A [ i ][ k ] *  B [ k ][ j ] } }

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Lecture 2 family of fcts
Lecture 2   family of fctsLecture 2   family of fcts
Lecture 2 family of fcts
 
MATLAB for Technical Computing
MATLAB for Technical ComputingMATLAB for Technical Computing
MATLAB for Technical Computing
 
An Introduction to Functional Programming using Haskell
An Introduction to Functional Programming using HaskellAn Introduction to Functional Programming using Haskell
An Introduction to Functional Programming using Haskell
 
Cs101 endsem 2014
Cs101 endsem 2014Cs101 endsem 2014
Cs101 endsem 2014
 
Programming with matlab session 6
Programming with matlab session 6Programming with matlab session 6
Programming with matlab session 6
 
Differential calculus
Differential calculus  Differential calculus
Differential calculus
 
Array
ArrayArray
Array
 
Ee693 questionshomework
Ee693 questionshomeworkEe693 questionshomework
Ee693 questionshomework
 
Extended network and algorithm finding maximal flows
Extended network and algorithm finding maximal flows Extended network and algorithm finding maximal flows
Extended network and algorithm finding maximal flows
 
Tsp branch and bound
Tsp branch and boundTsp branch and bound
Tsp branch and bound
 
Different types of functions
Different types of functionsDifferent types of functions
Different types of functions
 
Gentle Introduction to Functional Programming
Gentle Introduction to Functional ProgrammingGentle Introduction to Functional Programming
Gentle Introduction to Functional Programming
 
Lecture two
Lecture twoLecture two
Lecture two
 
Programming with matlab session 1
Programming with matlab session 1Programming with matlab session 1
Programming with matlab session 1
 
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
 
The dag representation of basic blocks
The dag representation of basic blocksThe dag representation of basic blocks
The dag representation of basic blocks
 
Ezmath
EzmathEzmath
Ezmath
 
Computation Assignment Help
Computation Assignment Help Computation Assignment Help
Computation Assignment Help
 
FDM Numerical solution of Laplace Equation using MATLAB
FDM Numerical solution of Laplace Equation using MATLABFDM Numerical solution of Laplace Equation using MATLAB
FDM Numerical solution of Laplace Equation using MATLAB
 
strassen matrix multiplication algorithm
strassen matrix multiplication algorithmstrassen matrix multiplication algorithm
strassen matrix multiplication algorithm
 

Destaque

From Ink to Pixel and Beyond...
From Ink to Pixel and Beyond...From Ink to Pixel and Beyond...
From Ink to Pixel and Beyond...
guest9fdfb7cd
 
電子書籍と図書館 120619Ver.3
電子書籍と図書館 120619Ver.3電子書籍と図書館 120619Ver.3
電子書籍と図書館 120619Ver.3
shinya Jingushi
 
Worldcup2010 gs report
Worldcup2010 gs reportWorldcup2010 gs report
Worldcup2010 gs report
pemmott
 
Raporti Mbi Shqiperine ... Raport Su Albania
Raporti Mbi Shqiperine ... Raport Su AlbaniaRaporti Mbi Shqiperine ... Raport Su Albania
Raporti Mbi Shqiperine ... Raport Su Albania
Aleks Sandro
 
Nings To Knols Upload
Nings To Knols UploadNings To Knols Upload
Nings To Knols Upload
guesta3ed78
 
Disco Dirt Evaluation
Disco Dirt EvaluationDisco Dirt Evaluation
Disco Dirt Evaluation
hanmat
 
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
guestbdec7c
 
Barrier of packaging
Barrier of packagingBarrier of packaging
Barrier of packaging
hoangvunl
 
Pm104 standard
Pm104 standardPm104 standard
Pm104 standard
Munhchimeg
 

Destaque (20)

joaquina aizpuru
joaquina aizpurujoaquina aizpuru
joaquina aizpuru
 
From Ink to Pixel and Beyond...
From Ink to Pixel and Beyond...From Ink to Pixel and Beyond...
From Ink to Pixel and Beyond...
 
Timebanking, ICT, employment and employability in a European context
Timebanking, ICT, employment and employability in a European contextTimebanking, ICT, employment and employability in a European context
Timebanking, ICT, employment and employability in a European context
 
電子書籍と図書館 120619Ver.3
電子書籍と図書館 120619Ver.3電子書籍と図書館 120619Ver.3
電子書籍と図書館 120619Ver.3
 
Worldcup2010 gs report
Worldcup2010 gs reportWorldcup2010 gs report
Worldcup2010 gs report
 
2010 Training And Educational Offerings For Northern Ohio’S
2010 Training And Educational Offerings For Northern Ohio’S2010 Training And Educational Offerings For Northern Ohio’S
2010 Training And Educational Offerings For Northern Ohio’S
 
Chap04alg
Chap04algChap04alg
Chap04alg
 
Tobch lecture
Tobch lectureTobch lecture
Tobch lecture
 
Lecture911
Lecture911Lecture911
Lecture911
 
Raporti Mbi Shqiperine ... Raport Su Albania
Raporti Mbi Shqiperine ... Raport Su AlbaniaRaporti Mbi Shqiperine ... Raport Su Albania
Raporti Mbi Shqiperine ... Raport Su Albania
 
Chap02alg
Chap02algChap02alg
Chap02alg
 
Lissajous pattern
Lissajous patternLissajous pattern
Lissajous pattern
 
Nings To Knols Upload
Nings To Knols UploadNings To Knols Upload
Nings To Knols Upload
 
Hybrid worlds fungi updated - crews
Hybrid worlds   fungi updated - crewsHybrid worlds   fungi updated - crews
Hybrid worlds fungi updated - crews
 
Protsesor
ProtsesorProtsesor
Protsesor
 
Lecture911
Lecture911Lecture911
Lecture911
 
Disco Dirt Evaluation
Disco Dirt EvaluationDisco Dirt Evaluation
Disco Dirt Evaluation
 
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
 
Barrier of packaging
Barrier of packagingBarrier of packaging
Barrier of packaging
 
Pm104 standard
Pm104 standardPm104 standard
Pm104 standard
 

Semelhante a Chap05alg

Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)
stasimus
 

Semelhante a Chap05alg (20)

Chap08alg
Chap08algChap08alg
Chap08alg
 
Chap08alg
Chap08algChap08alg
Chap08alg
 
Tucker tensor analysis of Matern functions in spatial statistics
Tucker tensor analysis of Matern functions in spatial statistics Tucker tensor analysis of Matern functions in spatial statistics
Tucker tensor analysis of Matern functions in spatial statistics
 
algorithm Unit 3
algorithm Unit 3algorithm Unit 3
algorithm Unit 3
 
Chap11alg
Chap11algChap11alg
Chap11alg
 
Chap11alg
Chap11algChap11alg
Chap11alg
 
Unit 3 daa
Unit 3 daaUnit 3 daa
Unit 3 daa
 
Indefinite Integration One shot Revision
Indefinite Integration One shot Revision Indefinite Integration One shot Revision
Indefinite Integration One shot Revision
 
Chap12alg
Chap12algChap12alg
Chap12alg
 
Chap12alg
Chap12algChap12alg
Chap12alg
 
Data structure 8.pptx
Data structure 8.pptxData structure 8.pptx
Data structure 8.pptx
 
Chap09alg
Chap09algChap09alg
Chap09alg
 
Chap09alg
Chap09algChap09alg
Chap09alg
 
Chapter 2 Image Processing: Pixel Relation
Chapter 2 Image Processing: Pixel RelationChapter 2 Image Processing: Pixel Relation
Chapter 2 Image Processing: Pixel Relation
 
Chap06alg
Chap06algChap06alg
Chap06alg
 
Chap06alg
Chap06algChap06alg
Chap06alg
 
Nbvtalkatbzaonencryptionpuzzles
NbvtalkatbzaonencryptionpuzzlesNbvtalkatbzaonencryptionpuzzles
Nbvtalkatbzaonencryptionpuzzles
 
Nbvtalkatbzaonencryptionpuzzles
NbvtalkatbzaonencryptionpuzzlesNbvtalkatbzaonencryptionpuzzles
Nbvtalkatbzaonencryptionpuzzles
 
Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)
 
DAA-Divide and Conquer methodology, DAA 2024
DAA-Divide and Conquer methodology, DAA 2024DAA-Divide and Conquer methodology, DAA 2024
DAA-Divide and Conquer methodology, DAA 2024
 

Mais de Munhchimeg (20)

Ded algorithm1
Ded algorithm1Ded algorithm1
Ded algorithm1
 
Ded algorithm
Ded algorithmDed algorithm
Ded algorithm
 
Tobch lecture1
Tobch lecture1Tobch lecture1
Tobch lecture1
 
Recursive
RecursiveRecursive
Recursive
 
Lecture916
Lecture916Lecture916
Lecture916
 
Lecture915
Lecture915Lecture915
Lecture915
 
Lecture914
Lecture914Lecture914
Lecture914
 
Lecture913
Lecture913Lecture913
Lecture913
 
Lecture912
Lecture912Lecture912
Lecture912
 
Lecture910
Lecture910Lecture910
Lecture910
 
Lecture9
Lecture9Lecture9
Lecture9
 
Lecture8
Lecture8Lecture8
Lecture8
 
Lecture7
Lecture7Lecture7
Lecture7
 
Lecture6
Lecture6Lecture6
Lecture6
 
Lecture5
Lecture5Lecture5
Lecture5
 
Lecture4
Lecture4Lecture4
Lecture4
 
Lecture3
Lecture3Lecture3
Lecture3
 
Protsesor
ProtsesorProtsesor
Protsesor
 
Pm104 2004 2005
Pm104 2004 2005Pm104 2004 2005
Pm104 2004 2005
 
Lecture916
Lecture916Lecture916
Lecture916
 

Último

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

Chap05alg

  • 1. CHAPTER 5 Divide and Conquer
  • 2. Algorithm 5.1.4 Tiling a Deficient Board with Trominoes This algorithm constructs a tiling by trominoes of a deficient n × n board where n is a power of 2.
  • 3. Input Parameters: n , a power of 2 (the board size); the location L of the missing square Output Parameters: None tile ( n , L ) { if ( n == 2) { // the board is a right tromino T tile with T return } divide the board into four n /2 × n /2 subboards place one tromino as in Figure 5.1.4(b) // each of the 1 × 1 squares in this tromino // is considered as missing let m 1 , m 2 , m 3 , m 4 be the locations of the missing squares tile( n /2, m 1 ) tile( n /2, m 2 ) tile( n /2, m 3 ) tile( n /2, m 4 ) }
  • 4. Algorithm 5.2.2 Merge This algorithm receives as input indexes i , m , and j , and an array a , where a [ i ], ... , a [ m ] and a [ m +1], ... , a [ j ] are each sorted in nondecreasing order. These two nondecreasing subarrays are merged into a single nondecreasing array.
  • 5. Input Parameters: a , i , m , j Output Parameter: a merge ( a , i , m , j ) { p = i // index in a [ i ], ... , a [ m ] q = m + 1 // index in a [ m + 1], ... , a [ j ] r = i // index in a local array c while ( p ≤ m && q ≤ j ) { // copy smaller value to c if ( a [ p ] ≤ a [ q ]) { c [ r ] = a [ p ] p = p + 1 } else { c [ r ] = a [ q ] q = q + 1 } r = r + 1 } ...
  • 6. ... // copy remainder, if any, of first subarray to c while ( p ≤ m ) { c [ r ] = a [ p ] p = p + 1 r = r + 1 } // copy remainder, if any, of second subarray to c while ( q ≤ j ) { c [ r ] = a [ q ] q = q + 1 r = r + 1 } // copy c back to a for r = i to j a [ r ] = c [ r ] }
  • 7. Algorithm 5.2.3 Mergesort This algorithm sorts the array a [ i ], ... , a [ j ] in nondecreasing order. It uses the merge algorithm (Algorithm 5.2.2). Input Parameters: a , i , j Output Parameter: a mergesort ( a , i , j ) { // if only one element, just return if ( i == j ) return // divide a into two nearly equal parts m = ( i + j )/2 // sort each half mergesort ( a , i , m ) mergesort ( a , m + 1, j ) // merge the two sorted halves merge ( a , i , m , j ) }
  • 8. Algorithm 5.3.2 Finding the Distance Between a Closest Pair of Points This algorithm finds the distance between a closest pair of points. The input is an array p [1], ... , p [ n ] of n = 2 points. If p is a point, p . x is the x - coordinate of p , and p . y is the y -coordinate of p . The function merge is Algorithm 5.2.2 and mergesort is Algorithm 5.2.3. The function merge uses as the key the y -coordinate of the point. The function mergesort uses as the key either the x - or y -coordinate of the point; the comments indicate which. The function dist ( p , q ) returns the Euclidean distance between points p and q .
  • 9. Input Parameters: p Output Parameter: None closest_pair ( p ) { n = p . last mergesort ( p ,1, n ) // sort by x-coordinate return rec_cl_pair ( p ,1, n ) } // rec_cl_pair assumes that input is sorted by x -coordinate. // At termination, the input is sorted by y -coordinate. rec_cl_pair ( p , i , j ) { if ( j - i < 3) { mergesort ( p , i , j ) // sort by y -coordinate // find the distance delta between a closest pair delta = dist ( p [ i ], p [ i + 1]) if ( j - i == 1) // two points return delta // three points if ( dist ( p [ i + 1], p [ i + 2]) < delta ) delta = dist ( p [ i + 1], p [ i + 2]) if ( dist ( p [ i ], p [ i + 2]) < delta ) delta = dist ( p [ i ], p [ i + 2]) return delta } ...
  • 10. ... k = ( i + j )/ 2 l = p [ k ]. x deltaL = rec_cl_pair ( p , i , k ) deltaR = rec_cl_pair ( p , k + 1, j ) delta = min ( deltaL , deltaR ) // p [ i ], ... , p [ k ] is now sorted by y -coordinate, and // p [ k + 1], ... , p [ j ] is now sorted by y -coordinate. merge ( p , i , k , j ) // p [ i ], ... , p [ j ] is now sorted by y -coordinate. // store points in the vertical strip in v . t = 0 for k = i to j if ( p [ k ]. x > l - delta && p [ k ]. x < l + delta ) { t = t + 1 v [ t ] = p [ k ] } // look for closer pairs in the strip by comparing // each point in the strip to the next 7 points. for k = 1 to t - 1 for s = k + 1 to min ( t , k + 7) delta = min ( delta , dist ( v [ k ], v [ s ])) return delta }
  • 11. Algorithm 5.4.1 Matrix Product This algorithm computes the product C of the n × n matrices A and B directly from the definition of the matrix product. Input Parameters: A , B Output Parameter: C matrix_product ( A , B , C ) { n = A . last for i = 1 to n for j = 1 to n { C [ i ][ j ] = 0 for k = 1 to n C [ i ][ j ] = C [ i ][ j ] + A [ i ][ k ] * B [ k ][ j ] } }