SlideShare a Scribd company logo
MERGE SORT
merge sort - updated to c           .ppt
AVERAGE AND WORST CASE TIME
COMPLEXITY OF MERGE SORT
//program for merge sort
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
int a[20];
int low,high;
int temp[20] ; //to store sorted result
void get_data();
void merge_sort(int low,int high);
void combine (int low,int mid,int high);
void display();
void get_data()
{
int i;
printf(“nn Enter number of data to be sort :”);
scanf(“n %d “, &n);
printf(“n Enter Element one by one”);
for(i=0 ;i<n; i++)
scanf(“n %d “, &a[i]);
}
void merge_sort(int low,int high);
{
int mid;
if (low<high)
{
mid=(low+high)/2;
merge_sort(low,mid);
merge_sort(mid+1,high);
combine(low,mid,high);
}
}
void combine(int low,int mid,int high)
{
int i,j,k;
k=low;
i=low;
j=mid+1;
while(i<=mid && j<=high)
{
if (a[i])<=a[j])
{
temp[k]=a[i];
i++;
k++;
}
if(a[i]>a[j])
{
temp[k]=a[j];
j++;
k++;
}
} //closing of while loop
while(i<=mid)
{
temp[k]=a[i];
i++;
k++;
}
while (j<=high)
{
temp[k]=a[j];
j++;
k++;
}
} // closing of function combine
void display()
{
printf("nArray elements after Merge sort ");
for(i=0;i<n;++i)
printf("%d ",temp[i]);
}
void main()
{
clrscr();
printf(“n Merge Sort”);
get_data(); //1.read input
merge_sort(0,n-1); //2.merge sort
display(); //3.display output
getch();
}
Output
Merge sort
Enter number of data to be sort :5
Enter Element one by one”);
45
78
2
34
63
Array elements after Merge sort
2 34 45 63 78

More Related Content

PDF
Merge sort
PPTX
Merge sort analysis and its real time applications
PDF
Ds sorting
PDF
Sorting Algorithms and their implementations
PPTX
Data Structures and Agorithm: DS 20 Merge Sort.pptx
PPTX
Merge sort
PPTX
Merge sort algorithm power point presentation
PPTX
Daa final
Merge sort
Merge sort analysis and its real time applications
Ds sorting
Sorting Algorithms and their implementations
Data Structures and Agorithm: DS 20 Merge Sort.pptx
Merge sort
Merge sort algorithm power point presentation
Daa final

Similar to merge sort - updated to c .ppt (20)

DOCX
Merge sort in CSolution#include-stdio-h- #define MAX 50 void mergeSort.docx
PPTX
PPT.pptx Searching and Sorting Techniques
PPTX
Merge sort-algorithm for computer science engineering students
PPTX
Mergesort
PPTX
Merge sort
PPTX
8.05.Merge_sort.pptxCUYGYUKTGUIJBJKGKUYGFKJBNVKUYV87VYFHHGVTFGU
PPTX
dsa presentation on merge sorting in C++.pptx
PPT
merge sort help in language C with algorithms
PPTX
Merj sort
PDF
Analysis and design of algorithms part2
DOCX
Write a complete C programme to implement the following sorting algor.docx
PDF
Merge sort
PPTX
Data Structure Marge sort Group 5 pptx so
PPT
Sorting algos > Data Structures & Algorithums
PPTX
merg sort.pptx
DOCX
Merge sort lab mannual
DOC
Ds program-print
PPTX
Merge sort
PDF
Sorting algorithms bubble sort to merge sort.pdf
PDF
Merge sort in CSolution#include-stdio-h- #define MAX 50 void mergeSort.docx
PPT.pptx Searching and Sorting Techniques
Merge sort-algorithm for computer science engineering students
Mergesort
Merge sort
8.05.Merge_sort.pptxCUYGYUKTGUIJBJKGKUYGFKJBNVKUYV87VYFHHGVTFGU
dsa presentation on merge sorting in C++.pptx
merge sort help in language C with algorithms
Merj sort
Analysis and design of algorithms part2
Write a complete C programme to implement the following sorting algor.docx
Merge sort
Data Structure Marge sort Group 5 pptx so
Sorting algos > Data Structures & Algorithums
merg sort.pptx
Merge sort lab mannual
Ds program-print
Merge sort
Sorting algorithms bubble sort to merge sort.pdf
Ad

Recently uploaded (20)

PDF
RMMM.pdf make it easy to upload and study
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PDF
Hazard Identification & Risk Assessment .pdf
PPTX
Cell Types and Its function , kingdom of life
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
Classroom Observation Tools for Teachers
PPTX
Lesson notes of climatology university.
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Weekly quiz Compilation Jan -July 25.pdf
PPTX
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
PDF
Empowerment Technology for Senior High School Guide
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
PDF
Trump Administration's workforce development strategy
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PDF
SOIL: Factor, Horizon, Process, Classification, Degradation, Conservation
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
RMMM.pdf make it easy to upload and study
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
Hazard Identification & Risk Assessment .pdf
Cell Types and Its function , kingdom of life
A systematic review of self-coping strategies used by university students to ...
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
Classroom Observation Tools for Teachers
Lesson notes of climatology university.
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Weekly quiz Compilation Jan -July 25.pdf
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
Empowerment Technology for Senior High School Guide
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
Trump Administration's workforce development strategy
Chinmaya Tiranga quiz Grand Finale.pdf
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
SOIL: Factor, Horizon, Process, Classification, Degradation, Conservation
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
Ad

merge sort - updated to c .ppt

  • 3. AVERAGE AND WORST CASE TIME COMPLEXITY OF MERGE SORT
  • 4. //program for merge sort #include<stdio.h> #include<stdlib.h> #include<conio.h> int a[20]; int low,high; int temp[20] ; //to store sorted result void get_data(); void merge_sort(int low,int high); void combine (int low,int mid,int high); void display();
  • 5. void get_data() { int i; printf(“nn Enter number of data to be sort :”); scanf(“n %d “, &n); printf(“n Enter Element one by one”); for(i=0 ;i<n; i++) scanf(“n %d “, &a[i]); }
  • 6. void merge_sort(int low,int high); { int mid; if (low<high) { mid=(low+high)/2; merge_sort(low,mid); merge_sort(mid+1,high); combine(low,mid,high); } }
  • 7. void combine(int low,int mid,int high) { int i,j,k; k=low; i=low; j=mid+1; while(i<=mid && j<=high) { if (a[i])<=a[j]) { temp[k]=a[i]; i++; k++; }
  • 8. if(a[i]>a[j]) { temp[k]=a[j]; j++; k++; } } //closing of while loop while(i<=mid) { temp[k]=a[i]; i++; k++; } while (j<=high) { temp[k]=a[j]; j++; k++; } } // closing of function combine
  • 9. void display() { printf("nArray elements after Merge sort "); for(i=0;i<n;++i) printf("%d ",temp[i]); } void main() { clrscr(); printf(“n Merge Sort”); get_data(); //1.read input merge_sort(0,n-1); //2.merge sort display(); //3.display output getch(); } Output Merge sort Enter number of data to be sort :5 Enter Element one by one”); 45 78 2 34 63 Array elements after Merge sort 2 34 45 63 78