1 / 24

CS 575 Design and Analysis of Computer Algorithms Professor Michal Cutler Introduction

CS 575 Design and Analysis of Computer Algorithms Professor Michal Cutler Introduction. This class. General Information Web page for course http://bingweb.binghamton.edu/ ~cs575c/f07/index.html Goals Analysis Problem size. Goals of the course:. Prepare students for: Job interviews

lawtond
Download Presentation

CS 575 Design and Analysis of Computer Algorithms Professor Michal Cutler Introduction

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. CS 575Design and Analysis of Computer AlgorithmsProfessor Michal CutlerIntroduction

  2. This class • General Information • Web page for course http://bingweb.binghamton.edu/ ~cs575c/f07/index.html • Goals • Analysis • Problem size

  3. Goals of the course: Prepare students for: Job interviews Future technical challenges Using critical thinking for problem solving Implementing algorithms efficiently and correctly Arguing correctness Analyzing time complexity Using common algorithms (building blocks) Learning to design using well known methods

  4. Job interviews (1) • Job interviews contain many data structures and algorithm related questions • “Describe binary search” • “Describe an efficient algorithm that reads a file containing in random order all the numbers between 100 and 2035 excluding one, and determines the missing number. • The algorithm should be linear in time and use only constantspace”

  5. Job interviews (2) • Often you will be asked to program your solutions • “Write a program to find the first character of a string that occurs only once” [A] • “Write a program to decide whether a linked list contains a cycle”

  6. Job interviews (3) • Interviews also contain puzzles and brain teasers • The goal is to test: • Creative, logical and critical thinking • Basic knowledge

  7. What you should do (1) • Repeat the question, and make sure that you understand it (ask questions if you don’t) • Try a simple example. For question [A] try the string “necessary sufficient” “a” is the answer for this example. • Consider alternative designs and data structures for the solution • Analyze the different computation times • Choose the best one • Often there is a very simple solution, and less obvious more efficient ones

  8. What you should do (2) • Write the code making sure to deal with possible exceptions • Walk thru the code with a specific example • Make corrections if necessary

  9. What should universities teach? From Communications ACM, September 2003, pp39 “A traditional university education is to provide the foundations for further learning. It provides just-in-case learning rather than just-in-time learning provided by on-the-job training”

  10. Critical thinking Glaser’s definition: Critical thinking calls for a persistent effort to examine any belief or supposed form of knowledge in the light of the evidence that supports it and the further conclusion to which it tends (Glaser 1941)

  11. Critical thinking Ennis’s definition: “Critical thinking is reasonable reflective thinking that is focused on deciding what to believe or do” (Norris and Ennis 1989)

  12. Using critical thinking for problem solving • Considering different approaches for solving a problem (for example dynamic vectors) • Analyzing the merits of each • Considering different implementations for a chosen approach (for example Prim’s algorithm) • Analyzing the merit of the different implementation

  13. Efficiency • The efficiency of an algorithm depends on the quantity of resources it requires • Usually we compare algorithms based on their time • Sometimes also based on the space resources they need. • The time required by an algorithm depends on the instance size, and its data

  14. Instance Size • Formally: Size = number of (binary) bits needed to represent the instance on a computer. • We will usually be much less formal • For sort we assume that the size of a record is c or bound by c number of bits • Formally the size of an input to sort with n records of c bits is nc, informally we use just n • Why do we need the formal definition?

  15. Number problems • Problems where input numbers can become increasingly large. • Examples: • Factorial of 10, 106, 1015 • Fibonacci numbers • Multiplying, adding, dividing big numbers • For these problems we should use the formal definition • Size for a single number with valuen is O(lg n) Best, average, worst?

  16. int fib(int n) { if (n <=1) return n; prev=0; cur=1; for (i=2; i<=n; i++) { next = cur + prev; prev = cur; cur= next; } return next } Analysis. Number of operations c*n (?) Number bits for value n, s=floor(lgn) +1 floor(lgn)=s-1 n >= 2s -1 Fibonacci

  17. Time Analysis • Best Case: The smallest amount of time needed to run any instance of a given size • Worst Case: The largest amount of time needed to run any instance of a given size • Average Case: the expected time required by an instance of a given size

  18. Requirements for time analysis • Independent of (what?) • A priori (why?) • Large instances (why?) • Growth rate classes • What are they? • Why?

  19. Growth Rate Classes Requirement • Time analysis should partition algorithms into: • ordered classes (algorithms in a class considered to have same efficiency), and • if class A “is better than“ class B then all algorithms that belong to A are considered more efficient than all algorithms in class B.

  20. The classes • Time analysis partitions algorithms into general equivalence classes such as: • logarithmic, • square-root • linear, • linear*logarithmic (nlgn) • quadratic, cubic, … • polynomial (nk where k>=0 is a constant) • exponential, (such as cn) etc. • Reason for this kind of classification • Growth rate classes are derived from instruction counts and the derived constants are estimates

  21. Instruction counts • Provide rough estimates of actual number of instructions executed • Depend on: • Language used to describe algorithm • Programmer style • Method used to derive count • May be quite different from actual counts • Algorithm with an estimated count = 2n, may not be faster than one with estimated count=5n (why?)

  22. Method 1: Sum Line Counts • Derive a count for each line of code taking into account all loop nesting. • Compute total by adding line counts.

  23. Method 2: Barometer Operation • A “barometer instruction” is selected • Count = number of times that barometer instruction is executed. • Search algorithms: • barometer instruction (x == L[j]?). • Sort algorithms: • barometer instruction (L[i] == L[j]?). • Should be chosen with care.

  24. Next class • Asymptotic growth functions

More Related