Java Programming: From Problem Analysis to Program Design, 5e Chapter 14 Bubble Sort
Objectives <ul><li>Explore how to sort an array using bubble sort </li></ul>Java Programming: From Problem Analysis to Pro...
Sorting a List <ul><li>Bubble sort </li></ul><ul><ul><li>Suppose  list[0...n   -   1]  is a list of n elements, indexed  0...
Bubble Sort Java Programming: From Problem Analysis to Program Design, 5e
Bubble Sort (continued) Java Programming: From Problem Analysis to Program Design, 5e
Bubble Sort (continued) Java Programming: From Problem Analysis to Program Design, 5e
Bubble Sort (continued) Java Programming: From Problem Analysis to Program Design, 5e
Bubble Sort (continued) Java Programming: From Problem Analysis to Program Design, 5e
Bubble Sort (continued) Java Programming: From Problem Analysis to Program Design, 5e
Bubble Sort (continued) Java Programming: From Problem Analysis to Program Design, 5e <ul><li>It is known that for a list ...
Upcoming SlideShare
Loading in …5
×

9781111530532 ppt ch14_bubble_sort

884 views

Published on

Published in: Technology, News & Politics
  • Be the first to comment

  • Be the first to like this

9781111530532 ppt ch14_bubble_sort

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

×