SlideShare a Scribd company logo
1 of 10
Quick Sorting
IntroductionIntroduction
 Quick sort is an example of divide and conquer algorithm. It
was developed in1960 by Tony Hoare. It is a recursive
algorithm.The intutive idea is as follows:
 Divide:- Choose any element of the list, say the last element
as a pivot value. Remove the pivot from the list. Divide the
remaining elements into two parts,left and right,such that all
the elements equal to or less than the pivot are in the left list,
while the elements greater than the pivot are in right list.
 Conquer:-Sort the two halves recursively using quick sort.
 Combine:-Return sorted_left + pivot + sorted_right,as your
final sorted_list.
History of Quick Sort AlgorithmHistory of Quick Sort Algorithm
 While studying at Moscow State University, Tony Hoare
received an offer of employment from
 National Physical Laboratory (NPL) to work on new project
for machine translation form Russian to English. However
,because dictionaries were sorted into alphabetical order
before translation. Hoare thought of two methods to solve
this problem.The first method would have taken an amount
of time proportional to the square of the length of a
sentence. The second method would later manifest as
quicksort.
 During this course, Hoare programmed an ultra-fast sorting
algorithm now known as quicksort. His paper on Quicksort
was also published in 1961,with another following in 1962.
Example of Quick SortExample of Quick Sort
Implementation of code in codeblocksImplementation of code in codeblocks
 #include < stdio. h>
 void quicksort(int [10],int,int);
 int main(){
 int x[20], size , i;
 printf("Enter size of the array: ");
 scanf("%d",&size);
 printf("Enter %d elements: ",size);
 for(i=0;i<size ; i++)
 scanf("% d",& x [i]);
 quicksort(x,0,size-1);
 return 0;
 }
 printf("Sorted elements: ");
 for(i=0;i<size ; i++)
 printf(" %d ", x[ i]);
 void quicksort(int x[10],int first,int last){
 int pivot,j,temp,i;
 if(first<last){
 pivot=first;
 i=first;
 j=last;
 while(i<j){
 while(x[i]<=x[pivot]&&i<last)
Algorithm For Quick SortAlgorithm For Quick Sort
 Quick( A, N, Beg, End , Loc)
 Here A is an array of N elements .Parameters Beg and End contain
the boundary values of the sublist to which this procedure applies.
Loc keeps track of the position of the first element A[Beg] of the
sublist during the procedure. The local variable Left and Right will
contain the boundary values of the list of elements that have not
been scanned.
1. [Initialize].Set Left:= Beg, Right:=End and Loc:=Beg.
2. [Scan from right to left]
a) Repeat while A[Loc]<=A[Right] and Loc!=Right. Right:=Right-1
[End of Loop]
b) If Loc=Right, then: return.
c) If A[Loc]>A[Right],then:
i. Interchange A[loc] and A[Right].
ii. Set Loc:=Right.
iii. Go to Step 3.
3. [Scan from left to right]
a) Repeat while A[Left]<=A[Loc] and Left!=Loc: Left :=Left+1.
b) If Loc=Left , then return.
c) if A[Left]>A[Loc],then
i. Interchange A[Left] and A[Loc].
ii. Set Loc:=Left
iii. Go to Step 2.
[End of if structure].
 i++;
 while(x[j]>x[pivot])
 j--;
 if(i<j){
 temp=x[i];
 x[i]=x[j];
 x[j]=temp;}
 }
 temp=x[pivot];
 x[pivot]=x[j];
 x[j]=temp;
 quicksort(x,first,j-1);
 quicksort(x,j+1,last);
 }
 }
ConclusionConclusion
We discussed the history of the algorithm. Then implemented
the code in codeblocks. Quick sort is an efficient algorithm and
has an average running time of O(n*log(n)).While the worst-case
running time for quick sort is higher than that of the merge sort,
in practice quick sort works slightly faster the the merge sort.

More Related Content

What's hot

Algorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching AlgorithmsAlgorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching AlgorithmsMohamed Loey
 
Algorithm & data structures lec4&5
Algorithm & data structures lec4&5Algorithm & data structures lec4&5
Algorithm & data structures lec4&5Abdul Khan
 
Data structures and algorithms - sorting algorithms
Data structures and algorithms - sorting algorithmsData structures and algorithms - sorting algorithms
Data structures and algorithms - sorting algorithmsAbimbola Idowu
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithmsmultimedia9
 
Insertion sort
Insertion sortInsertion sort
Insertion sortalmaqboli
 
Different types of Shoring Algorithms with Animation
Different types of Shoring Algorithms with AnimationDifferent types of Shoring Algorithms with Animation
Different types of Shoring Algorithms with AnimationZakaria Hossain
 
Dsa – data structure and algorithms searching
Dsa – data structure and algorithms   searchingDsa – data structure and algorithms   searching
Dsa – data structure and algorithms searchingsajinis3
 
Linear search algorithm
Linear search algorithmLinear search algorithm
Linear search algorithmNeoClassical
 
Review of basic data structures
Review of basic data structuresReview of basic data structures
Review of basic data structuresDeepa Rani
 
Lect11 Sorting
Lect11 SortingLect11 Sorting
Lect11 Sortingryokollll
 
Quick Select (Decrease and Conquer)
Quick Select (Decrease and Conquer) Quick Select (Decrease and Conquer)
Quick Select (Decrease and Conquer) Gem WeBlog
 

What's hot (20)

Algorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching AlgorithmsAlgorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching Algorithms
 
Quick Sort
Quick SortQuick Sort
Quick Sort
 
Algorithm & data structures lec4&5
Algorithm & data structures lec4&5Algorithm & data structures lec4&5
Algorithm & data structures lec4&5
 
Data structures and algorithms - sorting algorithms
Data structures and algorithms - sorting algorithmsData structures and algorithms - sorting algorithms
Data structures and algorithms - sorting algorithms
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
Searching algorithms
Searching algorithmsSearching algorithms
Searching algorithms
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
 
Data Structures 2
Data Structures 2Data Structures 2
Data Structures 2
 
Different types of Shoring Algorithms with Animation
Different types of Shoring Algorithms with AnimationDifferent types of Shoring Algorithms with Animation
Different types of Shoring Algorithms with Animation
 
Dsa – data structure and algorithms searching
Dsa – data structure and algorithms   searchingDsa – data structure and algorithms   searching
Dsa – data structure and algorithms searching
 
Linear search algorithm
Linear search algorithmLinear search algorithm
Linear search algorithm
 
02 Stack
02 Stack02 Stack
02 Stack
 
Review of basic data structures
Review of basic data structuresReview of basic data structures
Review of basic data structures
 
Lect11 Sorting
Lect11 SortingLect11 Sorting
Lect11 Sorting
 
List interface
List interfaceList interface
List interface
 
Quick Select (Decrease and Conquer)
Quick Select (Decrease and Conquer) Quick Select (Decrease and Conquer)
Quick Select (Decrease and Conquer)
 
L10 sorting-searching
L10 sorting-searchingL10 sorting-searching
L10 sorting-searching
 
Binary Search
Binary SearchBinary Search
Binary Search
 
Vectors,squence & list
Vectors,squence & listVectors,squence & list
Vectors,squence & list
 
Sorting
SortingSorting
Sorting
 

Similar to Quick sorting

Dsa – data structure and algorithms sorting
Dsa – data structure and algorithms  sortingDsa – data structure and algorithms  sorting
Dsa – data structure and algorithms sortingsajinis3
 
Algorithm, Pseudocode and Flowcharting in C++
Algorithm, Pseudocode and Flowcharting in C++Algorithm, Pseudocode and Flowcharting in C++
Algorithm, Pseudocode and Flowcharting in C++Johnny Jean Tigas
 
Searching techniques with progrms
Searching techniques with progrmsSearching techniques with progrms
Searching techniques with progrmsMisssaxena
 
Data Structures by Maneesh Boddu
Data Structures by Maneesh BodduData Structures by Maneesh Boddu
Data Structures by Maneesh Boddumaneesh boddu
 
computer notes - List implementation
computer notes - List implementationcomputer notes - List implementation
computer notes - List implementationecomputernotes
 
lecture 11
lecture 11lecture 11
lecture 11sajinsc
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-listpinakspatel
 
Quick sort by Sania Nisar
Quick sort by Sania NisarQuick sort by Sania Nisar
Quick sort by Sania NisarSania Nisar
 
Searching and sorting Techniques in Data structures
Searching and sorting Techniques in Data structuresSearching and sorting Techniques in Data structures
Searching and sorting Techniques in Data structuresPRIANKA R
 
An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...
An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...
An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...Tosin Amuda
 

Similar to Quick sorting (20)

21-algorithms (1).ppt
21-algorithms (1).ppt21-algorithms (1).ppt
21-algorithms (1).ppt
 
21-algorithms.ppt
21-algorithms.ppt21-algorithms.ppt
21-algorithms.ppt
 
Dsa – data structure and algorithms sorting
Dsa – data structure and algorithms  sortingDsa – data structure and algorithms  sorting
Dsa – data structure and algorithms sorting
 
21-algorithms.ppt
21-algorithms.ppt21-algorithms.ppt
21-algorithms.ppt
 
Algorithm, Pseudocode and Flowcharting in C++
Algorithm, Pseudocode and Flowcharting in C++Algorithm, Pseudocode and Flowcharting in C++
Algorithm, Pseudocode and Flowcharting in C++
 
Searching techniques with progrms
Searching techniques with progrmsSearching techniques with progrms
Searching techniques with progrms
 
Lect-2.pptx
Lect-2.pptxLect-2.pptx
Lect-2.pptx
 
Quick sort
Quick sortQuick sort
Quick sort
 
Unit 2 - Quick Sort.pptx
Unit 2 - Quick Sort.pptxUnit 2 - Quick Sort.pptx
Unit 2 - Quick Sort.pptx
 
Chapter3.pptx
Chapter3.pptxChapter3.pptx
Chapter3.pptx
 
Big o notation
Big o notationBig o notation
Big o notation
 
Big o notation
Big o notationBig o notation
Big o notation
 
Big O Notation
Big O NotationBig O Notation
Big O Notation
 
Data Structures by Maneesh Boddu
Data Structures by Maneesh BodduData Structures by Maneesh Boddu
Data Structures by Maneesh Boddu
 
computer notes - List implementation
computer notes - List implementationcomputer notes - List implementation
computer notes - List implementation
 
lecture 11
lecture 11lecture 11
lecture 11
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-list
 
Quick sort by Sania Nisar
Quick sort by Sania NisarQuick sort by Sania Nisar
Quick sort by Sania Nisar
 
Searching and sorting Techniques in Data structures
Searching and sorting Techniques in Data structuresSearching and sorting Techniques in Data structures
Searching and sorting Techniques in Data structures
 
An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...
An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...
An Experiment to Determine and Compare Practical Efficiency of Insertion Sort...
 

More from Lovely Professional University

The HyperText Markup Language or HTML is the standard markup language
The HyperText Markup Language or HTML is the standard markup languageThe HyperText Markup Language or HTML is the standard markup language
The HyperText Markup Language or HTML is the standard markup languageLovely Professional University
 

More from Lovely Professional University (20)

The HyperText Markup Language or HTML is the standard markup language
The HyperText Markup Language or HTML is the standard markup languageThe HyperText Markup Language or HTML is the standard markup language
The HyperText Markup Language or HTML is the standard markup language
 
Working with JSON
Working with JSONWorking with JSON
Working with JSON
 
Yargs Module
Yargs ModuleYargs Module
Yargs Module
 
NODEMON Module
NODEMON ModuleNODEMON Module
NODEMON Module
 
Getting Input from User
Getting Input from UserGetting Input from User
Getting Input from User
 
fs Module.pptx
fs Module.pptxfs Module.pptx
fs Module.pptx
 
Transaction Processing in DBMS.pptx
Transaction Processing in DBMS.pptxTransaction Processing in DBMS.pptx
Transaction Processing in DBMS.pptx
 
web_server_browser.ppt
web_server_browser.pptweb_server_browser.ppt
web_server_browser.ppt
 
Web Server.pptx
Web Server.pptxWeb Server.pptx
Web Server.pptx
 
Number System.pptx
Number System.pptxNumber System.pptx
Number System.pptx
 
Programming Language.ppt
Programming Language.pptProgramming Language.ppt
Programming Language.ppt
 
Information System.pptx
Information System.pptxInformation System.pptx
Information System.pptx
 
Applications of Computer Science in Pharmacy-1.pptx
Applications of Computer Science in Pharmacy-1.pptxApplications of Computer Science in Pharmacy-1.pptx
Applications of Computer Science in Pharmacy-1.pptx
 
Application of Computers in Pharmacy.pptx
Application of Computers in Pharmacy.pptxApplication of Computers in Pharmacy.pptx
Application of Computers in Pharmacy.pptx
 
Deploying your app.pptx
Deploying your app.pptxDeploying your app.pptx
Deploying your app.pptx
 
Setting up github and ssh keys.ppt
Setting up github and ssh keys.pptSetting up github and ssh keys.ppt
Setting up github and ssh keys.ppt
 
Adding a New Feature and Deploying.ppt
Adding a New Feature and Deploying.pptAdding a New Feature and Deploying.ppt
Adding a New Feature and Deploying.ppt
 
Requiring your own files.pptx
Requiring your own files.pptxRequiring your own files.pptx
Requiring your own files.pptx
 
Unit-2 Getting Input from User.pptx
Unit-2 Getting Input from User.pptxUnit-2 Getting Input from User.pptx
Unit-2 Getting Input from User.pptx
 
Yargs Module.pptx
Yargs Module.pptxYargs Module.pptx
Yargs Module.pptx
 

Recently uploaded

Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdfSuman Jyoti
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Christo Ananth
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756dollysharma2066
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLManishPatel169454
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesPrabhanshu Chaturvedi
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 

Recently uploaded (20)

Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and Properties
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 

Quick sorting

  • 2. IntroductionIntroduction  Quick sort is an example of divide and conquer algorithm. It was developed in1960 by Tony Hoare. It is a recursive algorithm.The intutive idea is as follows:  Divide:- Choose any element of the list, say the last element as a pivot value. Remove the pivot from the list. Divide the remaining elements into two parts,left and right,such that all the elements equal to or less than the pivot are in the left list, while the elements greater than the pivot are in right list.  Conquer:-Sort the two halves recursively using quick sort.  Combine:-Return sorted_left + pivot + sorted_right,as your final sorted_list.
  • 3. History of Quick Sort AlgorithmHistory of Quick Sort Algorithm  While studying at Moscow State University, Tony Hoare received an offer of employment from  National Physical Laboratory (NPL) to work on new project for machine translation form Russian to English. However ,because dictionaries were sorted into alphabetical order before translation. Hoare thought of two methods to solve this problem.The first method would have taken an amount of time proportional to the square of the length of a sentence. The second method would later manifest as quicksort.  During this course, Hoare programmed an ultra-fast sorting algorithm now known as quicksort. His paper on Quicksort was also published in 1961,with another following in 1962.
  • 4. Example of Quick SortExample of Quick Sort
  • 5. Implementation of code in codeblocksImplementation of code in codeblocks  #include < stdio. h>  void quicksort(int [10],int,int);  int main(){  int x[20], size , i;  printf("Enter size of the array: ");  scanf("%d",&size);  printf("Enter %d elements: ",size);  for(i=0;i<size ; i++)  scanf("% d",& x [i]);  quicksort(x,0,size-1);
  • 6.  return 0;  }  printf("Sorted elements: ");  for(i=0;i<size ; i++)  printf(" %d ", x[ i]);  void quicksort(int x[10],int first,int last){  int pivot,j,temp,i;  if(first<last){  pivot=first;  i=first;  j=last;  while(i<j){  while(x[i]<=x[pivot]&&i<last)
  • 7. Algorithm For Quick SortAlgorithm For Quick Sort  Quick( A, N, Beg, End , Loc)  Here A is an array of N elements .Parameters Beg and End contain the boundary values of the sublist to which this procedure applies. Loc keeps track of the position of the first element A[Beg] of the sublist during the procedure. The local variable Left and Right will contain the boundary values of the list of elements that have not been scanned. 1. [Initialize].Set Left:= Beg, Right:=End and Loc:=Beg. 2. [Scan from right to left] a) Repeat while A[Loc]<=A[Right] and Loc!=Right. Right:=Right-1 [End of Loop] b) If Loc=Right, then: return. c) If A[Loc]>A[Right],then: i. Interchange A[loc] and A[Right]. ii. Set Loc:=Right. iii. Go to Step 3.
  • 8. 3. [Scan from left to right] a) Repeat while A[Left]<=A[Loc] and Left!=Loc: Left :=Left+1. b) If Loc=Left , then return. c) if A[Left]>A[Loc],then i. Interchange A[Left] and A[Loc]. ii. Set Loc:=Left iii. Go to Step 2. [End of if structure].
  • 9.  i++;  while(x[j]>x[pivot])  j--;  if(i<j){  temp=x[i];  x[i]=x[j];  x[j]=temp;}  }  temp=x[pivot];  x[pivot]=x[j];  x[j]=temp;  quicksort(x,first,j-1);  quicksort(x,j+1,last);  }  }
  • 10. ConclusionConclusion We discussed the history of the algorithm. Then implemented the code in codeblocks. Quick sort is an efficient algorithm and has an average running time of O(n*log(n)).While the worst-case running time for quick sort is higher than that of the merge sort, in practice quick sort works slightly faster the the merge sort.