sorting - Programming Sorting Arrays P102 Prog....

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Programming Sorting Arrays
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
P102 Prog. Fundamentals. Sorting I/ Slide 2 Sorting To arrange a set of items in sequence. It is estimated that 25~50% of all computing power is used for sorting activities. Possible reasons: Many applications require sorting; Many applications perform sorting when they don't have to; Many applications use inefficient sorting algorithms.
Background image of page 2
P102 Prog. Fundamentals. Sorting I/ Slide 3 Sorting Applications To prepare a list of student ID, names, and scores in a table (sorted by ID or name) for easy checking. To prepare a list of scores before letter grade assignment. To produce a list of horses after a race (sorted by the finishing times) for payoff calculation. To prepare an originally unsorted array for ordered binary searching.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
P102 Prog. Fundamentals. Sorting I/ Slide 4 Some Sorting Methods Selection sort Bubble sort Shell sort (a simple but faster sorting method than above; see p.331 of Numerical Recipes in C , 2nd ed., by William H. Press et al , Cambridge University Press, 1992) Quick sort (a very efficient sorting method for most applications; p.332-336, ibid .)
Background image of page 4
P102 Prog. Fundamentals. Sorting I/ Slide 5 Ex. 1A: Selection Sort Selection sort performs sorting by repeatedly putting the largest element in the unsorted portion of the array to the end of this unsorted portion until the whole array is sorted. It is similar to the way that many people do their sorting.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Ex. 1A: Selection Sort Algorithm 1. Define the entire array as the unsorted portion of the array 2. While the unsorted portion of the array has more than one element: Find its largest element. Swap with last element (assuming their
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 18

sorting - Programming Sorting Arrays P102 Prog....

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online