SlideShare uma empresa Scribd logo
Ineed this in python. Thank you
Modify the merge sort algorithm to sort a list in descending order.
Solution
#! /usr/bin/python
def Merge(Array, firstStart, firstEnd, secondEnd):
n1 = firstEnd - firstStart + 1
n2 = secondEnd = firstEnd
Temp1 = [None] * n1
Temp2 = [None] * n2
for i in range(n1):
Temp1[i] = Array[firstStart + i]
for i in range(n2):
Temp2[i] = Array[firstEnd + i + 1]
i = 0
j = 0
for k in range(firstStart, secondEnd):
if Temp1[i] >= Temp2[j]:
Array[k] = Temp1[i]
i = i + 1
else:
Array[k] = Temp2[j]
j = j + 1
return Array
def MergeSort(Array, left, right):
if left < right:
mid = (left + right) / 2
MergeSort(Array, left, mid)
MergeSort(Array, mid+1, right)
Merge(Array, left, mid, right)
Array  = [10, 30, 40, 80, 20, 70, 90, 60, 50]
MergeSort(Array, 0, 8)
print Array

Mais conteúdo relacionado

Mais de rtodd972

In the Lewis structures listed below- M and X represent various elemen.docx
In the Lewis structures listed below- M and X represent various elemen.docxIn the Lewis structures listed below- M and X represent various elemen.docx
In the Lewis structures listed below- M and X represent various elemen.docx
rtodd972
 
In the independent data marts architecture- the independent data marts.docx
In the independent data marts architecture- the independent data marts.docxIn the independent data marts architecture- the independent data marts.docx
In the independent data marts architecture- the independent data marts.docx
rtodd972
 
iron (III) chloride + sodium thiosulfate - write the half reactions an.docx
iron (III) chloride + sodium thiosulfate - write the half reactions an.docxiron (III) chloride + sodium thiosulfate - write the half reactions an.docx
iron (III) chloride + sodium thiosulfate - write the half reactions an.docx
rtodd972
 
It has been said that the advantage that leading-edge retailers such a.docx
It has been said that the advantage that leading-edge retailers such a.docxIt has been said that the advantage that leading-edge retailers such a.docx
It has been said that the advantage that leading-edge retailers such a.docx
rtodd972
 
ISP who has allowed them the use of 4 externally routable IP addresses.docx
ISP who has allowed them the use of 4 externally routable IP addresses.docxISP who has allowed them the use of 4 externally routable IP addresses.docx
ISP who has allowed them the use of 4 externally routable IP addresses.docx
rtodd972
 
Is TOD a input or output-- Is this correct--- Inputs- start- stop- fl.docx
Is TOD a input or output--  Is this correct--- Inputs- start- stop- fl.docxIs TOD a input or output--  Is this correct--- Inputs- start- stop- fl.docx
Is TOD a input or output-- Is this correct--- Inputs- start- stop- fl.docx
rtodd972
 
Is there a universal code for ethical business behavior- (Check the De.docx
Is there a universal code for ethical business behavior- (Check the De.docxIs there a universal code for ethical business behavior- (Check the De.docx
Is there a universal code for ethical business behavior- (Check the De.docx
rtodd972
 
In the following search function for a linked list (using the Node and.docx
In the following search function for a linked list (using the Node and.docxIn the following search function for a linked list (using the Node and.docx
In the following search function for a linked list (using the Node and.docx
rtodd972
 
Is it easier to perform a computer forensic investigation if the suspe.docx
Is it easier to perform a computer forensic investigation if the suspe.docxIs it easier to perform a computer forensic investigation if the suspe.docx
Is it easier to perform a computer forensic investigation if the suspe.docx
rtodd972
 
Is a public park considered to be a public good- Why or why not-Soluti.docx
Is a public park considered to be a public good- Why or why not-Soluti.docxIs a public park considered to be a public good- Why or why not-Soluti.docx
Is a public park considered to be a public good- Why or why not-Soluti.docx
rtodd972
 
Is a firm-'s 10-K an unbiased perspective on its strengths and weaknes.docx
Is a firm-'s 10-K an unbiased perspective on its strengths and weaknes.docxIs a firm-'s 10-K an unbiased perspective on its strengths and weaknes.docx
Is a firm-'s 10-K an unbiased perspective on its strengths and weaknes.docx
rtodd972
 
Iron(II) ion reacts with water to a small extent by a hydrolysis react.docx
Iron(II) ion reacts with water to a small extent by a hydrolysis react.docxIron(II) ion reacts with water to a small extent by a hydrolysis react.docx
Iron(II) ion reacts with water to a small extent by a hydrolysis react.docx
rtodd972
 
Investors require a 17- rate of return on Levine Company-'s stock (tha.docx
Investors require a 17- rate of return on Levine Company-'s stock (tha.docxInvestors require a 17- rate of return on Levine Company-'s stock (tha.docx
Investors require a 17- rate of return on Levine Company-'s stock (tha.docx
rtodd972
 
ionic compounds crystallize in a cubic closest packed array of anions.docx
ionic compounds crystallize in a cubic closest packed array of anions.docxionic compounds crystallize in a cubic closest packed array of anions.docx
ionic compounds crystallize in a cubic closest packed array of anions.docx
rtodd972
 
Invoke Netbeans and create a project Exercise 7- Enter the following.docx
Invoke Netbeans and create a project Exercise 7-  Enter the following.docxInvoke Netbeans and create a project Exercise 7-  Enter the following.docx
Invoke Netbeans and create a project Exercise 7- Enter the following.docx
rtodd972
 
Investors and management use the statement of cash flows to evaluate a.docx
Investors and management use the statement of cash flows to evaluate a.docxInvestors and management use the statement of cash flows to evaluate a.docx
Investors and management use the statement of cash flows to evaluate a.docx
rtodd972
 
In the short run- what distinguishes liquidity from profitability- 1-.docx
In the short run- what distinguishes liquidity from profitability- 1-.docxIn the short run- what distinguishes liquidity from profitability- 1-.docx
In the short run- what distinguishes liquidity from profitability- 1-.docx
rtodd972
 

Mais de rtodd972 (17)

In the Lewis structures listed below- M and X represent various elemen.docx
In the Lewis structures listed below- M and X represent various elemen.docxIn the Lewis structures listed below- M and X represent various elemen.docx
In the Lewis structures listed below- M and X represent various elemen.docx
 
In the independent data marts architecture- the independent data marts.docx
In the independent data marts architecture- the independent data marts.docxIn the independent data marts architecture- the independent data marts.docx
In the independent data marts architecture- the independent data marts.docx
 
iron (III) chloride + sodium thiosulfate - write the half reactions an.docx
iron (III) chloride + sodium thiosulfate - write the half reactions an.docxiron (III) chloride + sodium thiosulfate - write the half reactions an.docx
iron (III) chloride + sodium thiosulfate - write the half reactions an.docx
 
It has been said that the advantage that leading-edge retailers such a.docx
It has been said that the advantage that leading-edge retailers such a.docxIt has been said that the advantage that leading-edge retailers such a.docx
It has been said that the advantage that leading-edge retailers such a.docx
 
ISP who has allowed them the use of 4 externally routable IP addresses.docx
ISP who has allowed them the use of 4 externally routable IP addresses.docxISP who has allowed them the use of 4 externally routable IP addresses.docx
ISP who has allowed them the use of 4 externally routable IP addresses.docx
 
Is TOD a input or output-- Is this correct--- Inputs- start- stop- fl.docx
Is TOD a input or output--  Is this correct--- Inputs- start- stop- fl.docxIs TOD a input or output--  Is this correct--- Inputs- start- stop- fl.docx
Is TOD a input or output-- Is this correct--- Inputs- start- stop- fl.docx
 
Is there a universal code for ethical business behavior- (Check the De.docx
Is there a universal code for ethical business behavior- (Check the De.docxIs there a universal code for ethical business behavior- (Check the De.docx
Is there a universal code for ethical business behavior- (Check the De.docx
 
In the following search function for a linked list (using the Node and.docx
In the following search function for a linked list (using the Node and.docxIn the following search function for a linked list (using the Node and.docx
In the following search function for a linked list (using the Node and.docx
 
Is it easier to perform a computer forensic investigation if the suspe.docx
Is it easier to perform a computer forensic investigation if the suspe.docxIs it easier to perform a computer forensic investigation if the suspe.docx
Is it easier to perform a computer forensic investigation if the suspe.docx
 
Is a public park considered to be a public good- Why or why not-Soluti.docx
Is a public park considered to be a public good- Why or why not-Soluti.docxIs a public park considered to be a public good- Why or why not-Soluti.docx
Is a public park considered to be a public good- Why or why not-Soluti.docx
 
Is a firm-'s 10-K an unbiased perspective on its strengths and weaknes.docx
Is a firm-'s 10-K an unbiased perspective on its strengths and weaknes.docxIs a firm-'s 10-K an unbiased perspective on its strengths and weaknes.docx
Is a firm-'s 10-K an unbiased perspective on its strengths and weaknes.docx
 
Iron(II) ion reacts with water to a small extent by a hydrolysis react.docx
Iron(II) ion reacts with water to a small extent by a hydrolysis react.docxIron(II) ion reacts with water to a small extent by a hydrolysis react.docx
Iron(II) ion reacts with water to a small extent by a hydrolysis react.docx
 
Investors require a 17- rate of return on Levine Company-'s stock (tha.docx
Investors require a 17- rate of return on Levine Company-'s stock (tha.docxInvestors require a 17- rate of return on Levine Company-'s stock (tha.docx
Investors require a 17- rate of return on Levine Company-'s stock (tha.docx
 
ionic compounds crystallize in a cubic closest packed array of anions.docx
ionic compounds crystallize in a cubic closest packed array of anions.docxionic compounds crystallize in a cubic closest packed array of anions.docx
ionic compounds crystallize in a cubic closest packed array of anions.docx
 
Invoke Netbeans and create a project Exercise 7- Enter the following.docx
Invoke Netbeans and create a project Exercise 7-  Enter the following.docxInvoke Netbeans and create a project Exercise 7-  Enter the following.docx
Invoke Netbeans and create a project Exercise 7- Enter the following.docx
 
Investors and management use the statement of cash flows to evaluate a.docx
Investors and management use the statement of cash flows to evaluate a.docxInvestors and management use the statement of cash flows to evaluate a.docx
Investors and management use the statement of cash flows to evaluate a.docx
 
In the short run- what distinguishes liquidity from profitability- 1-.docx
In the short run- what distinguishes liquidity from profitability- 1-.docxIn the short run- what distinguishes liquidity from profitability- 1-.docx
In the short run- what distinguishes liquidity from profitability- 1-.docx
 

Último

How to Manage Shipping Connectors & Shipping Methods in Odoo 17
How to Manage Shipping Connectors & Shipping Methods in Odoo 17How to Manage Shipping Connectors & Shipping Methods in Odoo 17
How to Manage Shipping Connectors & Shipping Methods in Odoo 17
Celine George
 
Our Guide to the July 2024 USPS® Rate Change
Our Guide to the July 2024 USPS® Rate ChangeOur Guide to the July 2024 USPS® Rate Change
Our Guide to the July 2024 USPS® Rate Change
Postal Advocate Inc.
 
E-learning Odoo 17 New features - Odoo 17 Slides
E-learning Odoo 17  New features - Odoo 17 SlidesE-learning Odoo 17  New features - Odoo 17 Slides
E-learning Odoo 17 New features - Odoo 17 Slides
Celine George
 
"DANH SÁCH THÍ SINH XÉT TUYỂN SỚM ĐỦ ĐIỀU KIỆN TRÚNG TUYỂN ĐẠI HỌC CHÍNH QUY ...
"DANH SÁCH THÍ SINH XÉT TUYỂN SỚM ĐỦ ĐIỀU KIỆN TRÚNG TUYỂN ĐẠI HỌC CHÍNH QUY ..."DANH SÁCH THÍ SINH XÉT TUYỂN SỚM ĐỦ ĐIỀU KIỆN TRÚNG TUYỂN ĐẠI HỌC CHÍNH QUY ...
"DANH SÁCH THÍ SINH XÉT TUYỂN SỚM ĐỦ ĐIỀU KIỆN TRÚNG TUYỂN ĐẠI HỌC CHÍNH QUY ...
thanhluan21
 
Odoo 17 Events - Attendees List Scanning
Odoo 17 Events - Attendees List ScanningOdoo 17 Events - Attendees List Scanning
Odoo 17 Events - Attendees List Scanning
Celine George
 
Benchmarking Sustainability: Neurosciences and AI Tech Research in Macau - Ke...
Benchmarking Sustainability: Neurosciences and AI Tech Research in Macau - Ke...Benchmarking Sustainability: Neurosciences and AI Tech Research in Macau - Ke...
Benchmarking Sustainability: Neurosciences and AI Tech Research in Macau - Ke...
Alvaro Barbosa
 
MVC Interview Questions PDF By ScholarHat
MVC Interview Questions PDF By ScholarHatMVC Interview Questions PDF By ScholarHat
MVC Interview Questions PDF By ScholarHat
Scholarhat
 
formative Evaluation By Dr.Kshirsagar R.V
formative Evaluation By Dr.Kshirsagar R.Vformative Evaluation By Dr.Kshirsagar R.V
formative Evaluation By Dr.Kshirsagar R.V
DrRavindrakshirsagar1
 
How to Manage Access Rights & User Types in Odoo 17
How to Manage Access Rights & User Types in Odoo 17How to Manage Access Rights & User Types in Odoo 17
How to Manage Access Rights & User Types in Odoo 17
Celine George
 
Mail Server Configuration Using App passwords in Odoo 17
Mail Server Configuration Using App passwords in Odoo 17Mail Server Configuration Using App passwords in Odoo 17
Mail Server Configuration Using App passwords in Odoo 17
Celine George
 
How to Add a Filter in the Odoo 17 - Odoo 17 Slides
How to Add a Filter in the Odoo 17 - Odoo 17 SlidesHow to Add a Filter in the Odoo 17 - Odoo 17 Slides
How to Add a Filter in the Odoo 17 - Odoo 17 Slides
Celine George
 
Node JS Interview Question PDF By ScholarHat
Node JS Interview Question PDF By ScholarHatNode JS Interview Question PDF By ScholarHat
Node JS Interview Question PDF By ScholarHat
Scholarhat
 
Power of Ignored Skills: Change the Way You Think and Decide by Manoj Tripathi
Power of Ignored Skills: Change the Way You Think and Decide by Manoj TripathiPower of Ignored Skills: Change the Way You Think and Decide by Manoj Tripathi
Power of Ignored Skills: Change the Way You Think and Decide by Manoj Tripathi
Pankaj523992
 
How to Manage Early Receipt Printing in Odoo 17 POS
How to Manage Early Receipt Printing in Odoo 17 POSHow to Manage Early Receipt Printing in Odoo 17 POS
How to Manage Early Receipt Printing in Odoo 17 POS
Celine George
 
ASP.NET Core Interview Questions PDF By ScholarHat.pdf
ASP.NET Core Interview Questions PDF By ScholarHat.pdfASP.NET Core Interview Questions PDF By ScholarHat.pdf
ASP.NET Core Interview Questions PDF By ScholarHat.pdf
Scholarhat
 
C# Interview Questions PDF By ScholarHat.pdf
C# Interview Questions PDF By ScholarHat.pdfC# Interview Questions PDF By ScholarHat.pdf
C# Interview Questions PDF By ScholarHat.pdf
Scholarhat
 
A beginner’s guide to project reviews - everything you wanted to know but wer...
A beginner’s guide to project reviews - everything you wanted to know but wer...A beginner’s guide to project reviews - everything you wanted to know but wer...
A beginner’s guide to project reviews - everything you wanted to know but wer...
Association for Project Management
 
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH LỚP 12 - GLOBAL SUCCESS - FORM MỚI 2025 - ...
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH LỚP 12 - GLOBAL SUCCESS - FORM MỚI 2025 - ...BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH LỚP 12 - GLOBAL SUCCESS - FORM MỚI 2025 - ...
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH LỚP 12 - GLOBAL SUCCESS - FORM MỚI 2025 - ...
Nguyen Thanh Tu Collection
 
Codeavour 5.0 International Impact Report - The Biggest International AI, Cod...
Codeavour 5.0 International Impact Report - The Biggest International AI, Cod...Codeavour 5.0 International Impact Report - The Biggest International AI, Cod...
Codeavour 5.0 International Impact Report - The Biggest International AI, Cod...
Codeavour International
 
How to Empty a One2Many Field in Odoo 17
How to Empty a One2Many Field in Odoo 17How to Empty a One2Many Field in Odoo 17
How to Empty a One2Many Field in Odoo 17
Celine George
 

Último (20)

How to Manage Shipping Connectors & Shipping Methods in Odoo 17
How to Manage Shipping Connectors & Shipping Methods in Odoo 17How to Manage Shipping Connectors & Shipping Methods in Odoo 17
How to Manage Shipping Connectors & Shipping Methods in Odoo 17
 
Our Guide to the July 2024 USPS® Rate Change
Our Guide to the July 2024 USPS® Rate ChangeOur Guide to the July 2024 USPS® Rate Change
Our Guide to the July 2024 USPS® Rate Change
 
E-learning Odoo 17 New features - Odoo 17 Slides
E-learning Odoo 17  New features - Odoo 17 SlidesE-learning Odoo 17  New features - Odoo 17 Slides
E-learning Odoo 17 New features - Odoo 17 Slides
 
"DANH SÁCH THÍ SINH XÉT TUYỂN SỚM ĐỦ ĐIỀU KIỆN TRÚNG TUYỂN ĐẠI HỌC CHÍNH QUY ...
"DANH SÁCH THÍ SINH XÉT TUYỂN SỚM ĐỦ ĐIỀU KIỆN TRÚNG TUYỂN ĐẠI HỌC CHÍNH QUY ..."DANH SÁCH THÍ SINH XÉT TUYỂN SỚM ĐỦ ĐIỀU KIỆN TRÚNG TUYỂN ĐẠI HỌC CHÍNH QUY ...
"DANH SÁCH THÍ SINH XÉT TUYỂN SỚM ĐỦ ĐIỀU KIỆN TRÚNG TUYỂN ĐẠI HỌC CHÍNH QUY ...
 
Odoo 17 Events - Attendees List Scanning
Odoo 17 Events - Attendees List ScanningOdoo 17 Events - Attendees List Scanning
Odoo 17 Events - Attendees List Scanning
 
Benchmarking Sustainability: Neurosciences and AI Tech Research in Macau - Ke...
Benchmarking Sustainability: Neurosciences and AI Tech Research in Macau - Ke...Benchmarking Sustainability: Neurosciences and AI Tech Research in Macau - Ke...
Benchmarking Sustainability: Neurosciences and AI Tech Research in Macau - Ke...
 
MVC Interview Questions PDF By ScholarHat
MVC Interview Questions PDF By ScholarHatMVC Interview Questions PDF By ScholarHat
MVC Interview Questions PDF By ScholarHat
 
formative Evaluation By Dr.Kshirsagar R.V
formative Evaluation By Dr.Kshirsagar R.Vformative Evaluation By Dr.Kshirsagar R.V
formative Evaluation By Dr.Kshirsagar R.V
 
How to Manage Access Rights & User Types in Odoo 17
How to Manage Access Rights & User Types in Odoo 17How to Manage Access Rights & User Types in Odoo 17
How to Manage Access Rights & User Types in Odoo 17
 
Mail Server Configuration Using App passwords in Odoo 17
Mail Server Configuration Using App passwords in Odoo 17Mail Server Configuration Using App passwords in Odoo 17
Mail Server Configuration Using App passwords in Odoo 17
 
How to Add a Filter in the Odoo 17 - Odoo 17 Slides
How to Add a Filter in the Odoo 17 - Odoo 17 SlidesHow to Add a Filter in the Odoo 17 - Odoo 17 Slides
How to Add a Filter in the Odoo 17 - Odoo 17 Slides
 
Node JS Interview Question PDF By ScholarHat
Node JS Interview Question PDF By ScholarHatNode JS Interview Question PDF By ScholarHat
Node JS Interview Question PDF By ScholarHat
 
Power of Ignored Skills: Change the Way You Think and Decide by Manoj Tripathi
Power of Ignored Skills: Change the Way You Think and Decide by Manoj TripathiPower of Ignored Skills: Change the Way You Think and Decide by Manoj Tripathi
Power of Ignored Skills: Change the Way You Think and Decide by Manoj Tripathi
 
How to Manage Early Receipt Printing in Odoo 17 POS
How to Manage Early Receipt Printing in Odoo 17 POSHow to Manage Early Receipt Printing in Odoo 17 POS
How to Manage Early Receipt Printing in Odoo 17 POS
 
ASP.NET Core Interview Questions PDF By ScholarHat.pdf
ASP.NET Core Interview Questions PDF By ScholarHat.pdfASP.NET Core Interview Questions PDF By ScholarHat.pdf
ASP.NET Core Interview Questions PDF By ScholarHat.pdf
 
C# Interview Questions PDF By ScholarHat.pdf
C# Interview Questions PDF By ScholarHat.pdfC# Interview Questions PDF By ScholarHat.pdf
C# Interview Questions PDF By ScholarHat.pdf
 
A beginner’s guide to project reviews - everything you wanted to know but wer...
A beginner’s guide to project reviews - everything you wanted to know but wer...A beginner’s guide to project reviews - everything you wanted to know but wer...
A beginner’s guide to project reviews - everything you wanted to know but wer...
 
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH LỚP 12 - GLOBAL SUCCESS - FORM MỚI 2025 - ...
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH LỚP 12 - GLOBAL SUCCESS - FORM MỚI 2025 - ...BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH LỚP 12 - GLOBAL SUCCESS - FORM MỚI 2025 - ...
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH LỚP 12 - GLOBAL SUCCESS - FORM MỚI 2025 - ...
 
Codeavour 5.0 International Impact Report - The Biggest International AI, Cod...
Codeavour 5.0 International Impact Report - The Biggest International AI, Cod...Codeavour 5.0 International Impact Report - The Biggest International AI, Cod...
Codeavour 5.0 International Impact Report - The Biggest International AI, Cod...
 
How to Empty a One2Many Field in Odoo 17
How to Empty a One2Many Field in Odoo 17How to Empty a One2Many Field in Odoo 17
How to Empty a One2Many Field in Odoo 17
 

Ineed this in python- Thank you Modify the merge sort algorithm to sor.docx

  • 1. Ineed this in python. Thank you Modify the merge sort algorithm to sort a list in descending order. Solution #! /usr/bin/python def Merge(Array, firstStart, firstEnd, secondEnd): n1 = firstEnd - firstStart + 1 n2 = secondEnd = firstEnd Temp1 = [None] * n1 Temp2 = [None] * n2 for i in range(n1): Temp1[i] = Array[firstStart + i] for i in range(n2): Temp2[i] = Array[firstEnd + i + 1] i = 0 j = 0 for k in range(firstStart, secondEnd): if Temp1[i] >= Temp2[j]: Array[k] = Temp1[i] i = i + 1 else: Array[k] = Temp2[j] j = j + 1 return Array def MergeSort(Array, left, right): if left < right: mid = (left + right) / 2 MergeSort(Array, left, mid) MergeSort(Array, mid+1, right) Merge(Array, left, mid, right) Array  = [10, 30, 40, 80, 20, 70, 90, 60, 50]