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

Arrays
ArraysArrays
Arrays
uos
 
Workshop 04 Review
Workshop 04 ReviewWorkshop 04 Review
Workshop 04 Review
migiwara
 
Using other functions
Using other functionsUsing other functions
Using other functions
Cha Mostierra
 

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

Skhandelwal Portfolio
Skhandelwal PortfolioSkhandelwal Portfolio
Skhandelwal Portfolio
donydpony
 
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 hoyos
Efrén Ingledue
 
Proyecto lectoescritura 29128
Proyecto lectoescritura 29128Proyecto lectoescritura 29128
Proyecto lectoescritura 29128
Efré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ñolas
Ternum
 

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).pptx
prakashvs7
 
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
Vivek487417
 
Ijcse13 05-01-048
Ijcse13 05-01-048Ijcse13 05-01-048
Ijcse13 05-01-048
vital vital
 
Ijcse13 05-01-048
Ijcse13 05-01-048Ijcse13 05-01-048
Ijcse13 05-01-048
vital vital
 

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

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Recently uploaded (20)

Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 

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];