1 / 9

Shuttle sort

Shuttle sort. Step 1: Compare 1 st and 2 nd numbers in the list and swap if necessary Step 2: Compare the 2 nd and 3 rd numbers in the list and swap if necessary. If a swap has occurred, compare the 1 st and 2 nd numbers and swap if necessary.

mio
Download Presentation

Shuttle sort

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Shuttle sort Step 1: Compare 1st and 2nd numbers in the list and swap if necessary Step 2: Compare the 2nd and 3rd numbers in the list and swap if necessary. If a swap has occurred, compare the 1st and 2nd numbers and swap if necessary. Step 3: Compare the 3rd and 4th numbers and swap if necessary. If a swap has occurred compare 2nd and 3rd numbers and so on up the list.

  2. Bubble sort Step 1: If there is only one number in the list then stop. Step 2: Make one pass down the list, comparing numbers in pairs and swapping if necessary. Step 3: If no swaps have occurred stop. Otherwise ignore the last element of the list and return to Step 1.

  3. Application 1. Apply both Bubble sort and Shuttle sort to the numbers 5, 4, 3, 2, 1. Count how many comparison and how many swaps are required to produce the order 1, 2, 3, 4, 5. 2. Generalise you answer to a list of n numbers.

  4. Order of an algorithm The size of the problem is a measure of its complexity. The efficiency of an algorithm is a measure of the number of calculations needed. The order of an algorithm is a measure of its efficiency.

  5. Order of an algorithm The size of the problem is a measure of its complexity. The efficiency of an algorithm is a measure of the number of calculations needed. The order of an algorithm is a measure of its efficiency. Example: Shuttle Sort of n numbers: Size : n Efficiency: ½n(n-1) Order: n2

  6. Order of an algorithm Example: Shuttle Sort of n numbers: Size : n Efficiency: ½n(n-1) Order: n2 If a computer takes 2 ms to sort 10,000 numbers now long would it take to sort a million?

  7. Climate models Figure 13.1: A finite grid superposed on the Earth, with 10o resolution. Data on such a grid would be stored at the intersections of gridlines. A finite difference scheme will also extend the grid in the vertical.

  8. Climate models Figure 13.1: A finite grid superposed on the Earth, with 10o resolution. Typical resolutions of GCMs are currently around 2.5o in the horizontal. If a climate model takes 10 sec to simulate a year, how long would a GCM take?

  9. Order of an algorithm Example: Epidemic model Size : Efficiency: Order:

More Related