Quick sort demo

121 views
93 views

Published on

qa.zariga.com

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
121
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Scanning from right to left the first number visited that has value less than 51, thus exchange both of them
  • Scanning from right to left the first number visited that has value less than 51, thus exchange both of them
  • Scanning from left to right the first number visited that has value greater than 51, thus exchange both of them
  • Scanning from right to left the first number visited that has value less than 51, thus exchange both of them
  • Scanning from left to right the first number visited that has value greater than 51, thus exchange both of them
  • Scanning from right to left the first number visited that has value less than 51, thus exchange both of them
  • Quick sort demo

    1. 1. Quick Sort DemoAnishqa.zariga.com
    2. 2. Quick SortA[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 76qa.zariga.com1. Divide and Conquer design.2. It works recursively3. Choose a Pivot element in an array(Random)Pivot4. Place this element in such a way, thearray list will get divided into two sublistso that pivot element will be greater thanfirst sublist and less than other sublist
    3. 3. Quick Sort Scanning from right to left the firstnumber visited that has value less than 51, thusexchange both of themIteration=1A[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 76startLeft to right searchthe number whichless that 51 swapA[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.comPivotElement
    4. 4. Quick Sort Scanning from left to right the firstnumber visited that has value greater than 51, thusexchange both of themIteration=2A[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 76startRight to left search51<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 76qa.zariga.com
    5. 5. Quick Sort Scanning from right to left the firstnumber visited that has value less than 51, thusexchange both of themIteration=3A[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 76startA[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 76qa.zariga.com
    6. 6. Quick Sort Scanning from left to right the firstnumber visited that has value greater than 51, thusexchange both of themIteration=4A[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 76A[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 76qa.zariga.com
    7. 7. Quick Sort Scanning from right to left the firstnumber visited that has value less than 51, thusexchange both of themIteration=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 76start51 >A[n]No Element FoundScanning from left to right the first number visited that has value greater than 51,thus exchange both of them51<A[n]No Element FoundA[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 76qa.zariga.com
    8. 8. Quick Sort The Number 51 is Placedto proper PositionA[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 76Sublist1 has valueless than 51Sublist1 has valuegreater than 511. The Whole Process is repeated forboth Sublist1 and Sublis22. The Final List what we get as SortedListA[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 105qa.zariga.com
    9. 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 ofsize n/22qa.zariga.com
    10. 10. ThanksVisitzariga.comqa.zariga.comyoutube.com/zarigatongy/qa.zariga.com

    ×