SlideShare a Scribd company logo
1 of 7
Download to read offline
Quick sort: 
29 | 13 | 47 | 25 | 11 | 3 | 9 | 37 
a[] = 
ΕϋϚͯϙϚχϑϋϚώϏϙχϘϘχϟχϙϚώϋϔϛϓψϋϘϙϚϕψϋϙϕϘϚϋϊͨ 
Ίͼͽяͺлтͥкмͥнрͥлоͥккͥмͥтͥмрͻ 
ΝώϋϒϕύϏωψϋώϏϔϊϚώϋϗϛϏωϑϙϕϘϚϏϙϑϔϕϝϔϚϕϛͨΜϕΎϜϋϘϟϕϔϋ 
ωχϔώχϜϋχϊϏόόϋϘϋϔϚϚϟϖϋϕόωϕϊϋψχϙϋϊϕϔϚώχϚϒϕύϏωͨΒϝϏϒϒ 
ϚχϑϋχϔϋϞχϓϖϒϋψχϙϋϊϕϔϓϟωϕϊϋχϔϊϋϞϖϒχϏϔϏϚϚϕϛͨ΋ϛϚϏϚͯϙ 
ϔϕϚϔϋωϋϙϙχϘϟϚώχϚϛϓχϟόϕϒϒϕϝϚώϏϙϕϔϋϕϔϒϟͨ 
ΝώϋϖϘϕύϘχϓ͸ωϕϊϋ͹ωχϔψϋϕόϟϕϛϘϕϝϔωώϕϏωϋͨ 
http://comsciguide.blogspot.com/2014/10/quick-sort-quick-sort- 
is-most-general.html
Quick sort: 
P Q 
Pivot 29 | 13 | 47 | 25 | 11 | 3 | 9 | 37 
΋ϋόϕϘϋύϕϏϔύϚϕϘϋχϊϚώϏϙϙϒϏϊϋͥΒϘϋωϕϓϓϋϔϊϛϚϕ 
ύϕϚώϘϕϛύώϚώϋωϕϊϋϚώχϚϝχϙϏϔϚώϋϒϏϔϑψϋϒϕϝͨ 
ΕϋϚͯϙωϕϔϙϏϊϋϘϚώϋϖϏϜϕϚχϙόϏϘϙϚϋϒϋϓϋϔϚχͼйͽͥϔϋϞϚ 
ϋϒϋϓϋϔϚχͼкͽχϙϖχϔϊϚώϋϒχϙϚϋϒϋϓϋϔϚχϙχͼрͽχϙϗ 
http://comsciguide.blogspot.com/2014/10/quick-sort-quick-sort- 
is-most-general.html
Quick sort: 
while(q=p) 
{ 
while(ia[p]) // pivot=i; 
p++; 
while(ia[q]) 
q--; 
if(qp) 
{ 
t=a[p]; 
a[p]=a[q]; 
a[q]=t; 
} 
} 
http://comsciguide.blogspot.com/2014/10/quick-sort-quick-sort- 
is-most-general.html
Quick sort: 
Do u have doubt why these p and q variables..? 
The p will be looking for the elements that are greater 
than pivot and q for lesser elements. So when p finds a greater 
element, it comes out of the while loop and q finds a lesser 
element it comes out of the loop and these elements are 
interchanged their positions i.e. Swapping . 
http://comsciguide.blogspot.com/2014/10/quick-sort-quick-sort- 
is-most-general.html
Quick sort: 
P Q 
29 | 13 | 47 | 25 | 11 | 3 | 9 | 37 
P Q 
29 | 13 | 47 | 25 | 11 | 3 | 9 | 37 
P Q 
29 | 13 | 9 | 25 | 11 | 3 | 47 | 37 
Before while loop starts : 
After while loop starts : 
Before interchanging : 
After interchanging : 
And this process carry on untill both will meet or 
crossover each other. After the pivot element is 
interchanged with q
Quick sort: 
P Q 
29 | 13 | 9 | 25 | 11 | 3 | 47 | 37 
The next greater element is 47 and lesser element is 3. So if P 
comes to 47 and q comes to 3 ,by this time the two variables 
crossover each other. So there will be no swapping hereafter 
between P and Q. Atlast the q and pivot will be interchanged. 
29 | 13 | 9 | 25 | 11 | 3 | 47 | 37 
P 
Q 
3 | 13 | 9 | 25 | 11 | 29 | 47 | 37 
P 
Q 
Pivot 
Pivot 
Left array 3 | 13 | 9 | 25 | 11 29 47 | 37 Right array
Quick sort: 3 | 13 | 9 | 25 | 11 | 29 | 47 | 37 
Using Recursion 
again the left and 
right elements are 
sorted in the same 
manner. 
3 | 13 | 9 | 25 | 11 29 
47 | 37 
13 | 9 | 25 | 11 37 | 47 
13 | 9 | 11 | 25 
11 | 9 | 13 | 25 
11 | 9 25 
9 | 11 
29 
29 
3 | 9 |11 | 13 | 25 | 29 | 37 | 47 
3 
3 
3 
3 13 
37 | 47 
37 | 47 
37 | 47 
3 13 25 
29 
29 
29 37 | 47 
Finally The sorted array is A[ ] =

More Related Content

What's hot

String Matching (Naive,Rabin-Karp,KMP)
String Matching (Naive,Rabin-Karp,KMP)String Matching (Naive,Rabin-Karp,KMP)
String Matching (Naive,Rabin-Karp,KMP)Aditya pratap Singh
 
String matching algorithms(knuth morris-pratt)
String matching algorithms(knuth morris-pratt)String matching algorithms(knuth morris-pratt)
String matching algorithms(knuth morris-pratt)Neel Shah
 
Iswc 2016 completeness correctude
Iswc 2016 completeness correctudeIswc 2016 completeness correctude
Iswc 2016 completeness correctudeAndré Valdestilhas
 
KMP Pattern Matching algorithm
KMP Pattern Matching algorithmKMP Pattern Matching algorithm
KMP Pattern Matching algorithmKamal Nayan
 
Geom 7point4and5
Geom 7point4and5Geom 7point4and5
Geom 7point4and5herbison
 
Order of operations
Order of operationsOrder of operations
Order of operationsMegan Woods
 
Conclusion math box
Conclusion math boxConclusion math box
Conclusion math boxAmar Cout
 
String Matching Algorithms-The Naive Algorithm
String Matching Algorithms-The Naive AlgorithmString Matching Algorithms-The Naive Algorithm
String Matching Algorithms-The Naive AlgorithmAdeel Rasheed
 
Sequential and Parallel Searching Algorithms
Sequential and Parallel Searching AlgorithmsSequential and Parallel Searching Algorithms
Sequential and Parallel Searching AlgorithmsSuresh Pokharel
 
4.1 planning schedulling
4.1 planning schedulling4.1 planning schedulling
4.1 planning schedullingNatalie Ulza
 

What's hot (17)

String matching algorithms
String matching algorithmsString matching algorithms
String matching algorithms
 
String Matching (Naive,Rabin-Karp,KMP)
String Matching (Naive,Rabin-Karp,KMP)String Matching (Naive,Rabin-Karp,KMP)
String Matching (Naive,Rabin-Karp,KMP)
 
String matching algorithms(knuth morris-pratt)
String matching algorithms(knuth morris-pratt)String matching algorithms(knuth morris-pratt)
String matching algorithms(knuth morris-pratt)
 
Iswc 2016 completeness correctude
Iswc 2016 completeness correctudeIswc 2016 completeness correctude
Iswc 2016 completeness correctude
 
KMP Pattern Matching algorithm
KMP Pattern Matching algorithmKMP Pattern Matching algorithm
KMP Pattern Matching algorithm
 
Geom 7point4and5
Geom 7point4and5Geom 7point4and5
Geom 7point4and5
 
Order of operations
Order of operationsOrder of operations
Order of operations
 
Merge sort
Merge sortMerge sort
Merge sort
 
Rabin karp string matcher
Rabin karp string matcherRabin karp string matcher
Rabin karp string matcher
 
Conclusion math box
Conclusion math boxConclusion math box
Conclusion math box
 
Aitken’s method
Aitken’s methodAitken’s method
Aitken’s method
 
String matching algorithm
String matching algorithmString matching algorithm
String matching algorithm
 
Ch08 pm2ndhalf
Ch08 pm2ndhalfCh08 pm2ndhalf
Ch08 pm2ndhalf
 
String Matching Algorithms-The Naive Algorithm
String Matching Algorithms-The Naive AlgorithmString Matching Algorithms-The Naive Algorithm
String Matching Algorithms-The Naive Algorithm
 
Construction Management
Construction ManagementConstruction Management
Construction Management
 
Sequential and Parallel Searching Algorithms
Sequential and Parallel Searching AlgorithmsSequential and Parallel Searching Algorithms
Sequential and Parallel Searching Algorithms
 
4.1 planning schedulling
4.1 planning schedulling4.1 planning schedulling
4.1 planning schedulling
 

Viewers also liked

Quick sort and binary search PDF
Quick sort and binary search PDFQuick sort and binary search PDF
Quick sort and binary search PDFDivya modi
 
04 ds and algorithm session_05
04 ds and algorithm session_0504 ds and algorithm session_05
04 ds and algorithm session_05Niit Care
 
Quicksort Presentation
Quicksort PresentationQuicksort Presentation
Quicksort Presentationirdginfo
 
Divide and conquer - Quick sort
Divide and conquer - Quick sortDivide and conquer - Quick sort
Divide and conquer - Quick sortMadhu Bala
 
Algorithm: Quick-Sort
Algorithm: Quick-SortAlgorithm: Quick-Sort
Algorithm: Quick-SortTareq Hasan
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1Amrinder Arora
 

Viewers also liked (10)

Quick sort
Quick sortQuick sort
Quick sort
 
Quick sort and binary search PDF
Quick sort and binary search PDFQuick sort and binary search PDF
Quick sort and binary search PDF
 
Quick sort
Quick sortQuick sort
Quick sort
 
04 ds and algorithm session_05
04 ds and algorithm session_0504 ds and algorithm session_05
04 ds and algorithm session_05
 
Quicksort
QuicksortQuicksort
Quicksort
 
Quicksort Presentation
Quicksort PresentationQuicksort Presentation
Quicksort Presentation
 
Divide and conquer - Quick sort
Divide and conquer - Quick sortDivide and conquer - Quick sort
Divide and conquer - Quick sort
 
Quick Sort
Quick SortQuick Sort
Quick Sort
 
Algorithm: Quick-Sort
Algorithm: Quick-SortAlgorithm: Quick-Sort
Algorithm: Quick-Sort
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1
 

More from Ajay Chimmani

24 standard interview puzzles - Secret mail puzzle
24 standard interview puzzles - Secret mail puzzle24 standard interview puzzles - Secret mail puzzle
24 standard interview puzzles - Secret mail puzzleAjay Chimmani
 
24 standard interview puzzles - The pot of beans
24 standard interview puzzles - The pot of beans24 standard interview puzzles - The pot of beans
24 standard interview puzzles - The pot of beansAjay Chimmani
 
24 standard interview puzzles - How strog is an egg
24 standard interview puzzles - How strog is an egg24 standard interview puzzles - How strog is an egg
24 standard interview puzzles - How strog is an eggAjay Chimmani
 
24 standard interview puzzles - 4 men in hats
24 standard interview puzzles - 4 men in hats24 standard interview puzzles - 4 men in hats
24 standard interview puzzles - 4 men in hatsAjay Chimmani
 
Aptitude Training - TIME AND DISTANCE 3
Aptitude Training - TIME AND DISTANCE 3Aptitude Training - TIME AND DISTANCE 3
Aptitude Training - TIME AND DISTANCE 3Ajay Chimmani
 
Aptitude Training - PIPES AND CISTERN
Aptitude Training - PIPES AND CISTERNAptitude Training - PIPES AND CISTERN
Aptitude Training - PIPES AND CISTERNAjay Chimmani
 
Aptitude Training - PROFIT AND LOSS
Aptitude Training - PROFIT AND LOSSAptitude Training - PROFIT AND LOSS
Aptitude Training - PROFIT AND LOSSAjay Chimmani
 
Aptitude Training - SOLID GEOMETRY 1
Aptitude Training - SOLID GEOMETRY 1Aptitude Training - SOLID GEOMETRY 1
Aptitude Training - SOLID GEOMETRY 1Ajay Chimmani
 
Aptitude Training - SIMPLE AND COMPOUND INTEREST
Aptitude Training - SIMPLE AND COMPOUND INTERESTAptitude Training - SIMPLE AND COMPOUND INTEREST
Aptitude Training - SIMPLE AND COMPOUND INTERESTAjay Chimmani
 
Aptitude Training - TIME AND DISTANCE 4
Aptitude Training - TIME AND DISTANCE 4Aptitude Training - TIME AND DISTANCE 4
Aptitude Training - TIME AND DISTANCE 4Ajay Chimmani
 
Aptitude Training - TIME AND DISTANCE 1
Aptitude Training - TIME AND DISTANCE 1Aptitude Training - TIME AND DISTANCE 1
Aptitude Training - TIME AND DISTANCE 1Ajay Chimmani
 
Aptitude Training - PROBLEMS ON CUBES
Aptitude Training - PROBLEMS ON CUBESAptitude Training - PROBLEMS ON CUBES
Aptitude Training - PROBLEMS ON CUBESAjay Chimmani
 
Aptitude Training - RATIO AND PROPORTION 1
Aptitude Training - RATIO AND PROPORTION 1Aptitude Training - RATIO AND PROPORTION 1
Aptitude Training - RATIO AND PROPORTION 1Ajay Chimmani
 
Aptitude Training - PROBABILITY
Aptitude Training - PROBABILITYAptitude Training - PROBABILITY
Aptitude Training - PROBABILITYAjay Chimmani
 
Aptitude Training - RATIO AND PROPORTION 4
Aptitude Training - RATIO AND PROPORTION 4Aptitude Training - RATIO AND PROPORTION 4
Aptitude Training - RATIO AND PROPORTION 4Ajay Chimmani
 
Aptitude Training - NUMBERS
Aptitude Training - NUMBERSAptitude Training - NUMBERS
Aptitude Training - NUMBERSAjay Chimmani
 
Aptitude Training - RATIO AND PROPORTION 2
Aptitude Training - RATIO AND PROPORTION 2Aptitude Training - RATIO AND PROPORTION 2
Aptitude Training - RATIO AND PROPORTION 2Ajay Chimmani
 
Aptitude Training - PERMUTATIONS AND COMBINATIONS 2
Aptitude Training - PERMUTATIONS AND COMBINATIONS 2Aptitude Training - PERMUTATIONS AND COMBINATIONS 2
Aptitude Training - PERMUTATIONS AND COMBINATIONS 2Ajay Chimmani
 
Aptitude Training - PERCENTAGE 2
Aptitude Training - PERCENTAGE 2Aptitude Training - PERCENTAGE 2
Aptitude Training - PERCENTAGE 2Ajay Chimmani
 
Aptitude Training - PERCENTAGE 1
Aptitude Training - PERCENTAGE 1Aptitude Training - PERCENTAGE 1
Aptitude Training - PERCENTAGE 1Ajay Chimmani
 

More from Ajay Chimmani (20)

24 standard interview puzzles - Secret mail puzzle
24 standard interview puzzles - Secret mail puzzle24 standard interview puzzles - Secret mail puzzle
24 standard interview puzzles - Secret mail puzzle
 
24 standard interview puzzles - The pot of beans
24 standard interview puzzles - The pot of beans24 standard interview puzzles - The pot of beans
24 standard interview puzzles - The pot of beans
 
24 standard interview puzzles - How strog is an egg
24 standard interview puzzles - How strog is an egg24 standard interview puzzles - How strog is an egg
24 standard interview puzzles - How strog is an egg
 
24 standard interview puzzles - 4 men in hats
24 standard interview puzzles - 4 men in hats24 standard interview puzzles - 4 men in hats
24 standard interview puzzles - 4 men in hats
 
Aptitude Training - TIME AND DISTANCE 3
Aptitude Training - TIME AND DISTANCE 3Aptitude Training - TIME AND DISTANCE 3
Aptitude Training - TIME AND DISTANCE 3
 
Aptitude Training - PIPES AND CISTERN
Aptitude Training - PIPES AND CISTERNAptitude Training - PIPES AND CISTERN
Aptitude Training - PIPES AND CISTERN
 
Aptitude Training - PROFIT AND LOSS
Aptitude Training - PROFIT AND LOSSAptitude Training - PROFIT AND LOSS
Aptitude Training - PROFIT AND LOSS
 
Aptitude Training - SOLID GEOMETRY 1
Aptitude Training - SOLID GEOMETRY 1Aptitude Training - SOLID GEOMETRY 1
Aptitude Training - SOLID GEOMETRY 1
 
Aptitude Training - SIMPLE AND COMPOUND INTEREST
Aptitude Training - SIMPLE AND COMPOUND INTERESTAptitude Training - SIMPLE AND COMPOUND INTEREST
Aptitude Training - SIMPLE AND COMPOUND INTEREST
 
Aptitude Training - TIME AND DISTANCE 4
Aptitude Training - TIME AND DISTANCE 4Aptitude Training - TIME AND DISTANCE 4
Aptitude Training - TIME AND DISTANCE 4
 
Aptitude Training - TIME AND DISTANCE 1
Aptitude Training - TIME AND DISTANCE 1Aptitude Training - TIME AND DISTANCE 1
Aptitude Training - TIME AND DISTANCE 1
 
Aptitude Training - PROBLEMS ON CUBES
Aptitude Training - PROBLEMS ON CUBESAptitude Training - PROBLEMS ON CUBES
Aptitude Training - PROBLEMS ON CUBES
 
Aptitude Training - RATIO AND PROPORTION 1
Aptitude Training - RATIO AND PROPORTION 1Aptitude Training - RATIO AND PROPORTION 1
Aptitude Training - RATIO AND PROPORTION 1
 
Aptitude Training - PROBABILITY
Aptitude Training - PROBABILITYAptitude Training - PROBABILITY
Aptitude Training - PROBABILITY
 
Aptitude Training - RATIO AND PROPORTION 4
Aptitude Training - RATIO AND PROPORTION 4Aptitude Training - RATIO AND PROPORTION 4
Aptitude Training - RATIO AND PROPORTION 4
 
Aptitude Training - NUMBERS
Aptitude Training - NUMBERSAptitude Training - NUMBERS
Aptitude Training - NUMBERS
 
Aptitude Training - RATIO AND PROPORTION 2
Aptitude Training - RATIO AND PROPORTION 2Aptitude Training - RATIO AND PROPORTION 2
Aptitude Training - RATIO AND PROPORTION 2
 
Aptitude Training - PERMUTATIONS AND COMBINATIONS 2
Aptitude Training - PERMUTATIONS AND COMBINATIONS 2Aptitude Training - PERMUTATIONS AND COMBINATIONS 2
Aptitude Training - PERMUTATIONS AND COMBINATIONS 2
 
Aptitude Training - PERCENTAGE 2
Aptitude Training - PERCENTAGE 2Aptitude Training - PERCENTAGE 2
Aptitude Training - PERCENTAGE 2
 
Aptitude Training - PERCENTAGE 1
Aptitude Training - PERCENTAGE 1Aptitude Training - PERCENTAGE 1
Aptitude Training - PERCENTAGE 1
 

Recently uploaded

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
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
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
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
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
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.pdfQucHHunhnh
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
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
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 

Recently uploaded (20)

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
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
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
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
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.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
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
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
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 

Quicksort

  • 1. Quick sort: 29 | 13 | 47 | 25 | 11 | 3 | 9 | 37 a[] = ΕϋϚͯϙϚχϑϋϚώϏϙχϘϘχϟχϙϚώϋϔϛϓψϋϘϙϚϕψϋϙϕϘϚϋϊͨ Ίͼͽяͺлтͥкмͥнрͥлоͥккͥмͥтͥмрͻ ΝώϋϒϕύϏωψϋώϏϔϊϚώϋϗϛϏωϑϙϕϘϚϏϙϑϔϕϝϔϚϕϛͨΜϕΎϜϋϘϟϕϔϋ ωχϔώχϜϋχϊϏόόϋϘϋϔϚϚϟϖϋϕόωϕϊϋψχϙϋϊϕϔϚώχϚϒϕύϏωͨΒϝϏϒϒ ϚχϑϋχϔϋϞχϓϖϒϋψχϙϋϊϕϔϓϟωϕϊϋχϔϊϋϞϖϒχϏϔϏϚϚϕϛͨ΋ϛϚϏϚͯϙ ϔϕϚϔϋωϋϙϙχϘϟϚώχϚϛϓχϟόϕϒϒϕϝϚώϏϙϕϔϋϕϔϒϟͨ ΝώϋϖϘϕύϘχϓ͸ωϕϊϋ͹ωχϔψϋϕόϟϕϛϘϕϝϔωώϕϏωϋͨ http://comsciguide.blogspot.com/2014/10/quick-sort-quick-sort- is-most-general.html
  • 2. Quick sort: P Q Pivot 29 | 13 | 47 | 25 | 11 | 3 | 9 | 37 ΋ϋόϕϘϋύϕϏϔύϚϕϘϋχϊϚώϏϙϙϒϏϊϋͥΒϘϋωϕϓϓϋϔϊϛϚϕ ύϕϚώϘϕϛύώϚώϋωϕϊϋϚώχϚϝχϙϏϔϚώϋϒϏϔϑψϋϒϕϝͨ ΕϋϚͯϙωϕϔϙϏϊϋϘϚώϋϖϏϜϕϚχϙόϏϘϙϚϋϒϋϓϋϔϚχͼйͽͥϔϋϞϚ ϋϒϋϓϋϔϚχͼкͽχϙϖχϔϊϚώϋϒχϙϚϋϒϋϓϋϔϚχϙχͼрͽχϙϗ http://comsciguide.blogspot.com/2014/10/quick-sort-quick-sort- is-most-general.html
  • 3. Quick sort: while(q=p) { while(ia[p]) // pivot=i; p++; while(ia[q]) q--; if(qp) { t=a[p]; a[p]=a[q]; a[q]=t; } } http://comsciguide.blogspot.com/2014/10/quick-sort-quick-sort- is-most-general.html
  • 4. Quick sort: Do u have doubt why these p and q variables..? The p will be looking for the elements that are greater than pivot and q for lesser elements. So when p finds a greater element, it comes out of the while loop and q finds a lesser element it comes out of the loop and these elements are interchanged their positions i.e. Swapping . http://comsciguide.blogspot.com/2014/10/quick-sort-quick-sort- is-most-general.html
  • 5. Quick sort: P Q 29 | 13 | 47 | 25 | 11 | 3 | 9 | 37 P Q 29 | 13 | 47 | 25 | 11 | 3 | 9 | 37 P Q 29 | 13 | 9 | 25 | 11 | 3 | 47 | 37 Before while loop starts : After while loop starts : Before interchanging : After interchanging : And this process carry on untill both will meet or crossover each other. After the pivot element is interchanged with q
  • 6. Quick sort: P Q 29 | 13 | 9 | 25 | 11 | 3 | 47 | 37 The next greater element is 47 and lesser element is 3. So if P comes to 47 and q comes to 3 ,by this time the two variables crossover each other. So there will be no swapping hereafter between P and Q. Atlast the q and pivot will be interchanged. 29 | 13 | 9 | 25 | 11 | 3 | 47 | 37 P Q 3 | 13 | 9 | 25 | 11 | 29 | 47 | 37 P Q Pivot Pivot Left array 3 | 13 | 9 | 25 | 11 29 47 | 37 Right array
  • 7. Quick sort: 3 | 13 | 9 | 25 | 11 | 29 | 47 | 37 Using Recursion again the left and right elements are sorted in the same manner. 3 | 13 | 9 | 25 | 11 29 47 | 37 13 | 9 | 25 | 11 37 | 47 13 | 9 | 11 | 25 11 | 9 | 13 | 25 11 | 9 25 9 | 11 29 29 3 | 9 |11 | 13 | 25 | 29 | 37 | 47 3 3 3 3 13 37 | 47 37 | 47 37 | 47 3 13 25 29 29 29 37 | 47 Finally The sorted array is A[ ] =