This preview shows pages 1–5. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 1 CENG 213 Data Structures Analysis of Algorithms Algorithm Input Output An algorithm is a stepbystep procedure for solving a problem in a finite amount of time. 2 Running Time Most algorithms transform input objects into output objects. The running time of an algorithm typically grows with the input size. Average case time is often difficult to determine. We focus on the worst case running time. square6 Easier to analyze square6 Crucial to applications such as games, finance and robotics 20 40 60 80 100 120 Running Time 1000 2000 3000 4000 Input Size best case average case worst case 2 3 Experimental Studies Write a program implementing the algorithm Run the program with inputs of varying size and composition Use a function, like the builtin clock() function, to get an accurate measure of the actual running time Plot the results 1000 2000 3000 4000 5000 6000 7000 8000 9000 50 100 Input Size Time (ms) 4 Limitations of Experiments It is necessary to implement the algorithm, which may be difficult Results may not be indicative of the running time on other inputs not included in the experiment. In order to compare two algorithms, the same hardware and software environments must be used 3 5 Theoretical Analysis Uses a highlevel description of the algorithm instead of an implementation Characterizes running time as a function of the input size, n . Takes into account all possible inputs Allows us to evaluate the speed of an algorithm independent of the hardware/software environment 6 Pseudocode Highlevel description of an algorithm More structured than English prose Less detailed than a program Preferred notation for describing algorithms Hides program design issues Algorithm arrayMax ( A , n ) Input array A of n integers Output maximum element of A currentMax ← A [0] for i ← 1 to n 1 do if A [ i ] currentMax then currentMax ← A [ i ] return currentMax Example: find max element of an array 4 7 Pseudocode Details Control flow square6 if … then … [ else …] square6 while … do … square6 repeat … until … square6 for … do … square6 Indentation replaces braces Method declaration Algorithm method ( arg [, arg …]) Input … Output … Method/Function call var.method ( arg [, arg …]) Return value return expression Expressions ← Assignment (like = in C++) = Equality testing (like == in C++) n 2 Superscripts and other mathematical formatting allowed 8 The Random Access Machine...
View
Full
Document
This note was uploaded on 11/12/2010 for the course CENG 223 taught by Professor Yok during the Spring '10 term at Middle East Technical University.
 Spring '10
 Yok

Click to edit the document details