1 / 19

Efficient In-Place Partitioning in Quicksort

This article explores the in-place partitioning technique used in the Quicksort algorithm. It details how to efficiently partition an array by selecting the rightmost element as the pivot. The process involves scanning the array from both ends, swapping larger and smaller elements appropriately until pointers cross. The aim is to achieve a divided array where elements on the left of the pivot are smaller and those on the right are larger, facilitating efficient sorting. Understanding this method is crucial for implementing the Quicksort algorithm effectively.

willis
Télécharger la présentation

Efficient In-Place Partitioning in Quicksort

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Q U I C K S O R T I S C O O L partition element unpartitioned left partitioned right Partitioning in Quicksort • How do we partition in-place efficiently? • Partition element = rightmost element. • Scan from left for larger element. • Scan from right for smaller element. • Exchange. • Repeat until pointers cross.

  2. swap me partition element unpartitioned left partitioned right Partitioning in Quicksort • How do we partition in-place efficiently? • Partition element = rightmost element. • Scan from left for larger element. • Scan from right for smaller element. • Exchange. • Repeat until pointers cross. Q U I C K S O R T I S C O O L

  3. swap me partition element unpartitioned left partitioned right Partitioning in Quicksort • How do we partition in-place efficiently? • Partition element = rightmost element. • Scan from left for larger element. • Scan from right for smaller element. • Exchange. • Repeat until pointers cross. Q U I C K S O R T I S C O O L

  4. swap me partition element unpartitioned left partitioned right Partitioning in Quicksort • How do we partition in-place efficiently? • Partition element = rightmost element. • Scan from left for larger element. • Scan from right for smaller element. • Exchange. • Repeat until pointers cross. Q U I C K S O R T I S C O O L

  5. swap me swap me partition element unpartitioned left partitioned right Partitioning in Quicksort • How do we partition in-place efficiently? • Partition element = rightmost element. • Scan from left for larger element. • Scan from right for smaller element. • Exchange. • Repeat until pointers cross. Q U I C K S O R T I S C O O L

  6. partition element unpartitioned left partitioned right Partitioning in Quicksort • How do we partition in-place efficiently? • Partition element = rightmost element. • Scan from left for larger element. • Scan from right for smaller element. • Exchange. • Repeat until pointers cross. C U I C K S O R T I S Q O O L

  7. swap me partition element unpartitioned left partitioned right Partitioning in Quicksort • How do we partition in-place efficiently? • Partition element = rightmost element. • Scan from left for larger element. • Scan from right for smaller element. • Exchange. • Repeat until pointers cross. C U I C K S O R T I S Q O O L

  8. swap me partition element unpartitioned left partitioned right Partitioning in Quicksort • How do we partition in-place efficiently? • Partition element = rightmost element. • Scan from left for larger element. • Scan from right for smaller element. • Exchange. • Repeat until pointers cross. C U I C K S O R T I S Q O O L

  9. swap me swap me partition element unpartitioned left partitioned right Partitioning in Quicksort • How do we partition in-place efficiently? • Partition element = rightmost element. • Scan from left for larger element. • Scan from right for smaller element. • Exchange. • Repeat until pointers cross. C U I C K S O R T I S Q O O L

  10. partition element unpartitioned left partitioned right Partitioning in Quicksort • How do we partition in-place efficiently? • Partition element = rightmost element. • Scan from left for larger element. • Scan from right for smaller element. • Exchange. • Repeat until pointers cross. C I I C K S O R T U S Q O O L

  11. partition element unpartitioned left partitioned right Partitioning in Quicksort • How do we partition in-place efficiently? • Partition element = rightmost element. • Scan from left for larger element. • Scan from right for smaller element. • Exchange. • Repeat until pointers cross. C I I C K S O R T U S Q O O L

  12. partition element unpartitioned left partitioned right Partitioning in Quicksort • How do we partition in-place efficiently? • Partition element = rightmost element. • Scan from left for larger element. • Scan from right for smaller element. • Exchange. • Repeat until pointers cross. C I I C K S O R T U S Q O O L

  13. partition element unpartitioned left partitioned right Partitioning in Quicksort • How do we partition in-place efficiently? • Partition element = rightmost element. • Scan from left for larger element. • Scan from right for smaller element. • Exchange. • Repeat until pointers cross. C I I C K S O R T U S Q O O L

  14. swap me partition element unpartitioned left partitioned right Partitioning in Quicksort • How do we partition in-place efficiently? • Partition element = rightmost element. • Scan from left for larger element. • Scan from right for smaller element. • Exchange. • Repeat until pointers cross. C I I C K S O R T U S Q O O L

  15. swap me partition element unpartitioned left partitioned right Partitioning in Quicksort • How do we partition in-place efficiently? • Partition element = rightmost element. • Scan from left for larger element. • Scan from right for smaller element. • Exchange. • Repeat until pointers cross. C I I C K S O R T U S Q O O L

  16. swap me partition element unpartitioned left partitioned right Partitioning in Quicksort • How do we partition in-place efficiently? • Partition element = rightmost element. • Scan from left for larger element. • Scan from right for smaller element. • Exchange. • Repeat until pointers cross. C I I C K S O R T U S Q O O L

  17. swap me partition element unpartitioned left partitioned right Partitioning in Quicksort • How do we partition in-place efficiently? • Partition element = rightmost element. • Scan from left for larger element. • Scan from right for smaller element. • Exchange. • Repeat until pointers cross. C I I C K S O R T U S Q O O L

  18. partition element unpartitioned left partitioned right Partitioning in Quicksort • How do we partition in-place efficiently? • Partition element = rightmost element. • Scan from left for larger element. • Scan from right for smaller element. • Exchange. • Repeat until pointers cross. swap with partitioning element pointers cross C I I C K S O R T U S Q O O L

  19. partition element unpartitioned left partitioned right Partitioning in Quicksort • How do we partition in-place efficiently? • Partition element = rightmost element. • Scan from left for larger element. • Scan from right for smaller element. • Exchange. • Repeat until pointers cross. partition is complete C I I C K L O R T U S Q O O S

More Related