SlideShare a Scribd company logo
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

PPTX
PPTX
Hashing Techniques in Data Structures Part2
PDF
Hashing Algorithm
PPTX
Greatest integer
PPTX
Actividad 1
PPT
AREA DE FIGURAS PLANAS
PDF
Inaugural Addresses
PDF
Teaching Students with Emojis, Emoticons, & Textspeak
Hashing Techniques in Data Structures Part2
Hashing Algorithm
Greatest integer
Actividad 1
AREA DE FIGURAS PLANAS
Inaugural Addresses
Teaching Students with Emojis, Emoticons, & Textspeak

Similar to Quick sort demo (20)

PPTX
Quick sort
PPTX
Quick sort
PPTX
Unit 2 - Quick Sort.pptx
PPTX
Quick_sort1.pptx
PPTX
Sortings .pptx
PPT
3.8 quick sort
PPTX
Sorting and Searching - Data Structure - Notes
PPTX
Quick sort-Data Structure
PDF
Quick sort-170316064200
PDF
Sorting
PDF
Sorting
PPTX
Divide-and-conquer
PPTX
Unit 5 internal sorting &amp; files
PPTX
Searching and Sorting algorithms and working
PDF
CS253: Divide & Conquer Sort (2019)
PPTX
Sorting ppt
PPTX
Quick sort by Sania Nisar
XLSX
Data Structures : Sorting
Quick sort
Quick sort
Unit 2 - Quick Sort.pptx
Quick_sort1.pptx
Sortings .pptx
3.8 quick sort
Sorting and Searching - Data Structure - Notes
Quick sort-Data Structure
Quick sort-170316064200
Sorting
Sorting
Divide-and-conquer
Unit 5 internal sorting &amp; files
Searching and Sorting algorithms and working
CS253: Divide & Conquer Sort (2019)
Sorting ppt
Quick sort by Sania Nisar
Data Structures : Sorting
Ad

Recently uploaded (20)

PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PPTX
Lesson notes of climatology university.
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
RMMM.pdf make it easy to upload and study
PDF
Indian roads congress 037 - 2012 Flexible pavement
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PPTX
Digestion and Absorption of Carbohydrates, Proteina and Fats
PDF
Hazard Identification & Risk Assessment .pdf
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PPTX
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
PPTX
Cell Types and Its function , kingdom of life
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
Computing-Curriculum for Schools in Ghana
PDF
1_English_Language_Set_2.pdf probationary
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
Orientation - ARALprogram of Deped to the Parents.pptx
Lesson notes of climatology university.
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Supply Chain Operations Speaking Notes -ICLT Program
RMMM.pdf make it easy to upload and study
Indian roads congress 037 - 2012 Flexible pavement
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
Digestion and Absorption of Carbohydrates, Proteina and Fats
Hazard Identification & Risk Assessment .pdf
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
A powerpoint presentation on the Revised K-10 Science Shaping Paper
Paper A Mock Exam 9_ Attempt review.pdf.
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
Cell Types and Its function , kingdom of life
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Computing-Curriculum for Schools in Ghana
1_English_Language_Set_2.pdf probationary
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
Ad

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

  • #3: Scanning from right to left the first number visited that has value less 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
  • #7: Scanning from left to right the first number visited that has value greater than 51, thus exchange both of them
  • #8: Scanning from right to left the first number visited that has value less than 51, thus exchange both of them