SlideShare a Scribd company logo
1 of 4
Quick sort
Quick sort is often the most practical choice for an efficient sorting algorithm. Quick sort follows
a divide and conquer strategy. In place sorting and very fast, time complexity is average.
List of integers given in the form of array
To arrange the list of integers in increasing order. First we select one of element from the list, and
this can be any element in this example .We call the selected number Pivot and arrange the list
such that all the element lesser than the pivot are towards the left of it and all the element greater
towards the right. So partition is the process in which we select s pivot and rearrange the list such
that all the elements lesser than the pivot are towards the left and all the elements greater than pivot
toward s the right
2 1 3 4
Here 2, 1, 3 are less which is in left. Once we partitioned the array like this we can break this
segment in two sub segment. Same sorting procedure is carried out in sub segment until the
element
//Initialize array with 5 element,arrange them in ascending order
#include <stdio.h>
void quick_sort(int[ ],int,int);
int partition(int[ ],int,int);
int main()
{
int a[50],size,i;
printf("Enter the elements?");
scanf("%d",&size);
printf("nEnter array elements:");
8 5 7 6
for(i=0;i<size;i++)
scanf("%d",&a[i]);
quick_sort(a,0,size-1);
printf("n Ascending order :");
for(i=0;i<size;i++)
printf("%d ",a[i]);
return 0;
}
void quick_sort(int a[],int l,int u)
{
int j;
if(l<u)
{
j=partition(a,l,u);
quick_sort(a,l,j-1);
quick_sort(a,j+1,u);
}
}
int partition(int a[],int l,int u)
{
int v,i,j,temp;
v=a[l];
i=l;
j=u+1;
do
{
do
i++;
while(a[i]<v&&i<=u);
do
j--;
while(v<a[j]);
if(i<j)
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}while(i<j);
a[l]=a[j];
a[j]=v;
return(j);
}
Quick sort

More Related Content

What's hot

linear search and binary search
linear search and binary searchlinear search and binary search
linear search and binary searchZia Ush Shamszaman
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSGokul Hari
 
Dsa – data structure and algorithms searching
Dsa – data structure and algorithms   searchingDsa – data structure and algorithms   searching
Dsa – data structure and algorithms searchingsajinis3
 
Arrays
ArraysArrays
Arraysuos
 
Quick sort data structures
Quick sort data structuresQuick sort data structures
Quick sort data structureschauhankapil
 
366 it elective 4 (analysis of algoritm)
366 it elective 4 (analysis of algoritm)366 it elective 4 (analysis of algoritm)
366 it elective 4 (analysis of algoritm)Neil Soliven
 
Workshop 04 Review
Workshop 04 ReviewWorkshop 04 Review
Workshop 04 Reviewmigiwara
 
Rahat &amp; juhith
Rahat &amp; juhithRahat &amp; juhith
Rahat &amp; juhithRj Juhith
 
Using other functions
Using other functionsUsing other functions
Using other functionsCha Mostierra
 
Selection sort and insertion sort
Selection sort and insertion sortSelection sort and insertion sort
Selection sort and insertion sortMay Ann Mendoza
 
Sorting and searching arrays binary search algorithm
Sorting and searching arrays binary search algorithmSorting and searching arrays binary search algorithm
Sorting and searching arrays binary search algorithmDavid Burks-Courses
 
Selection sort 1
Selection sort 1Selection sort 1
Selection sort 1asmhemu
 
Arithmetic Order Of Operations
Arithmetic Order Of OperationsArithmetic Order Of Operations
Arithmetic Order Of OperationsBrett Dovey
 
Sorting algorithms in Data Structure
Sorting algorithms in Data StructureSorting algorithms in Data Structure
Sorting algorithms in Data StructureBalamurugan M
 

What's hot (20)

Sorting
SortingSorting
Sorting
 
sorting and its types
sorting and its typessorting and its types
sorting and its types
 
linear search and binary search
linear search and binary searchlinear search and binary search
linear search and binary search
 
Selection sort algorithm presentation, selection sort example using power point
Selection sort algorithm presentation, selection sort example using power point Selection sort algorithm presentation, selection sort example using power point
Selection sort algorithm presentation, selection sort example using power point
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
 
Dsa – data structure and algorithms searching
Dsa – data structure and algorithms   searchingDsa – data structure and algorithms   searching
Dsa – data structure and algorithms searching
 
Arrays
ArraysArrays
Arrays
 
Quick sort data structures
Quick sort data structuresQuick sort data structures
Quick sort data structures
 
366 it elective 4 (analysis of algoritm)
366 it elective 4 (analysis of algoritm)366 it elective 4 (analysis of algoritm)
366 it elective 4 (analysis of algoritm)
 
Workshop 04 Review
Workshop 04 ReviewWorkshop 04 Review
Workshop 04 Review
 
Rahat &amp; juhith
Rahat &amp; juhithRahat &amp; juhith
Rahat &amp; juhith
 
Ms excel formulas
Ms excel formulasMs excel formulas
Ms excel formulas
 
Using other functions
Using other functionsUsing other functions
Using other functions
 
Sorting
SortingSorting
Sorting
 
Selection sort and insertion sort
Selection sort and insertion sortSelection sort and insertion sort
Selection sort and insertion sort
 
Sorting and searching arrays binary search algorithm
Sorting and searching arrays binary search algorithmSorting and searching arrays binary search algorithm
Sorting and searching arrays binary search algorithm
 
Selection sort 1
Selection sort 1Selection sort 1
Selection sort 1
 
Arithmetic Order Of Operations
Arithmetic Order Of OperationsArithmetic Order Of Operations
Arithmetic Order Of Operations
 
Sorting algorithms in Data Structure
Sorting algorithms in Data StructureSorting algorithms in Data Structure
Sorting algorithms in Data Structure
 
Linear and binary search
Linear and binary searchLinear and binary search
Linear and binary search
 

Viewers also liked

Islam Agama Fitrah
Islam Agama FitrahIslam Agama Fitrah
Islam Agama Fitrahustazahrusni
 
Vibration analysis unit1
Vibration analysis unit1Vibration analysis unit1
Vibration analysis unit1Dibyendu De
 
Technological pillars to enable Smarter (Collaborative + Inclusive) Environme...
Technological pillars to enable Smarter (Collaborative + Inclusive) Environme...Technological pillars to enable Smarter (Collaborative + Inclusive) Environme...
Technological pillars to enable Smarter (Collaborative + Inclusive) Environme...Diego López-de-Ipiña González-de-Artaza
 
Evite fraudes en ofertas de viajes y descuentos
Evite fraudes en ofertas de viajes y descuentosEvite fraudes en ofertas de viajes y descuentos
Evite fraudes en ofertas de viajes y descuentosCPP España
 
Skhandelwal Portfolio
Skhandelwal PortfolioSkhandelwal Portfolio
Skhandelwal Portfoliodonydpony
 
Argus 01857420046
Argus 01857420046Argus 01857420046
Argus 01857420046savomir
 
Aprendiendo a sumar y restar en los niños del grado aplicando las tic.
Aprendiendo a sumar y restar en los niños del grado  aplicando las tic.Aprendiendo a sumar y restar en los niños del grado  aplicando las tic.
Aprendiendo a sumar y restar en los niños del grado aplicando las tic.Efrén Ingledue
 
Jaidith del carmen peralta hoyos
Jaidith del carmen peralta hoyosJaidith del carmen peralta hoyos
Jaidith del carmen peralta hoyosEfrén Ingledue
 
Proyecto lectoescritura 29128
Proyecto lectoescritura 29128Proyecto lectoescritura 29128
Proyecto lectoescritura 29128Efrén Ingledue
 
Formato proyectos de aula (1) (2)
Formato proyectos de aula (1) (2)Formato proyectos de aula (1) (2)
Formato proyectos de aula (1) (2)Efrén Ingledue
 
Internacionalización en Polonia, una oportunidad para las pymes españolas
Internacionalización en Polonia, una oportunidad para las pymes españolasInternacionalización en Polonia, una oportunidad para las pymes españolas
Internacionalización en Polonia, una oportunidad para las pymes españolasTernum
 
Scale body design for cars
Scale body design for carsScale body design for cars
Scale body design for carsRasel Ahmed
 

Viewers also liked (18)

Islam Agama Fitrah
Islam Agama FitrahIslam Agama Fitrah
Islam Agama Fitrah
 
Vibration analysis unit1
Vibration analysis unit1Vibration analysis unit1
Vibration analysis unit1
 
Technological pillars to enable Smarter (Collaborative + Inclusive) Environme...
Technological pillars to enable Smarter (Collaborative + Inclusive) Environme...Technological pillars to enable Smarter (Collaborative + Inclusive) Environme...
Technological pillars to enable Smarter (Collaborative + Inclusive) Environme...
 
Evite fraudes en ofertas de viajes y descuentos
Evite fraudes en ofertas de viajes y descuentosEvite fraudes en ofertas de viajes y descuentos
Evite fraudes en ofertas de viajes y descuentos
 
Skhandelwal Portfolio
Skhandelwal PortfolioSkhandelwal Portfolio
Skhandelwal Portfolio
 
Resume
ResumeResume
Resume
 
Argus 01857420046
Argus 01857420046Argus 01857420046
Argus 01857420046
 
Proyecto de aula
Proyecto de aulaProyecto de aula
Proyecto de aula
 
Slideshare
SlideshareSlideshare
Slideshare
 
Aprendiendo a sumar y restar en los niños del grado aplicando las tic.
Aprendiendo a sumar y restar en los niños del grado  aplicando las tic.Aprendiendo a sumar y restar en los niños del grado  aplicando las tic.
Aprendiendo a sumar y restar en los niños del grado aplicando las tic.
 
Jaidith del carmen peralta hoyos
Jaidith del carmen peralta hoyosJaidith del carmen peralta hoyos
Jaidith del carmen peralta hoyos
 
Proyecto lectoescritura 29128
Proyecto lectoescritura 29128Proyecto lectoescritura 29128
Proyecto lectoescritura 29128
 
Musica.
Musica.Musica.
Musica.
 
38636 tierra blanca
38636 tierra blanca38636 tierra blanca
38636 tierra blanca
 
Formato proyectos de aula (1) (2)
Formato proyectos de aula (1) (2)Formato proyectos de aula (1) (2)
Formato proyectos de aula (1) (2)
 
Internacionalización en Polonia, una oportunidad para las pymes españolas
Internacionalización en Polonia, una oportunidad para las pymes españolasInternacionalización en Polonia, una oportunidad para las pymes españolas
Internacionalización en Polonia, una oportunidad para las pymes españolas
 
Scale body design for cars
Scale body design for carsScale body design for cars
Scale body design for cars
 
38906
3890638906
38906
 

Similar to Quick sort

DS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptxDS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptxprakashvs7
 
Data Structures_ Sorting & Searching
Data Structures_ Sorting & SearchingData Structures_ Sorting & Searching
Data Structures_ Sorting & SearchingThenmozhiK5
 
Searching,sorting
Searching,sortingSearching,sorting
Searching,sortingLavanyaJ28
 
MODULE 5-Searching and-sorting
MODULE 5-Searching and-sortingMODULE 5-Searching and-sorting
MODULE 5-Searching and-sortingnikshaikh786
 
advanced searching and sorting.pdf
advanced searching and sorting.pdfadvanced searching and sorting.pdf
advanced searching and sorting.pdfharamaya university
 
What is a Sorting Algorithm Ishank mini project.pptx
What is a Sorting Algorithm Ishank mini project.pptxWhat is a Sorting Algorithm Ishank mini project.pptx
What is a Sorting Algorithm Ishank mini project.pptxSneakyGoblin1
 
DS PPT - ( 1 )SORTING lgoritham techniques with bast example
DS PPT - ( 1 )SORTING lgoritham techniques with bast exampleDS PPT - ( 1 )SORTING lgoritham techniques with bast example
DS PPT - ( 1 )SORTING lgoritham techniques with bast exampleVivek487417
 
data structures and algorithms Unit 3
data structures and algorithms Unit 3data structures and algorithms Unit 3
data structures and algorithms Unit 3infanciaj
 
SORTING techniques.pptx
SORTING techniques.pptxSORTING techniques.pptx
SORTING techniques.pptxDr.Shweta
 
Ijcse13 05-01-048
Ijcse13 05-01-048Ijcse13 05-01-048
Ijcse13 05-01-048vital vital
 
Ijcse13 05-01-048
Ijcse13 05-01-048Ijcse13 05-01-048
Ijcse13 05-01-048vital vital
 
Selection Sort with Improved Asymptotic Time Bounds
Selection Sort with Improved Asymptotic Time BoundsSelection Sort with Improved Asymptotic Time Bounds
Selection Sort with Improved Asymptotic Time Boundstheijes
 

Similar to Quick sort (20)

DS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptxDS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptx
 
Data Structures_ Sorting & Searching
Data Structures_ Sorting & SearchingData Structures_ Sorting & Searching
Data Structures_ Sorting & Searching
 
Unit v data structure-converted
Unit  v data structure-convertedUnit  v data structure-converted
Unit v data structure-converted
 
arrays in c
arrays in carrays in c
arrays in c
 
Searching,sorting
Searching,sortingSearching,sorting
Searching,sorting
 
my docoment
my docomentmy docoment
my docoment
 
Heap, quick and merge sort
Heap, quick and merge sortHeap, quick and merge sort
Heap, quick and merge sort
 
MODULE 5-Searching and-sorting
MODULE 5-Searching and-sortingMODULE 5-Searching and-sorting
MODULE 5-Searching and-sorting
 
advanced searching and sorting.pdf
advanced searching and sorting.pdfadvanced searching and sorting.pdf
advanced searching and sorting.pdf
 
What is a Sorting Algorithm Ishank mini project.pptx
What is a Sorting Algorithm Ishank mini project.pptxWhat is a Sorting Algorithm Ishank mini project.pptx
What is a Sorting Algorithm Ishank mini project.pptx
 
DS PPT - ( 1 )SORTING lgoritham techniques with bast example
DS PPT - ( 1 )SORTING lgoritham techniques with bast exampleDS PPT - ( 1 )SORTING lgoritham techniques with bast example
DS PPT - ( 1 )SORTING lgoritham techniques with bast example
 
Sorting
SortingSorting
Sorting
 
data structures and algorithms Unit 3
data structures and algorithms Unit 3data structures and algorithms Unit 3
data structures and algorithms Unit 3
 
SORTING techniques.pptx
SORTING techniques.pptxSORTING techniques.pptx
SORTING techniques.pptx
 
Quick sort algorithm
Quick sort algorithmQuick sort algorithm
Quick sort algorithm
 
Ijcse13 05-01-048
Ijcse13 05-01-048Ijcse13 05-01-048
Ijcse13 05-01-048
 
Ijcse13 05-01-048
Ijcse13 05-01-048Ijcse13 05-01-048
Ijcse13 05-01-048
 
Sorting.pptx
Sorting.pptxSorting.pptx
Sorting.pptx
 
Sorting
SortingSorting
Sorting
 
Selection Sort with Improved Asymptotic Time Bounds
Selection Sort with Improved Asymptotic Time BoundsSelection Sort with Improved Asymptotic Time Bounds
Selection Sort with Improved Asymptotic Time Bounds
 

Recently uploaded

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 

Recently uploaded (20)

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 

Quick sort

  • 1. Quick sort Quick sort is often the most practical choice for an efficient sorting algorithm. Quick sort follows a divide and conquer strategy. In place sorting and very fast, time complexity is average. List of integers given in the form of array To arrange the list of integers in increasing order. First we select one of element from the list, and this can be any element in this example .We call the selected number Pivot and arrange the list such that all the element lesser than the pivot are towards the left of it and all the element greater towards the right. So partition is the process in which we select s pivot and rearrange the list such that all the elements lesser than the pivot are towards the left and all the elements greater than pivot toward s the right 2 1 3 4 Here 2, 1, 3 are less which is in left. Once we partitioned the array like this we can break this segment in two sub segment. Same sorting procedure is carried out in sub segment until the element //Initialize array with 5 element,arrange them in ascending order #include <stdio.h> void quick_sort(int[ ],int,int); int partition(int[ ],int,int); int main() { int a[50],size,i; printf("Enter the elements?"); scanf("%d",&size); printf("nEnter array elements:"); 8 5 7 6
  • 2. for(i=0;i<size;i++) scanf("%d",&a[i]); quick_sort(a,0,size-1); printf("n Ascending order :"); for(i=0;i<size;i++) printf("%d ",a[i]); return 0; } void quick_sort(int a[],int l,int u) { int j; if(l<u) { j=partition(a,l,u); quick_sort(a,l,j-1); quick_sort(a,j+1,u); } } int partition(int a[],int l,int u) { int v,i,j,temp; v=a[l];