08_algorithms - Overview 4.1 - 4.2 Analysis of Algorithms...

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

View Full Document Right Arrow Icon
1 4.1 - 4.2 Analysis of Algorithms 2 Overview Analysis of algorithms. Framework for comparing algorithms and predicting performance. Scientific method. Observe some feature of the universe. Hypothesize a model that is consistent with observation. Predict events using the hypothesis. Verify the predictions by making further observations. Validate the theory by repeating the previous steps until the hypothesis agrees with the observations. Universe = computer itself. 3 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 Freidrich Gauss 1805 Jon von Neumann IAS 1945 4 Case Study: Sorting Sorting problem. Given N items, rearrange them in ascending order. Applications. Statistics, databases, data compression, computational biology, computer graphics, scientific computing, ... Hanley name Haskell Hauser Hayes Hong Hornet Hsu Hauser name Hong Hsu Hayes Haskell Hanley Hornet
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 5 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 public static void sort ( double [] a ) { for ( int i = 0 ; i < a . length ; i ++) { for ( int j = i ; j > 0 ; j --) { if ( less ( a [ j ], a [ j - 1 ])) exch ( a , j , j - 1 ); else break ; } } } 6 Sorting helper functions. Is real number x strictly less than y ? Swap real numbers stored in a[i] and a[j] . public static boolean less ( double x , double y ) { return ( x < y ); } public static void exch ( double [] a , int i , int j ) { double swap = a [ i ]; a [ i ] = a [ j ]; a [ j ] = swap ; } Helper Functions 7 Insertion Sort: Observation Observe and tabulate running time for various values of N. Data source: N random numbers between 0 and 1. Machine: Apple G5 1.8GHz with 1.5GB memory running OS X. Timing: Skagen wristwatch. 5.6 seconds 400 million 40,000 1.5 seconds 99 million 20,000 0.43 seconds 25 million 10,000 0.13 seconds 6.2 million 5,000 23 seconds Time Comparisons N 1600 million 80,000 8 Data analysis. Plot # comparisons vs. input size on log-log scale. Regression. Fit line through data points a N b . Hypothesis. # comparisons grows quadratically with input size N 2 /4.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/21/2009 for the course COMPUTER computer 1 taught by Professor Abedauthman during the Fall '08 term at Aarhus Universitet.

Page1 / 8

08_algorithms - Overview 4.1 - 4.2 Analysis of Algorithms...

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

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