02 - CIS 121 Spring 2010 Data Structures and Introduction...

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

View Full Document Right Arrow Icon
1 1/15/10 CIS121-Lecture Notes 2 1 CIS 121 Spring 2010 Data Structures and Introduction to Algorithms using JAVA Lecture Notes 2: Analysis, models of computation, Big-Oh notation © 1999-2010 S.Kannan, V.Tannen, S.Guha & K.Daniilidis © 2006 M.Goodrich & R.Tamassia (with permission) 1/15/10 CIS121-Lecture Notes 2 2 Recommended Reading Chapter 5 from Weiss
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 1/15/10 CIS121-Lecture Notes 2 3 Efficiency It is important to write “efficient” programs, but how can we tell that we have achieved this goal? Two main ways to determine efficiency of programs: Empirical (measure time taken by running program) Analytical (analyze the running time theoretically) What are the pros and cons of each approach? 1/15/10 CIS121-Lecture Notes 2 4 Measurement Run a program on an input and time it. We have already seen such measurements for the programs implementing the gcd algorithms. ˢ Extremely accurate (if done carefully) Easy to do ˣ Not very good predictive value on Other inputs Other machines, compilers, environments Can only be done after the whole program is written.
Background image of page 2
3 1/15/10 CIS121-Lecture Notes 2 5 Measuring a simple program We measure the time to generate N random numbers and store them in an array. We do this for various N: 1000, 10000, 100000, 1000000, 10000000. We do it once and report the time; we do it 10 times and divide the time by 10; same with 100 times. We do it on two machines, Eniac and David Siegel’s PC. We do it with various Java compilers: 1.3, 1.4, 1.5. We do it in various environments: plain operating system (OS) command line, Dr.Java, and a Java development environment called Eclipse. 1/15/10 CIS121-Lecture Notes 2 6 Various factors impact on measurements 1 trial N=1,000 10,000 100,000 1,000,000 10,000,000 PC, 1.4, Command Line 3 1 14 128 1292 PC, 1.5, Command Line 6 7 36 319 3203 PC, 1.5, DrJava 4 5 78 483 4834 PC, 1.5, Eclipse 3 4 110 456 3311 Eniac, 1.3, Command Line 7 3 31 288 2886 avg over 10 trials N=1,000 10,000 100,000 1,000,000 10,000,000 PC, 1.4, Command Line <1 1 15 132 1297 PC, 1.5, Command Line 1 4 36 369 3194 PC, 1.5, DrJava <1 5 48 478 4828 PC, 1.5, Eclipse <1 3 40 392 3233 Eniac, 1.3, Command Line <1 2 28 298 2910 avg over 100 trials N=1,000 10,000 100,000 1,000,000 10,000,000 PC, 1.4, Command Line <1 1 12 129 1296 PC, 1.5, Command Line <1 3 36 317 3187 PC, 1.5, DrJava <1 4 47 483 4833 PC, 1.5, Eclipse <1 3 38 325 3256 Eniac, 1.3, Command Line <1 2 29 290 kicked out Times are in milliseconds OS :-( machine, compiler, environment
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 1/15/10 CIS121-Lecture Notes 2 7 Some lessons In general the time depends linearly on N: Time(N) = cN However: The constant c depends on many factors: machine, compiler, etc. This correspondence is more accurate for larger N than smaller N.
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/19/2010 for the course CIS 121 taught by Professor Tannen during the Spring '09 term at UPenn.

Page1 / 16

02 - CIS 121 Spring 2010 Data Structures and Introduction...

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

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