190 likes | 201 Views
Learn how to efficiently partition an array in Quicksort by choosing the rightmost element as the partition element, scanning from the right for smaller elements, scanning from the left for larger elements, exchanging elements, and repeating until the pointers cross.
E N D
Partitioning in Quicksort • How do we partition the array efficiently? • choose partition element to be rightmost element • scan from right for smaller element • scan from left for larger element • exchange • repeat until pointers cross
Partitioning in Quicksort swap me • How do we partition the array efficiently? • choose partition element to be rightmost element • scan from right for smaller element • scan from left for larger element • exchange • repeat until pointers cross
Partitioning in Quicksort swap me • How do we partition the array efficiently? • choose partition element to be rightmost element • scan from right for smaller element • scan from left for larger element • exchange • repeat until pointers cross
Partitioning in Quicksort swap me • How do we partition the array efficiently? • choose partition element to be rightmost element • scan from right for smaller element • scan from left for larger element • exchange • repeat until pointers cross
Partitioning in Quicksort swap me swap me • How do we partition the array efficiently? • choose partition element to be rightmost element • scan from right for smaller element • scan from left for larger element • exchange • repeat until pointers cross
Partitioning in Quicksort • How do we partition the array efficiently? • choose partition element to be rightmost element • scan from right for smaller element • scan from left for larger element • exchange • repeat until pointers cross
Partitioning in Quicksort swap me • How do we partition the array efficiently? • choose partition element to be rightmost element • scan from right for smaller element • scan from left for larger element • exchange • repeat until pointers cross
Partitioning in Quicksort swap me • How do we partition the array efficiently? • choose partition element to be rightmost element • scan from right for smaller element • scan from left for larger element • exchange • repeat until pointers cross
Partitioning in Quicksort swap me swap me • How do we partition the array efficiently? • choose partition element to be rightmost element • scan from right for smaller element • scan from left for larger element • exchange • repeat until pointers cross
Partitioning in Quicksort • How do we partition the array efficiently? • choose partition element to be rightmost element • scan from right for smaller element • scan from left for larger element • exchange • repeat until pointers cross
Partitioning in Quicksort • How do we partition the array efficiently? • choose partition element to be rightmost element • scan from right for smaller element • scan from left for larger element • exchange • repeat until pointers cross
Partitioning in Quicksort • How do we partition the array efficiently? • choose partition element to be rightmost element • scan from right for smaller element • scan from left for larger element • exchange • repeat until pointers cross
Partitioning in Quicksort • How do we partition the array efficiently? • choose partition element to be rightmost element • scan from right for smaller element • scan from left for larger element • exchange • repeat until pointers cross
Partitioning in Quicksort swap me • How do we partition the array efficiently? • choose partition element to be rightmost element • scan from right for smaller element • scan from left for larger element • exchange • repeat until pointers cross
Partitioning in Quicksort swap me • How do we partition the array efficiently? • choose partition element to be rightmost element • scan from right for smaller element • scan from left for larger element • exchange • repeat until pointers cross
Partitioning in Quicksort swap me • How do we partition the array efficiently? • choose partition element to be rightmost element • scan from right for smaller element • scan from left for larger element • exchange • repeat until pointers cross
Partitioning in Quicksort swap me • How do we partition the array efficiently? • choose partition element to be rightmost element • scan from right for smaller element • scan from left for larger element • exchange • repeat until pointers cross
Partitioning in Quicksort • How do we partition the array efficiently? • choose partition element to be rightmost element • scan from right for smaller element • scan from left for larger element • exchange • repeat until pointers cross swap with partitioning element pointers cross
Partitioning in Quicksort • How do we partition the array efficiently? • choose partition element to be rightmost element • scan from right for smaller element • scan from left for larger element • exchange • repeat until pointers cross