Your SlideShare is downloading. ×
  • Like
9781439035665 ppt ch14_bubble_sort
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

9781439035665 ppt ch14_bubble_sort

  • 995 views
Published

 

Published in Education
  • 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
995
On SlideShare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
15
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 Bubble Sort
  • 2. Objectives
    • Explore how to sort an array using bubble sort
  • 3. Sorting a List
    • Bubble sort
      • Suppose list[0...n - 1] is a list of n elements, indexed 0 to n - 1
      • We want to rearrange, that is, sort the elements of list in increasing order
      • The bubble sort algorithm works as follows:
        • In a series of n - 1 iterations, the successive elements list[index] and list[index + 1] of list are compared
        • If list[index] is greater than list[index + 1] , then the elements list[index] and list[index + 1] are swapped, that is, interchanged
  • 4. Bubble Sort
  • 5. Bubble Sort (continued)
  • 6. Bubble Sort (continued)
  • 7. Bubble Sort (continued)
  • 8. Bubble Sort (continued)
  • 9. Bubble Sort (continued)
  • 10. Bubble Sort (continued)
    • It is known that for a list of length n , on average bubble sort makes n ( n – 1) / 2 key comparisons and about n ( n – 1) / 4 item assignments
    • Therefore, if n = 1000, then to sort the list, bubble sort makes about 500,000 key comparisons and about 250,000 item assignments