• Like
Chapter 14 quick_sort
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Chapter 14 quick_sort

  • 1,134 views
Published

 

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
1,134
On SlideShare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
23
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Java Programming: From Problem Analysis to Program Design, 4e Chapter 14 Quick Sort
  • 2. Objectives
    • Explore how to sort an array using quick sort
  • 3. Sorting a List
    • Quick sort
  • 4. Quick Sort
  • 5. Quick Sort (continued)
    • Several ways to determine pivot
    • Pivot is chosen so that, it is hoped, lowerSublist and upperSublist are of nearly equal size
    • The choice of pivot affects the performance of the algorithm
    • We choose the middle element of the list as pivot
  • 6. Quick Sort (continued)
    • The partition procedure that we describe partitions this list using pivot as the middle element, in our case 50, as shown in Figure Q-2
  • 7. Quick Sort (continued)
    • Partition algorithm:
    • Determine pivot , and swap pivot with the first element
    • of the list.
    • Suppose that the index smallIndex points to the last element less than pivot . The index smallIndex is initialized to the first element of the list.
    • 2. For the remaining elements in the list (starting at the
    • second element): If the current element is less than pivot
      • a. Increment smallIndex .
      • b. Swap the current element with the array element
      • pointed to by smallIndex .
    • 3. Swap the first element, that is, pivot , with the array
    • element pointed to by smallIndex .
  • 8. Quick Sort (continued)
  • 9. Quick Sort (continued)
  • 10. Quick Sort (continued)
  • 11. Quick Sort (continued)
  • 12. Quick Sort (continued)
  • 13. Quick Sort (continued)
  • 14. Quick Sort (continued)
  • 15. Quick Sort (continued)