41Perf42Sort

41Perf42Sort - Running Time 4.1 Performance, 4.2 Sorting...

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

View Full Document Right Arrow Icon
4.1 Performance, 4.2 Sorting and Searching 2 Running Time Charles Babbage (1864) “As soon as an Analytic Engine exists, it will necessarily guide the future course of the science. Whenever any result is sought by its aid, the question will arise - By what course of calculation can these results be arrived at by the machine in the shortest time?” – Charles Babbage Analytic Engine how many times do you have to turn the crank? 3 Scientific Method Analysis of algorithms. Framework for comparing algorithms and predicting performance. Scientific method. ! Observe some feature of the natural world. ! Hypothesize a model that is consistent with the observations. ! Predict events using the hypothesis. ! Verify the predictions by making further observations. ! Validate by repeating until the hypothesis and observations agree. Principles. Experiments we design must be reproducible; hypothesis must be falsifiable. 4 Algorithmic Successes N-body Simulation. ! Simulate gravitational interactions among N bodies. ! Brute force: N 2 steps. ! Barnes-Hut: N log N steps, enables new research . Discrete Fourier transform. ! Break down waveform of N samples into periodic components. Applications: DVD, JPEG, MRI, astrophysics, …. ! Brute force: N 2 steps. ! FFT algorithm: N log N steps, enables new technology . Sorting. ! Rearrange N items in ascending order. ! Fundamental information processing abstraction. Andrew Appel PU '81 Freidrich Gauss 1805 Jon von Neumann IAS 1945
Background image of page 1

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

View Full DocumentRight Arrow Icon
5 Case Study: Sorting Sorting problem. Rearrange N items in ascending order. Applications. Statistics, databases, data compression, bioinformatics, computer graphics, scientific computing, ... Hanley Haskell Hauser Hayes Hong Hornet Hsu Hauser Hong Hsu Hayes Haskell Hanley Hornet 6 Insertion sort. ! Brute-force sorting solution. ! Move left-to-right through array. ! Exchange next element with larger elements to its left, one-by-one. Insertion Sort 7 Insertion sort. ! Brute-force sorting solution. ! Move left-to-right through array. ! Exchange next element with larger elements to its left, one-by-one. Insertion Sort 8 Insertion Sort: Java Implementation public class Insertion { public static void sort ( String [] a ) { int N = a . length ; for ( int i = 1 ; i < N ; i ++) for ( int j = i ; j > 0 ; j --) if ( a [ j - 1 ]. compareTo ( a [ j ]) > 0 ) exch ( a , j - 1 , j ); else break ; } private static void exch ( String [] a , int i , int j ) { String swap = a [ i ]; a [ i ] = a [ j ]; a [ j ] = swap ; } }
Background image of page 2
9 Insertion Sort: Observation
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/16/2008 for the course COS 126 taught by Professor Douglasw.clark during the Fall '08 term at Princeton.

Page1 / 9

41Perf42Sort - Running Time 4.1 Performance, 4.2 Sorting...

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

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