1 / 31

Computer Science II

Computer Science II. University of Palestine Faculty of Engineering and Urban planning Software Engineering Department. Lecture 4 of. Mohammad Amin Kuhail M.Sc. (York, UK). Analysis Tools. Tuesday, 25 September 2007. Analysis Tools. Agenda. What Is Running Time Anyway? Pseudo-Code

Télécharger la présentation

Computer Science II

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. Computer Science II University of Palestine Faculty of Engineering and Urban planning Software Engineering Department Lecture 4 of Mohammad Amin KuhailM.Sc. (York, UK) Analysis Tools Tuesday, 25 September 2007

  2. Analysis Tools Agenda • What Is Running Time Anyway? • Pseudo-Code • A Quick Mathematical Review • Analysis of algorithms • Average-Case and Worst-Case Analysis • Asymptotic Notation

  3. What Is Running Time Anyway? Definition • Running time : How long it takes a show to go from start to finish.

  4. What Is Running Time Anyway? Experimental Studies • Run a piece of code and record the time spent in execution. • Java.System.currentTimeMillis() • In general the time increases with The input size, and is affected by the hardware, and software environment.

  5. What Is Running Time Anyway? Limitations of running time studies • Experiments can be done on a limited set of test inputs, and may not be indicative of other inputs. • It is difficult to compare two algorithms unless experiments have the same software, and hardware environments. • It is necessary to implement and study an algorithm in order to study its running time.

  6. What Is Running Time Anyway? Requirements for a general methodology • Takes into account all possible inputs. • Allows us to evaluate the efficiency of an algorithm in a way that is independent from hardware and software environment. • Can be performed by studying a high-level description of the algorithm without actually implementing it or running experiments on it.

  7. Pseudo-Code Definition • Pseudo-code (derived from pseudo and code) is a compact and informal high-level description of a computer programming algorithm that uses the structural conventions of programming languages, but omits detailed subroutines, variable declarations or language-specific syntax. The programming language is augmented with natural language descriptions of the details, where convenient.

  8. Pseudo-Code Characteristics • High- level description of an algorithm • More structured than English prose • Less detailed than a program • Preferred notation for describing algorithms • Hides program design issues

  9. Pseudo-Code Syntax • As the name suggests, pseudo-code generally does not actually obey the syntax rules of any particular language; there is no systematic standard form, although any particular writer will generally borrow the appearance of a particular language.

  10. Pseudo-Code Syntax • Expression: Use ← instead of =, Use = instead of == • Method declaration: algorithm name(A,n) • Decision structures:If condition then true-actions else false-actions • While-loops:while condition do actions • Repeat-loops:repeat actions until condition • For-loops:for increment-action do actions • Array-indexing:A[i] • Method-calling:object.mehtod(args) or simply method(args). • Method-returs:return

  11. Pseudo-Code Example 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

  12. Pseudo-Code Vs. Flowchart ? • A flowchart (also spelled flow-chart and flow chart) is a schematic representation of an algorithm or a process.

  13. A Quick Mathematical Review Logarithms and Exponents

  14. A Quick Mathematical Review Logarithms and Exponents

  15. A Quick Mathematical Review Preposition • Let a, b, and c positive real numbers, we have:

  16. A Quick Mathematical Review Preposition Ceiling, Floor

  17. A Quick Mathematical Review Examples

  18. A Quick Mathematical Review Summations

  19. A Quick Mathematical Review Proposition For any integer n>=0 and any real number 0 <a1 , consider the summation

  20. A Quick Mathematical Review Example

  21. A Quick Mathematical Review Proposition For any integer n>=1 We have:

  22. A Quick Mathematical Review Example

  23. Analysis of algorithms Primitive Operations Definition • Assigning a value to a variable. • Calling a method. • Performing an arithmetic operation (e.g., adding two Numbers). • Comparing two numbers. • Indexing into an array. • Following an object reference. • Returning from a method.

  24. Analysis of algorithms Primitive Operations Analysis approach • Code up the algorithm in some high-level computer language. • Compile the program into some low-level executable language. • Determine for each instruction i of the low-level language, the time ti needed to execute the instruction. • Determine for each instruction i of the low-level language, the times ni that instruction i gets executed when the algorithm is run. • Sum up the products ni.ti over all the instructions, which yields the running time of the algorithm. Advantages Vs. Disadvantages ?

  25. Analysis of algorithms Primitive Operations Example Algorithm arrayMax(A, n) #operations currentMax ← A[0] for i ← 1 to n − 1 do if A[i] < currentMax then currentMax ← A[i] return currentMax

  26. Analysis of algorithms Primitive Operations Example Algorithm arrayMax(A, n) #operations currentMax ← A[0] 2 for i ← 1 to n − 1 do 1+ n if A[i] < currentMax then 2(n-1) currentMax ← A[i] at most 2(n-1) { increment counter i} 2(n − 1) return currentMax 1 AT LEAST: 2+1+n+4(n-1)+1=5n-1 AT MOST: 2+1+n+6(n-1)+1=7n-3

  27. Average-Case and Worst-Code Analysis Primitive Operations Example • Best Case. • Worst Case. • Average Case. - Expected number of execution times  probability theory

  28. Average-Case and Worst-Code Analysis Primitive Operations Example Worst case time Running Time ms Average Best case time Input Instance

  29. Asymptotic Notation Definition Asymptotic Notation is often used to describe how the size of the input data affects an algorithm's usage of computational resources (usually running time or memory).

  30. Asymptotic Notation Do we need that level of detail? Example: y= a*x+b ?

  31. References Analysis Tools [1] Textbook. [2]http://www.google.com/url?sa=X&start=0&oi=define&q=http://www.ascd.org/advocacykit/glossary_med.html&usg=AFQjCNEqZ25hi_bWLZ_uURa_YzaPGf7f5g [3] http://en.wikipedia.org/wiki/Pseudocode [4] http://en.wikipedia.org/wiki/Flowchart [5] http://en.wikipedia.org/wiki/Asymptotic_notation

More Related