SlideShare a Scribd company logo
USING JAVA:
Implement the quicksort optimization median-of-three, i.e., first, middle, and last, as pivot for
partition. Into this working quicksort algorithm: ( the spacing is bad, sorry)
private static void quicksort(int low, int high) {
int i = low, j = high;
// Get the pivot element from the middle of the list
int pivot = arr[(high+low)/2];
// Divide into two lists
while (i <= j) {
// If the current value from the left list is smaller then the pivot
// element then get the next element from the left list
while (arr[i] < pivot) i++;
// If the current value from the right list is larger then the pivot
// element then get the next element from the right list
while (arr[j] > pivot) j--;
// If we have found a value in the left list which is larger than
// the pivot element and if we have found a value in the right list
// which is smaller then the pivot element then we exchange the
// values.
// As we are done we can increase i and j
if (i < j) {
exchange(i, j);
i++;
j--;
} else if (i == j) { i++; j--; }
}
// Recursion
if (low < j)
quicksort(low, j);
if (i < high)
quicksort(i, high);
}
Solution
Hi, Please find my program:
private static void quicksort(int low, int high) {
if (low >= high)
return;
// Selecting the pivot
int first = low;
int second = arr[(high+low)/2];
int third = arr[high];
// median for first three
int pivot = Math.max(
Math.min(
array[first],
array[second]),
Math.min(
Math.max(
array[first],
array[second]
),
array[third]
)
);
while (low <= high)
{
while (array[low] < pivot)
{
low++;
}
while (array[high] > pivot)
{
high--;
}
if (low <= high)
{
// swapping
int temp = array[low];
array[low] = array[high];
array[high] = temp;
low++;
high--;
}
}
// Recursion
if (low < j)
quicksort(low, j);
if (i < high)
quicksort(i, high);
}

More Related Content

More from info785431

Carbon dioxide (CO_2) is a non-polar molecule. Is this consistent wit.pdf
Carbon dioxide (CO_2) is a non-polar molecule. Is this consistent wit.pdfCarbon dioxide (CO_2) is a non-polar molecule. Is this consistent wit.pdf
Carbon dioxide (CO_2) is a non-polar molecule. Is this consistent wit.pdf
info785431
 
Compare and contrast the messages about science and integrity in Fra.pdf
Compare and contrast the messages about science and integrity in Fra.pdfCompare and contrast the messages about science and integrity in Fra.pdf
Compare and contrast the messages about science and integrity in Fra.pdf
info785431
 
Briely, what was Darwins explanation for the appearance of design.pdf
Briely, what was Darwins explanation for the appearance of design.pdfBriely, what was Darwins explanation for the appearance of design.pdf
Briely, what was Darwins explanation for the appearance of design.pdf
info785431
 
A router receives a message addressed 172.16.15.75. The relevant rou.pdf
A router receives a message addressed 172.16.15.75. The relevant rou.pdfA router receives a message addressed 172.16.15.75. The relevant rou.pdf
A router receives a message addressed 172.16.15.75. The relevant rou.pdf
info785431
 
A study of sandflies in Panama classified flies caught in light traps.pdf
A study of sandflies in Panama classified flies caught in light traps.pdfA study of sandflies in Panama classified flies caught in light traps.pdf
A study of sandflies in Panama classified flies caught in light traps.pdf
info785431
 
___Tissue found in the brain, spinal cord, and peripheral nerves. The.pdf
___Tissue found in the brain, spinal cord, and peripheral nerves. The.pdf___Tissue found in the brain, spinal cord, and peripheral nerves. The.pdf
___Tissue found in the brain, spinal cord, and peripheral nerves. The.pdf
info785431
 
You have been exposed to each of the 8 microbes below. One of them h.pdf
You have been exposed to each of the 8 microbes below. One of them h.pdfYou have been exposed to each of the 8 microbes below. One of them h.pdf
You have been exposed to each of the 8 microbes below. One of them h.pdf
info785431
 
Write a snippet of C code that will enable the ADC to continuously r.pdf
Write a snippet of C code that will enable the ADC to continuously r.pdfWrite a snippet of C code that will enable the ADC to continuously r.pdf
Write a snippet of C code that will enable the ADC to continuously r.pdf
info785431
 
Write a JAVA LinkedListRec class that has the following methods siz.pdf
Write a JAVA LinkedListRec class that has the following methods siz.pdfWrite a JAVA LinkedListRec class that has the following methods siz.pdf
Write a JAVA LinkedListRec class that has the following methods siz.pdf
info785431
 
Write a BFS algorithm using only arrays and no other data structure..pdf
Write a BFS algorithm using only arrays and no other data structure..pdfWrite a BFS algorithm using only arrays and no other data structure..pdf
Write a BFS algorithm using only arrays and no other data structure..pdf
info785431
 
Why has one prominent textbook author described IO management as the.pdf
Why has one prominent textbook author described IO management as the.pdfWhy has one prominent textbook author described IO management as the.pdf
Why has one prominent textbook author described IO management as the.pdf
info785431
 
which is true of the data shown in the histogram Which is true of th.pdf
which is true of the data shown in the histogram Which is true of th.pdfwhich is true of the data shown in the histogram Which is true of th.pdf
which is true of the data shown in the histogram Which is true of th.pdf
info785431
 
What is the value of studying humanities in a business or technical .pdf
What is the value of studying humanities in a business or technical .pdfWhat is the value of studying humanities in a business or technical .pdf
What is the value of studying humanities in a business or technical .pdf
info785431
 
What are the two components of dynamic pressureVelocity and densi.pdf
What are the two components of dynamic pressureVelocity and densi.pdfWhat are the two components of dynamic pressureVelocity and densi.pdf
What are the two components of dynamic pressureVelocity and densi.pdf
info785431
 
There are 40 students in our class. How many ways they can be lined .pdf
There are 40 students in our class. How many ways they can be lined .pdfThere are 40 students in our class. How many ways they can be lined .pdf
There are 40 students in our class. How many ways they can be lined .pdf
info785431
 
The Task For this assignment you will write a rudimentary text edi.pdf
The Task For this assignment you will write a rudimentary text edi.pdfThe Task For this assignment you will write a rudimentary text edi.pdf
The Task For this assignment you will write a rudimentary text edi.pdf
info785431
 
The SIP handles what functionsA.) establishes a call through the .pdf
The SIP handles what functionsA.) establishes a call through the .pdfThe SIP handles what functionsA.) establishes a call through the .pdf
The SIP handles what functionsA.) establishes a call through the .pdf
info785431
 
The NBA decides to look into the use of meldonium in the league foll.pdf
The NBA decides to look into the use of meldonium in the league foll.pdfThe NBA decides to look into the use of meldonium in the league foll.pdf
The NBA decides to look into the use of meldonium in the league foll.pdf
info785431
 
The organelle that serves as the digestive system in the cell is the .pdf
The organelle that serves as the digestive system in the cell is the .pdfThe organelle that serves as the digestive system in the cell is the .pdf
The organelle that serves as the digestive system in the cell is the .pdf
info785431
 
The major type of interactive forces between molecules of NH_3 are .pdf
The major type of interactive forces between molecules of NH_3 are  .pdfThe major type of interactive forces between molecules of NH_3 are  .pdf
The major type of interactive forces between molecules of NH_3 are .pdf
info785431
 

More from info785431 (20)

Carbon dioxide (CO_2) is a non-polar molecule. Is this consistent wit.pdf
Carbon dioxide (CO_2) is a non-polar molecule. Is this consistent wit.pdfCarbon dioxide (CO_2) is a non-polar molecule. Is this consistent wit.pdf
Carbon dioxide (CO_2) is a non-polar molecule. Is this consistent wit.pdf
 
Compare and contrast the messages about science and integrity in Fra.pdf
Compare and contrast the messages about science and integrity in Fra.pdfCompare and contrast the messages about science and integrity in Fra.pdf
Compare and contrast the messages about science and integrity in Fra.pdf
 
Briely, what was Darwins explanation for the appearance of design.pdf
Briely, what was Darwins explanation for the appearance of design.pdfBriely, what was Darwins explanation for the appearance of design.pdf
Briely, what was Darwins explanation for the appearance of design.pdf
 
A router receives a message addressed 172.16.15.75. The relevant rou.pdf
A router receives a message addressed 172.16.15.75. The relevant rou.pdfA router receives a message addressed 172.16.15.75. The relevant rou.pdf
A router receives a message addressed 172.16.15.75. The relevant rou.pdf
 
A study of sandflies in Panama classified flies caught in light traps.pdf
A study of sandflies in Panama classified flies caught in light traps.pdfA study of sandflies in Panama classified flies caught in light traps.pdf
A study of sandflies in Panama classified flies caught in light traps.pdf
 
___Tissue found in the brain, spinal cord, and peripheral nerves. The.pdf
___Tissue found in the brain, spinal cord, and peripheral nerves. The.pdf___Tissue found in the brain, spinal cord, and peripheral nerves. The.pdf
___Tissue found in the brain, spinal cord, and peripheral nerves. The.pdf
 
You have been exposed to each of the 8 microbes below. One of them h.pdf
You have been exposed to each of the 8 microbes below. One of them h.pdfYou have been exposed to each of the 8 microbes below. One of them h.pdf
You have been exposed to each of the 8 microbes below. One of them h.pdf
 
Write a snippet of C code that will enable the ADC to continuously r.pdf
Write a snippet of C code that will enable the ADC to continuously r.pdfWrite a snippet of C code that will enable the ADC to continuously r.pdf
Write a snippet of C code that will enable the ADC to continuously r.pdf
 
Write a JAVA LinkedListRec class that has the following methods siz.pdf
Write a JAVA LinkedListRec class that has the following methods siz.pdfWrite a JAVA LinkedListRec class that has the following methods siz.pdf
Write a JAVA LinkedListRec class that has the following methods siz.pdf
 
Write a BFS algorithm using only arrays and no other data structure..pdf
Write a BFS algorithm using only arrays and no other data structure..pdfWrite a BFS algorithm using only arrays and no other data structure..pdf
Write a BFS algorithm using only arrays and no other data structure..pdf
 
Why has one prominent textbook author described IO management as the.pdf
Why has one prominent textbook author described IO management as the.pdfWhy has one prominent textbook author described IO management as the.pdf
Why has one prominent textbook author described IO management as the.pdf
 
which is true of the data shown in the histogram Which is true of th.pdf
which is true of the data shown in the histogram Which is true of th.pdfwhich is true of the data shown in the histogram Which is true of th.pdf
which is true of the data shown in the histogram Which is true of th.pdf
 
What is the value of studying humanities in a business or technical .pdf
What is the value of studying humanities in a business or technical .pdfWhat is the value of studying humanities in a business or technical .pdf
What is the value of studying humanities in a business or technical .pdf
 
What are the two components of dynamic pressureVelocity and densi.pdf
What are the two components of dynamic pressureVelocity and densi.pdfWhat are the two components of dynamic pressureVelocity and densi.pdf
What are the two components of dynamic pressureVelocity and densi.pdf
 
There are 40 students in our class. How many ways they can be lined .pdf
There are 40 students in our class. How many ways they can be lined .pdfThere are 40 students in our class. How many ways they can be lined .pdf
There are 40 students in our class. How many ways they can be lined .pdf
 
The Task For this assignment you will write a rudimentary text edi.pdf
The Task For this assignment you will write a rudimentary text edi.pdfThe Task For this assignment you will write a rudimentary text edi.pdf
The Task For this assignment you will write a rudimentary text edi.pdf
 
The SIP handles what functionsA.) establishes a call through the .pdf
The SIP handles what functionsA.) establishes a call through the .pdfThe SIP handles what functionsA.) establishes a call through the .pdf
The SIP handles what functionsA.) establishes a call through the .pdf
 
The NBA decides to look into the use of meldonium in the league foll.pdf
The NBA decides to look into the use of meldonium in the league foll.pdfThe NBA decides to look into the use of meldonium in the league foll.pdf
The NBA decides to look into the use of meldonium in the league foll.pdf
 
The organelle that serves as the digestive system in the cell is the .pdf
The organelle that serves as the digestive system in the cell is the .pdfThe organelle that serves as the digestive system in the cell is the .pdf
The organelle that serves as the digestive system in the cell is the .pdf
 
The major type of interactive forces between molecules of NH_3 are .pdf
The major type of interactive forces between molecules of NH_3 are  .pdfThe major type of interactive forces between molecules of NH_3 are  .pdf
The major type of interactive forces between molecules of NH_3 are .pdf
 

Recently uploaded

BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
Nguyen Thanh Tu Collection
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
imrankhan141184
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
EduSkills OECD
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
siemaillard
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
ssuser13ffe4
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
haiqairshad
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
Solutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptxSolutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptx
spdendr
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
MysoreMuleSoftMeetup
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
สมใจ จันสุกสี
 
B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
BoudhayanBhattachari
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 

Recently uploaded (20)

BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
Solutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptxSolutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptx
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
 
B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 

USING JAVAImplement the quicksort optimization median-of-three, i.pdf

  • 1. USING JAVA: Implement the quicksort optimization median-of-three, i.e., first, middle, and last, as pivot for partition. Into this working quicksort algorithm: ( the spacing is bad, sorry) private static void quicksort(int low, int high) { int i = low, j = high; // Get the pivot element from the middle of the list int pivot = arr[(high+low)/2]; // Divide into two lists while (i <= j) { // If the current value from the left list is smaller then the pivot // element then get the next element from the left list while (arr[i] < pivot) i++; // If the current value from the right list is larger then the pivot // element then get the next element from the right list while (arr[j] > pivot) j--; // If we have found a value in the left list which is larger than // the pivot element and if we have found a value in the right list // which is smaller then the pivot element then we exchange the // values. // As we are done we can increase i and j if (i < j) { exchange(i, j); i++; j--; } else if (i == j) { i++; j--; } } // Recursion if (low < j) quicksort(low, j); if (i < high) quicksort(i, high); } Solution
  • 2. Hi, Please find my program: private static void quicksort(int low, int high) { if (low >= high) return; // Selecting the pivot int first = low; int second = arr[(high+low)/2]; int third = arr[high]; // median for first three int pivot = Math.max( Math.min( array[first], array[second]), Math.min( Math.max( array[first], array[second] ), array[third] ) ); while (low <= high) { while (array[low] < pivot) { low++; } while (array[high] > pivot) { high--; } if (low <= high) { // swapping int temp = array[low];
  • 3. array[low] = array[high]; array[high] = temp; low++; high--; } } // Recursion if (low < j) quicksort(low, j); if (i < high) quicksort(i, high); }