SlideShare a Scribd company logo
1 of 13
MERGE
SORT
21MCA066 ROHAN THOMBRE
21MCA052 EKTA SINGH RATHORE
21MCA095 MOHIT NIHALANI
Merge Sort-
• Merge sort is a famous sorting algorithm.
• It uses a divide and conquer paradigm for sorting.
• It divides the problem into sub problems and solves them individually.
• It then combines the results of sub problems to get the solution of the original
problem.
How Merge Sort Works?
Before learning how merge sort works, let us learn about the merge procedure of merge sort
algorithm.
The merge procedure of merge sort algorithm is used to merge two sorted arrays into a third
array in sorted order.
Consider we want to merge the following two sorted sub arrays into a third array in sorted order-
Step 1:
• Create two variables i and j for left and right sub arrays.
• Create variable k for sorted output array.
Step 2:
• We have i = 0, j = 0, k = 0.
• Since L[0] < R[0], so we perform A[0] = L[0] i.e. we copy the first element from left sub array to our sorted
output array.
• Then, we increment i and k by 1.
Then, we have-
Step 3:
• We have i = 1, j = 0, k = 1.
• Since L[1] > R[0], so we perform A[1] = R[0] i.e. we copy the first element from right sub array to our
sorted output array.
• Then, we increment j and k by 1.
Then, we have-
Step 4:
• We have i = 1, j = 1, k = 2.
• Since L[1] > R[1], so we perform A[2] = R[1].
• Then, we increment j and k by 1.
Then, we have-
Step 5:
• We have i = 1, j = 2, k = 3.
• Since L[1] < R[2], so we perform A[3] = L[1].
• Then, we increment i and k by 1.
Then, we have-
Step 6:
• We have i = 2, j = 2, k = 4.
• Since L[2] > R[2], so we perform A[4] = R[2].
• Then, we increment j and k by 1.
Then, we have-
Step 7:
• Clearly, all the elements from right sub array have been added to the sorted output array.
• So, we exit the first while loop with the condition while(i<nL && j<nR) since now j>nR.
• Then, we add remaining elements from the left sub array to the sorted output array using next while loop.
Finally, our sorted output array is-
Merge Sort Algorithm-
Merge Sort Algorithm works in the following steps-
• It divides the given unsorted array into two halves- left and right sub arrays.
• The sub arrays are divided recursively.
• This division continues until the size of each sub array becomes 1.
• After each sub array contains only a single element, each sub array is sorted trivially.
• Then, the above discussed merge procedure is called.
• The merge procedure combines these trivially sorted arrays to produce a final sorted
array.
Properties-
Some of the important properties of merge sort algorithm are-
• Merge sort uses a divide and conquer paradigm for sorting.
• Merge sort is a recursive sorting algorithm.
• Merge sort is a stable sorting algorithm.
• Merge sort is not an in-place sorting algorithm.
• The time complexity of merge sort algorithm is Θ(nlogn).
• The space complexity of merge sort algorithm is Θ(n).
THANK YOU

More Related Content

Similar to presentation.pptx

Similar to presentation.pptx (20)

Sorting
SortingSorting
Sorting
 
sorting-160810203705.pptx
sorting-160810203705.pptxsorting-160810203705.pptx
sorting-160810203705.pptx
 
Quick sort
Quick sortQuick sort
Quick sort
 
Unit III Version I.pptx
Unit III Version I.pptxUnit III Version I.pptx
Unit III Version I.pptx
 
sorting-160810203705.pptx
sorting-160810203705.pptxsorting-160810203705.pptx
sorting-160810203705.pptx
 
Lecture 13 data structures and algorithms
Lecture 13 data structures and algorithmsLecture 13 data structures and algorithms
Lecture 13 data structures and algorithms
 
chapter7_Sec1.ppt
chapter7_Sec1.pptchapter7_Sec1.ppt
chapter7_Sec1.ppt
 
Quick sort
Quick sortQuick sort
Quick sort
 
Lecture23
Lecture23Lecture23
Lecture23
 
Unit 7 sorting
Unit 7   sortingUnit 7   sorting
Unit 7 sorting
 
Analysis of Algorithm (Bubblesort and Quicksort)
Analysis of Algorithm (Bubblesort and Quicksort)Analysis of Algorithm (Bubblesort and Quicksort)
Analysis of Algorithm (Bubblesort and Quicksort)
 
quick sort by deepak.pptx
quick sort by deepak.pptxquick sort by deepak.pptx
quick sort by deepak.pptx
 
Data structure using c module 3
Data structure using c module 3Data structure using c module 3
Data structure using c module 3
 
Lecture -16-merge sort (slides).pptx
Lecture -16-merge sort (slides).pptxLecture -16-merge sort (slides).pptx
Lecture -16-merge sort (slides).pptx
 
Sorting arrays
Sorting arrays Sorting arrays
Sorting arrays
 
Determinants.ppt
Determinants.pptDeterminants.ppt
Determinants.ppt
 
Presentation on binary search, quick sort, merge sort and problems
Presentation on binary search, quick sort, merge sort  and problemsPresentation on binary search, quick sort, merge sort  and problems
Presentation on binary search, quick sort, merge sort and problems
 
Linear Algebra and Matlab tutorial
Linear Algebra and Matlab tutorialLinear Algebra and Matlab tutorial
Linear Algebra and Matlab tutorial
 
day 13.pptx
day 13.pptxday 13.pptx
day 13.pptx
 
Parallel Algorithms
Parallel AlgorithmsParallel Algorithms
Parallel Algorithms
 

More from rohanthombre2

Java-Brochure-English(gsggsgshshssh).pdf
Java-Brochure-English(gsggsgshshssh).pdfJava-Brochure-English(gsggsgshshssh).pdf
Java-Brochure-English(gsggsgshshssh).pdfrohanthombre2
 
Student Management System presentatio.pptx
Student Management System presentatio.pptxStudent Management System presentatio.pptx
Student Management System presentatio.pptxrohanthombre2
 
Hosiptal-MS-PPT-zl64ci.pptx
Hosiptal-MS-PPT-zl64ci.pptxHosiptal-MS-PPT-zl64ci.pptx
Hosiptal-MS-PPT-zl64ci.pptxrohanthombre2
 
onlinelibrarymanagementsystem-160511065906.pdf
onlinelibrarymanagementsystem-160511065906.pdfonlinelibrarymanagementsystem-160511065906.pdf
onlinelibrarymanagementsystem-160511065906.pdfrohanthombre2
 
onlinecrimereportingsystemppt-171012174600.pdf
onlinecrimereportingsystemppt-171012174600.pdfonlinecrimereportingsystemppt-171012174600.pdf
onlinecrimereportingsystemppt-171012174600.pdfrohanthombre2
 
restaurantmanagementpresent-160801054633.pdf
restaurantmanagementpresent-160801054633.pdfrestaurantmanagementpresent-160801054633.pdf
restaurantmanagementpresent-160801054633.pdfrohanthombre2
 
87437-IOT Home Automation PPT-4-3.pptx
87437-IOT Home Automation PPT-4-3.pptx87437-IOT Home Automation PPT-4-3.pptx
87437-IOT Home Automation PPT-4-3.pptxrohanthombre2
 

More from rohanthombre2 (7)

Java-Brochure-English(gsggsgshshssh).pdf
Java-Brochure-English(gsggsgshshssh).pdfJava-Brochure-English(gsggsgshshssh).pdf
Java-Brochure-English(gsggsgshshssh).pdf
 
Student Management System presentatio.pptx
Student Management System presentatio.pptxStudent Management System presentatio.pptx
Student Management System presentatio.pptx
 
Hosiptal-MS-PPT-zl64ci.pptx
Hosiptal-MS-PPT-zl64ci.pptxHosiptal-MS-PPT-zl64ci.pptx
Hosiptal-MS-PPT-zl64ci.pptx
 
onlinelibrarymanagementsystem-160511065906.pdf
onlinelibrarymanagementsystem-160511065906.pdfonlinelibrarymanagementsystem-160511065906.pdf
onlinelibrarymanagementsystem-160511065906.pdf
 
onlinecrimereportingsystemppt-171012174600.pdf
onlinecrimereportingsystemppt-171012174600.pdfonlinecrimereportingsystemppt-171012174600.pdf
onlinecrimereportingsystemppt-171012174600.pdf
 
restaurantmanagementpresent-160801054633.pdf
restaurantmanagementpresent-160801054633.pdfrestaurantmanagementpresent-160801054633.pdf
restaurantmanagementpresent-160801054633.pdf
 
87437-IOT Home Automation PPT-4-3.pptx
87437-IOT Home Automation PPT-4-3.pptx87437-IOT Home Automation PPT-4-3.pptx
87437-IOT Home Automation PPT-4-3.pptx
 

Recently uploaded

2024: The FAR, Federal Acquisition Regulations, Part 32
2024: The FAR, Federal Acquisition Regulations, Part 322024: The FAR, Federal Acquisition Regulations, Part 32
2024: The FAR, Federal Acquisition Regulations, Part 32JSchaus & Associates
 
Honasa Consumer Limited Impact Report 2024.pdf
Honasa Consumer Limited Impact Report 2024.pdfHonasa Consumer Limited Impact Report 2024.pdf
Honasa Consumer Limited Impact Report 2024.pdfSocial Samosa
 
1935 CONSTITUTION REPORT IN RIPH FINALLS
1935 CONSTITUTION REPORT IN RIPH FINALLS1935 CONSTITUTION REPORT IN RIPH FINALLS
1935 CONSTITUTION REPORT IN RIPH FINALLSarandianics
 
Make a difference in a girl's life by donating to her education!
Make a difference in a girl's life by donating to her education!Make a difference in a girl's life by donating to her education!
Make a difference in a girl's life by donating to her education!SERUDS INDIA
 
2024: The FAR, Federal Acquisition Regulations, Part 31
2024: The FAR, Federal Acquisition Regulations, Part 312024: The FAR, Federal Acquisition Regulations, Part 31
2024: The FAR, Federal Acquisition Regulations, Part 31JSchaus & Associates
 
Call Girls in Moti Bagh (delhi) call me [8448380779] escort service 24X7
Call Girls in Moti Bagh (delhi) call me [8448380779] escort service 24X7Call Girls in Moti Bagh (delhi) call me [8448380779] escort service 24X7
Call Girls in Moti Bagh (delhi) call me [8448380779] escort service 24X7Delhi Call girls
 
NAP Expo - Delivering effective and adequate adaptation.pptx
NAP Expo - Delivering effective and adequate adaptation.pptxNAP Expo - Delivering effective and adequate adaptation.pptx
NAP Expo - Delivering effective and adequate adaptation.pptxNAP Global Network
 
Cheap Call Girls In Hyderabad Phone No 📞 9352988975 📞 Elite Escort Service Av...
Cheap Call Girls In Hyderabad Phone No 📞 9352988975 📞 Elite Escort Service Av...Cheap Call Girls In Hyderabad Phone No 📞 9352988975 📞 Elite Escort Service Av...
Cheap Call Girls In Hyderabad Phone No 📞 9352988975 📞 Elite Escort Service Av...kajalverma014
 
Dating Call Girls inBaloda Bazar Bhatapara 9332606886Call Girls Advance Cash...
Dating Call Girls inBaloda Bazar Bhatapara  9332606886Call Girls Advance Cash...Dating Call Girls inBaloda Bazar Bhatapara  9332606886Call Girls Advance Cash...
Dating Call Girls inBaloda Bazar Bhatapara 9332606886Call Girls Advance Cash...kumargunjan9515
 
Tuvalu Coastal Adaptation Project (TCAP)
Tuvalu Coastal Adaptation Project (TCAP)Tuvalu Coastal Adaptation Project (TCAP)
Tuvalu Coastal Adaptation Project (TCAP)NAP Global Network
 
An Atoll Futures Research Institute? Presentation for CANCC
An Atoll Futures Research Institute? Presentation for CANCCAn Atoll Futures Research Institute? Presentation for CANCC
An Atoll Futures Research Institute? Presentation for CANCCNAP Global Network
 
Call Girls Mehsana / 8250092165 Genuine Call girls with real Photos and Number
Call Girls Mehsana / 8250092165 Genuine Call girls with real Photos and NumberCall Girls Mehsana / 8250092165 Genuine Call girls with real Photos and Number
Call Girls Mehsana / 8250092165 Genuine Call girls with real Photos and NumberSareena Khatun
 
Antisemitism Awareness Act: pénaliser la critique de l'Etat d'Israël
Antisemitism Awareness Act: pénaliser la critique de l'Etat d'IsraëlAntisemitism Awareness Act: pénaliser la critique de l'Etat d'Israël
Antisemitism Awareness Act: pénaliser la critique de l'Etat d'IsraëlEdouardHusson
 
Unique Value Prop slide deck________.pdf
Unique Value Prop slide deck________.pdfUnique Value Prop slide deck________.pdf
Unique Value Prop slide deck________.pdfScottMeyers35
 
Vasai Call Girls In 07506202331, Nalasopara Call Girls In Mumbai
Vasai Call Girls In 07506202331, Nalasopara Call Girls In MumbaiVasai Call Girls In 07506202331, Nalasopara Call Girls In Mumbai
Vasai Call Girls In 07506202331, Nalasopara Call Girls In MumbaiPriya Reddy
 
Peace-Conflict-and-National-Adaptation-Plan-NAP-Processes-.pdf
Peace-Conflict-and-National-Adaptation-Plan-NAP-Processes-.pdfPeace-Conflict-and-National-Adaptation-Plan-NAP-Processes-.pdf
Peace-Conflict-and-National-Adaptation-Plan-NAP-Processes-.pdfNAP Global Network
 
Kolkata Call Girls Halisahar 💯Call Us 🔝 8005736733 🔝 💃 Top Class Call Girl ...
Kolkata Call Girls Halisahar  💯Call Us 🔝 8005736733 🔝 💃  Top Class Call Girl ...Kolkata Call Girls Halisahar  💯Call Us 🔝 8005736733 🔝 💃  Top Class Call Girl ...
Kolkata Call Girls Halisahar 💯Call Us 🔝 8005736733 🔝 💃 Top Class Call Girl ...Namrata Singh
 
Competitive Advantage slide deck___.pptx
Competitive Advantage slide deck___.pptxCompetitive Advantage slide deck___.pptx
Competitive Advantage slide deck___.pptxScottMeyers35
 

Recently uploaded (20)

AHMR volume 10 number 1 January-April 2024
AHMR volume 10 number 1 January-April 2024AHMR volume 10 number 1 January-April 2024
AHMR volume 10 number 1 January-April 2024
 
2024: The FAR, Federal Acquisition Regulations, Part 32
2024: The FAR, Federal Acquisition Regulations, Part 322024: The FAR, Federal Acquisition Regulations, Part 32
2024: The FAR, Federal Acquisition Regulations, Part 32
 
Honasa Consumer Limited Impact Report 2024.pdf
Honasa Consumer Limited Impact Report 2024.pdfHonasa Consumer Limited Impact Report 2024.pdf
Honasa Consumer Limited Impact Report 2024.pdf
 
1935 CONSTITUTION REPORT IN RIPH FINALLS
1935 CONSTITUTION REPORT IN RIPH FINALLS1935 CONSTITUTION REPORT IN RIPH FINALLS
1935 CONSTITUTION REPORT IN RIPH FINALLS
 
Make a difference in a girl's life by donating to her education!
Make a difference in a girl's life by donating to her education!Make a difference in a girl's life by donating to her education!
Make a difference in a girl's life by donating to her education!
 
2024: The FAR, Federal Acquisition Regulations, Part 31
2024: The FAR, Federal Acquisition Regulations, Part 312024: The FAR, Federal Acquisition Regulations, Part 31
2024: The FAR, Federal Acquisition Regulations, Part 31
 
tOld settlement register shouldnotaffect BTR
tOld settlement register shouldnotaffect BTRtOld settlement register shouldnotaffect BTR
tOld settlement register shouldnotaffect BTR
 
Call Girls in Moti Bagh (delhi) call me [8448380779] escort service 24X7
Call Girls in Moti Bagh (delhi) call me [8448380779] escort service 24X7Call Girls in Moti Bagh (delhi) call me [8448380779] escort service 24X7
Call Girls in Moti Bagh (delhi) call me [8448380779] escort service 24X7
 
NAP Expo - Delivering effective and adequate adaptation.pptx
NAP Expo - Delivering effective and adequate adaptation.pptxNAP Expo - Delivering effective and adequate adaptation.pptx
NAP Expo - Delivering effective and adequate adaptation.pptx
 
Cheap Call Girls In Hyderabad Phone No 📞 9352988975 📞 Elite Escort Service Av...
Cheap Call Girls In Hyderabad Phone No 📞 9352988975 📞 Elite Escort Service Av...Cheap Call Girls In Hyderabad Phone No 📞 9352988975 📞 Elite Escort Service Av...
Cheap Call Girls In Hyderabad Phone No 📞 9352988975 📞 Elite Escort Service Av...
 
Dating Call Girls inBaloda Bazar Bhatapara 9332606886Call Girls Advance Cash...
Dating Call Girls inBaloda Bazar Bhatapara  9332606886Call Girls Advance Cash...Dating Call Girls inBaloda Bazar Bhatapara  9332606886Call Girls Advance Cash...
Dating Call Girls inBaloda Bazar Bhatapara 9332606886Call Girls Advance Cash...
 
Tuvalu Coastal Adaptation Project (TCAP)
Tuvalu Coastal Adaptation Project (TCAP)Tuvalu Coastal Adaptation Project (TCAP)
Tuvalu Coastal Adaptation Project (TCAP)
 
An Atoll Futures Research Institute? Presentation for CANCC
An Atoll Futures Research Institute? Presentation for CANCCAn Atoll Futures Research Institute? Presentation for CANCC
An Atoll Futures Research Institute? Presentation for CANCC
 
Call Girls Mehsana / 8250092165 Genuine Call girls with real Photos and Number
Call Girls Mehsana / 8250092165 Genuine Call girls with real Photos and NumberCall Girls Mehsana / 8250092165 Genuine Call girls with real Photos and Number
Call Girls Mehsana / 8250092165 Genuine Call girls with real Photos and Number
 
Antisemitism Awareness Act: pénaliser la critique de l'Etat d'Israël
Antisemitism Awareness Act: pénaliser la critique de l'Etat d'IsraëlAntisemitism Awareness Act: pénaliser la critique de l'Etat d'Israël
Antisemitism Awareness Act: pénaliser la critique de l'Etat d'Israël
 
Unique Value Prop slide deck________.pdf
Unique Value Prop slide deck________.pdfUnique Value Prop slide deck________.pdf
Unique Value Prop slide deck________.pdf
 
Vasai Call Girls In 07506202331, Nalasopara Call Girls In Mumbai
Vasai Call Girls In 07506202331, Nalasopara Call Girls In MumbaiVasai Call Girls In 07506202331, Nalasopara Call Girls In Mumbai
Vasai Call Girls In 07506202331, Nalasopara Call Girls In Mumbai
 
Peace-Conflict-and-National-Adaptation-Plan-NAP-Processes-.pdf
Peace-Conflict-and-National-Adaptation-Plan-NAP-Processes-.pdfPeace-Conflict-and-National-Adaptation-Plan-NAP-Processes-.pdf
Peace-Conflict-and-National-Adaptation-Plan-NAP-Processes-.pdf
 
Kolkata Call Girls Halisahar 💯Call Us 🔝 8005736733 🔝 💃 Top Class Call Girl ...
Kolkata Call Girls Halisahar  💯Call Us 🔝 8005736733 🔝 💃  Top Class Call Girl ...Kolkata Call Girls Halisahar  💯Call Us 🔝 8005736733 🔝 💃  Top Class Call Girl ...
Kolkata Call Girls Halisahar 💯Call Us 🔝 8005736733 🔝 💃 Top Class Call Girl ...
 
Competitive Advantage slide deck___.pptx
Competitive Advantage slide deck___.pptxCompetitive Advantage slide deck___.pptx
Competitive Advantage slide deck___.pptx
 

presentation.pptx

  • 1. MERGE SORT 21MCA066 ROHAN THOMBRE 21MCA052 EKTA SINGH RATHORE 21MCA095 MOHIT NIHALANI
  • 2. Merge Sort- • Merge sort is a famous sorting algorithm. • It uses a divide and conquer paradigm for sorting. • It divides the problem into sub problems and solves them individually. • It then combines the results of sub problems to get the solution of the original problem.
  • 3. How Merge Sort Works? Before learning how merge sort works, let us learn about the merge procedure of merge sort algorithm. The merge procedure of merge sort algorithm is used to merge two sorted arrays into a third array in sorted order. Consider we want to merge the following two sorted sub arrays into a third array in sorted order-
  • 4. Step 1: • Create two variables i and j for left and right sub arrays. • Create variable k for sorted output array.
  • 5. Step 2: • We have i = 0, j = 0, k = 0. • Since L[0] < R[0], so we perform A[0] = L[0] i.e. we copy the first element from left sub array to our sorted output array. • Then, we increment i and k by 1. Then, we have-
  • 6. Step 3: • We have i = 1, j = 0, k = 1. • Since L[1] > R[0], so we perform A[1] = R[0] i.e. we copy the first element from right sub array to our sorted output array. • Then, we increment j and k by 1. Then, we have-
  • 7. Step 4: • We have i = 1, j = 1, k = 2. • Since L[1] > R[1], so we perform A[2] = R[1]. • Then, we increment j and k by 1. Then, we have-
  • 8. Step 5: • We have i = 1, j = 2, k = 3. • Since L[1] < R[2], so we perform A[3] = L[1]. • Then, we increment i and k by 1. Then, we have-
  • 9. Step 6: • We have i = 2, j = 2, k = 4. • Since L[2] > R[2], so we perform A[4] = R[2]. • Then, we increment j and k by 1. Then, we have-
  • 10. Step 7: • Clearly, all the elements from right sub array have been added to the sorted output array. • So, we exit the first while loop with the condition while(i<nL && j<nR) since now j>nR. • Then, we add remaining elements from the left sub array to the sorted output array using next while loop. Finally, our sorted output array is-
  • 11. Merge Sort Algorithm- Merge Sort Algorithm works in the following steps- • It divides the given unsorted array into two halves- left and right sub arrays. • The sub arrays are divided recursively. • This division continues until the size of each sub array becomes 1. • After each sub array contains only a single element, each sub array is sorted trivially. • Then, the above discussed merge procedure is called. • The merge procedure combines these trivially sorted arrays to produce a final sorted array.
  • 12. Properties- Some of the important properties of merge sort algorithm are- • Merge sort uses a divide and conquer paradigm for sorting. • Merge sort is a recursive sorting algorithm. • Merge sort is a stable sorting algorithm. • Merge sort is not an in-place sorting algorithm. • The time complexity of merge sort algorithm is Θ(nlogn). • The space complexity of merge sort algorithm is Θ(n).