SlideShare a Scribd company logo
C++ Programming
Given:
Write a closest Pair Function:
Deliverables
ClosestPair.h
ClosestPair.cpp
Solution
code:
Pair Closest_Pair( Point P[ ], int n)
{
float min = FLT_MAX;
int indexone=0;
int indextwo=0;
for (int i = 0; i < n; ++i)
for (int j = i+1; j < n; ++j)
if (dist(P[i], P[j]) < min)
{
min = dist(P[i], P[j]);
indexone=i;
indextwo=j;
}
Struct Pair st ;
st.indexPointOne = indexone;
st.indexPointTwo = indextwo;
return min;
}
float dist(Point p1, Point p2)
{
return sqrt( (p1.x - p2.x)*(p1.x - p2.x) +
(p1.y - p2.y)*(p1.y - p2.y)
);
}

More Related Content

More from footworld1

You get a call from a customer who reinstalled Windows on his comput.pdf
You get a call from a customer who reinstalled Windows on his comput.pdfYou get a call from a customer who reinstalled Windows on his comput.pdf
You get a call from a customer who reinstalled Windows on his comput.pdf
footworld1
 
Write a program to decipher messages encoded using a prefix code, gi.pdf
Write a program to decipher messages encoded using a prefix code, gi.pdfWrite a program to decipher messages encoded using a prefix code, gi.pdf
Write a program to decipher messages encoded using a prefix code, gi.pdf
footworld1
 
Write a class ArrayList that represents an array of integers. Init.pdf
Write a class ArrayList that represents an array of integers. Init.pdfWrite a class ArrayList that represents an array of integers. Init.pdf
Write a class ArrayList that represents an array of integers. Init.pdf
footworld1
 
What is heartwood What is sapwood What is the most abundant tissu.pdf
What is heartwood  What is sapwood  What is the most abundant tissu.pdfWhat is heartwood  What is sapwood  What is the most abundant tissu.pdf
What is heartwood What is sapwood What is the most abundant tissu.pdf
footworld1
 
Use arrays to store data for analysis. Use functions to perform the .pdf
Use arrays to store data for analysis. Use functions to perform the .pdfUse arrays to store data for analysis. Use functions to perform the .pdf
Use arrays to store data for analysis. Use functions to perform the .pdf
footworld1
 
The “Tripwire” system calculates all the hashes for all executable f.pdf
The “Tripwire” system calculates all the hashes for all executable f.pdfThe “Tripwire” system calculates all the hashes for all executable f.pdf
The “Tripwire” system calculates all the hashes for all executable f.pdf
footworld1
 
I have the first program completed (not how request, but it works) a.pdf
I have the first program completed (not how request, but it works) a.pdfI have the first program completed (not how request, but it works) a.pdf
I have the first program completed (not how request, but it works) a.pdf
footworld1
 

More from footworld1 (20)

You get a call from a customer who reinstalled Windows on his comput.pdf
You get a call from a customer who reinstalled Windows on his comput.pdfYou get a call from a customer who reinstalled Windows on his comput.pdf
You get a call from a customer who reinstalled Windows on his comput.pdf
 
You are running the Windows installation setup for Windows 7 on a co.pdf
You are running the Windows installation setup for Windows 7 on a co.pdfYou are running the Windows installation setup for Windows 7 on a co.pdf
You are running the Windows installation setup for Windows 7 on a co.pdf
 
Write a program to decipher messages encoded using a prefix code, gi.pdf
Write a program to decipher messages encoded using a prefix code, gi.pdfWrite a program to decipher messages encoded using a prefix code, gi.pdf
Write a program to decipher messages encoded using a prefix code, gi.pdf
 
With the biological species concept, the process of speciation is fre.pdf
With the biological species concept, the process of speciation is fre.pdfWith the biological species concept, the process of speciation is fre.pdf
With the biological species concept, the process of speciation is fre.pdf
 
Write a class ArrayList that represents an array of integers. Init.pdf
Write a class ArrayList that represents an array of integers. Init.pdfWrite a class ArrayList that represents an array of integers. Init.pdf
Write a class ArrayList that represents an array of integers. Init.pdf
 
what is the relationship between lnx and 1xSolutionThe relat.pdf
what is the relationship between lnx and 1xSolutionThe relat.pdfwhat is the relationship between lnx and 1xSolutionThe relat.pdf
what is the relationship between lnx and 1xSolutionThe relat.pdf
 
Which of these conclusions is supported by plant phylogenies (evolut.pdf
Which of these conclusions is supported by plant phylogenies (evolut.pdfWhich of these conclusions is supported by plant phylogenies (evolut.pdf
Which of these conclusions is supported by plant phylogenies (evolut.pdf
 
Who are some other individuals who might want to use the informa.pdf
Who are some other individuals who might want to use the informa.pdfWho are some other individuals who might want to use the informa.pdf
Who are some other individuals who might want to use the informa.pdf
 
Which account below is not a subdivision of owners equityAccumu.pdf
Which account below is not a subdivision of owners equityAccumu.pdfWhich account below is not a subdivision of owners equityAccumu.pdf
Which account below is not a subdivision of owners equityAccumu.pdf
 
What is the nucleoid region of a prokaryotic cell a membrane bound .pdf
What is the nucleoid region of a prokaryotic cell  a membrane bound .pdfWhat is the nucleoid region of a prokaryotic cell  a membrane bound .pdf
What is the nucleoid region of a prokaryotic cell a membrane bound .pdf
 
What is heartwood What is sapwood What is the most abundant tissu.pdf
What is heartwood  What is sapwood  What is the most abundant tissu.pdfWhat is heartwood  What is sapwood  What is the most abundant tissu.pdf
What is heartwood What is sapwood What is the most abundant tissu.pdf
 
Use arrays to store data for analysis. Use functions to perform the .pdf
Use arrays to store data for analysis. Use functions to perform the .pdfUse arrays to store data for analysis. Use functions to perform the .pdf
Use arrays to store data for analysis. Use functions to perform the .pdf
 
Using a telephone survey, a team of sociologists collect data on edu.pdf
Using a telephone survey, a team of sociologists collect data on edu.pdfUsing a telephone survey, a team of sociologists collect data on edu.pdf
Using a telephone survey, a team of sociologists collect data on edu.pdf
 
The “Tripwire” system calculates all the hashes for all executable f.pdf
The “Tripwire” system calculates all the hashes for all executable f.pdfThe “Tripwire” system calculates all the hashes for all executable f.pdf
The “Tripwire” system calculates all the hashes for all executable f.pdf
 
The archaeal RNA viruses described in the introduction were single-s.pdf
The archaeal RNA viruses described in the introduction were single-s.pdfThe archaeal RNA viruses described in the introduction were single-s.pdf
The archaeal RNA viruses described in the introduction were single-s.pdf
 
propose 3 key word centered on the topic which will make the basis o.pdf
propose 3 key word centered on the topic which will make the basis o.pdfpropose 3 key word centered on the topic which will make the basis o.pdf
propose 3 key word centered on the topic which will make the basis o.pdf
 
Molecular clock studies by Sarich and Wilson have suggested that .pdf
Molecular clock studies by Sarich and Wilson have suggested that .pdfMolecular clock studies by Sarich and Wilson have suggested that .pdf
Molecular clock studies by Sarich and Wilson have suggested that .pdf
 
Limestone rocks, coral reefs, and forests are examples of Select one.pdf
Limestone rocks, coral reefs, and forests are examples of  Select one.pdfLimestone rocks, coral reefs, and forests are examples of  Select one.pdf
Limestone rocks, coral reefs, and forests are examples of Select one.pdf
 
I have the first program completed (not how request, but it works) a.pdf
I have the first program completed (not how request, but it works) a.pdfI have the first program completed (not how request, but it works) a.pdf
I have the first program completed (not how request, but it works) a.pdf
 
How does chemotherapy function as a cancer treatmentA.It kills ce.pdf
How does chemotherapy function as a cancer treatmentA.It kills ce.pdfHow does chemotherapy function as a cancer treatmentA.It kills ce.pdf
How does chemotherapy function as a cancer treatmentA.It kills ce.pdf
 

Recently uploaded

Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 

Recently uploaded (20)

Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
NLC-2024-Orientation-for-RO-SDO (1).pptx
NLC-2024-Orientation-for-RO-SDO (1).pptxNLC-2024-Orientation-for-RO-SDO (1).pptx
NLC-2024-Orientation-for-RO-SDO (1).pptx
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
Operations Management - Book1.p  - Dr. Abdulfatah A. SalemOperations Management - Book1.p  - Dr. Abdulfatah A. Salem
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
 
2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx
 
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
 
Forest and Wildlife Resources Class 10 Free Study Material PDF
Forest and Wildlife Resources Class 10 Free Study Material PDFForest and Wildlife Resources Class 10 Free Study Material PDF
Forest and Wildlife Resources Class 10 Free Study Material PDF
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Benefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational ResourcesBenefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational Resources
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
 

C++ ProgrammingGivenWrite a closest Pair FunctionDeliverable.pdf

  • 1. C++ Programming Given: Write a closest Pair Function: Deliverables ClosestPair.h ClosestPair.cpp Solution code: Pair Closest_Pair( Point P[ ], int n) { float min = FLT_MAX; int indexone=0; int indextwo=0; for (int i = 0; i < n; ++i) for (int j = i+1; j < n; ++j) if (dist(P[i], P[j]) < min) { min = dist(P[i], P[j]); indexone=i; indextwo=j; } Struct Pair st ; st.indexPointOne = indexone; st.indexPointTwo = indextwo; return min; } float dist(Point p1, Point p2) { return sqrt( (p1.x - p2.x)*(p1.x - p2.x) + (p1.y - p2.y)*(p1.y - p2.y) ); }