SlideShare a Scribd company logo
1 of 10
Quick Sort Demo
Anish
qa.zariga.com
Quick Sort
A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[10] A[11] A[12]
51 41 21 61 81 101 46 71 105 31 91 76
qa.zariga.com
1. Divide and Conquer design.
2. It works recursively
3. Choose a Pivot element in an array
(Random)
P
i
v
o
t
4. Place this element in such a way, the
array list will get divided into two sublist
so that pivot element will be greater than
first sublist and less than other sublist
Quick Sort Scanning from right to left the first
number visited that has value less than 51, thus
exchange both of them
Iteration=1
A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[10] A[11] A[12]
51 41 21 61 81 101 46 71 105 31 91 76
s
t
a
r
t
Left to right search
the number which
less that 51 swap
A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[10] A[11] A[12]
31 41 21 61 81 101 46 71 105 51 91 76qa.zariga.com
Pivot
Element
Quick Sort Scanning from left to right the first
number visited that has value greater than 51, thus
exchange both of them
Iteration=2
A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[10] A[11] A[12]
31 41 21 61 81 101 46 71 105 51 91 76
s
t
a
r
t
Right to left search
51<A[n]
A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[10] A[11] A[12]
31 41 21 51 81 101 46 71 105 61 91 76
qa.zariga.com
Quick Sort Scanning from right to left the first
number visited that has value less than 51, thus
exchange both of them
Iteration=3
A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[10] A[11] A[12]
31 41 21 51 81 101 46 71 105 61 91 76
s
t
a
r
t
A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[10] A[11] A[12]
31 41 21 46 81 101 51 71 105 61 91 76
qa.zariga.com
Quick Sort Scanning from left to right the first
number visited that has value greater than 51, thus
exchange both of them
Iteration=4
A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[10] A[11] A[12]
31 41 21 46 81 101 51 71 105 61 91 76
A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[10] A[11] A[12]
31 41 21 46 51 101 81 71 105 61 91 76
qa.zariga.com
Quick Sort Scanning from right to left the first
number visited that has value less than 51, thus
exchange both of them
Iteration=6A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[10] A[11] A[12]
31 41 21 46 51 101 81 71 105 61 91 76
s
t
a
r
t
51 >A[n]
No Element Found
Scanning from left to right the first number visited that has value greater than 51,
thus exchange both of them
51<A[n]
No Element Found
A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[10] A[11] A[12]
31 41 21 46 51 101 81 71 105 61 91 76
qa.zariga.com
Quick Sort The Number 51 is Placed
to proper Position
A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[10] A[11] A[12]
31 41 21 46 51 101 81 71 105 61 91 76
Sublist1 has value
less than 51
Sublist1 has value
greater than 51
1. The Whole Process is repeated for
both Sublist1 and Sublis2
2. The Final List what we get as Sorted
List
A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[10] A[11] A[12]
21 31 41 46 51 61 71 76 81 91 101 105
qa.zariga.com
Quick Sort Analysis
• Worst Case O(n )
– Pivot is the Smallest or Largest element in Array
• Worst Case O(nlogn )
– Each Array is divided into two equla subarray of
size n/2
2
qa.zariga.com
Thanks
Visit
zariga.com
qa.zariga.com
youtube.com/zarigatongy/
qa.zariga.com

More Related Content

Recently uploaded

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
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
 
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
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

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
 
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
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
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
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
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
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
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...
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 

Featured

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Quick sort demo

  • 2. Quick Sort A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[10] A[11] A[12] 51 41 21 61 81 101 46 71 105 31 91 76 qa.zariga.com 1. Divide and Conquer design. 2. It works recursively 3. Choose a Pivot element in an array (Random) P i v o t 4. Place this element in such a way, the array list will get divided into two sublist so that pivot element will be greater than first sublist and less than other sublist
  • 3. Quick Sort Scanning from right to left the first number visited that has value less than 51, thus exchange both of them Iteration=1 A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[10] A[11] A[12] 51 41 21 61 81 101 46 71 105 31 91 76 s t a r t Left to right search the number which less that 51 swap A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[10] A[11] A[12] 31 41 21 61 81 101 46 71 105 51 91 76qa.zariga.com Pivot Element
  • 4. Quick Sort Scanning from left to right the first number visited that has value greater than 51, thus exchange both of them Iteration=2 A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[10] A[11] A[12] 31 41 21 61 81 101 46 71 105 51 91 76 s t a r t Right to left search 51<A[n] A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[10] A[11] A[12] 31 41 21 51 81 101 46 71 105 61 91 76 qa.zariga.com
  • 5. Quick Sort Scanning from right to left the first number visited that has value less than 51, thus exchange both of them Iteration=3 A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[10] A[11] A[12] 31 41 21 51 81 101 46 71 105 61 91 76 s t a r t A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[10] A[11] A[12] 31 41 21 46 81 101 51 71 105 61 91 76 qa.zariga.com
  • 6. Quick Sort Scanning from left to right the first number visited that has value greater than 51, thus exchange both of them Iteration=4 A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[10] A[11] A[12] 31 41 21 46 81 101 51 71 105 61 91 76 A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[10] A[11] A[12] 31 41 21 46 51 101 81 71 105 61 91 76 qa.zariga.com
  • 7. Quick Sort Scanning from right to left the first number visited that has value less than 51, thus exchange both of them Iteration=6A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[10] A[11] A[12] 31 41 21 46 51 101 81 71 105 61 91 76 s t a r t 51 >A[n] No Element Found Scanning from left to right the first number visited that has value greater than 51, thus exchange both of them 51<A[n] No Element Found A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[10] A[11] A[12] 31 41 21 46 51 101 81 71 105 61 91 76 qa.zariga.com
  • 8. Quick Sort The Number 51 is Placed to proper Position A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[10] A[11] A[12] 31 41 21 46 51 101 81 71 105 61 91 76 Sublist1 has value less than 51 Sublist1 has value greater than 51 1. The Whole Process is repeated for both Sublist1 and Sublis2 2. The Final List what we get as Sorted List A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[10] A[11] A[12] 21 31 41 46 51 61 71 76 81 91 101 105 qa.zariga.com
  • 9. Quick Sort Analysis • Worst Case O(n ) – Pivot is the Smallest or Largest element in Array • Worst Case O(nlogn ) – Each Array is divided into two equla subarray of size n/2 2 qa.zariga.com

Editor's Notes

  1. Scanning from right to left the first number visited that has value less than 51, thus exchange both of them
  2. Scanning from right to left the first number visited that has value less than 51, thus exchange both of them
  3. Scanning from left to right the first number visited that has value greater than 51, thus exchange both of them
  4. Scanning from right to left the first number visited that has value less than 51, thus exchange both of them
  5. Scanning from left to right the first number visited that has value greater than 51, thus exchange both of them
  6. Scanning from right to left the first number visited that has value less than 51, thus exchange both of them