Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction Algorithms and Conventions The design and analysis of algorithms is the core subject matter of Computer Science. Given a problem, we want.

Similar presentations


Presentation on theme: "Introduction Algorithms and Conventions The design and analysis of algorithms is the core subject matter of Computer Science. Given a problem, we want."— Presentation transcript:

1 Introduction Algorithms and Conventions The design and analysis of algorithms is the core subject matter of Computer Science. Given a problem, we want to find an algorithm to solve the problem (create) prove that the algorithm solves the problem correctly (validate) prove that we cannot solve the problem any faster (analyse) implement the algorithm test the program (debugging and profiling) 13 October 20151

2 Analysis Designing an algorithm for a computational problem involves knowledge of the problem domain, a thorough knowledge of the data structures that are available and suitable, and quite a lot of creativity. It covers the design of algorithms for various types of problems, as well as a mathematical analysis of those algorithms done independently of any actual computational experiments (a theoretical vs. empirical study). Analysis of algorithms is less obviously necessary, but has several purposes: Analysis can be more reliable than experimentation. If we experiment, we only know the behavior of a program on certain specific test cases, while analysis can give us guarantees about the performance on all inputs. It helps one choose among different solutions to problems. As we will see, there can be many different solutions to the same problem. A careful analysis and comparison can help us decide which one would be the best for our purpose, without requiring that all be implemented and tested. We can predict the performance of a program before we take the time to write code. In a large project, if we waited until after all the code was written to discover that something runs very slowly, it could be a major disaster, but if we do the analysis first we have time to discover speed problems and work around them. By analyzing an algorithm, we gain a better understanding of where the fast and slow parts are, and what to work on or work around in order to speed it up. 13 October 20152

3 What is an algorithm? An algorithm is an outline or idea behind a program. Generating an algorithm, itself, is a step-by-step process, getting more specific with each version. It usually starts with a precise statement to solve a problem on a computer but ultimately consists of a sequence of definite instructions to do a certain job. We express algorithms in pseudo-code: something resembling C or Java, but with some statements in English rather than within the programming language. It is expected that one could translate each pseudo-code statement to a small number of lines of actual code, easily and mechanically. 13 October 20153

4 Definition [Algorithm]: An algorithm is a finite set of instructions that, if followed, accomplishes a particular task. In addition, all algorithms must satisfy the following criteria: 1. Input. Zero or more quantities are externally supplied. 2. Output. At least one quantity is produced. (function vs procedure) 3. Definiteness. Each instruction is clear and unambiguous. 4. Finiteness. If we trace out the instructions of an algorithm, then for all cases, the algorithm terminates after a finite number of steps. 5. Effectiveness. Each instruction must be basic so that it can be carried out, in principle, by a person using only pencil and paper. It is not enough that each operation be definite as in criterion 3; it also must be feasible. 13 October 20154

5 Design of Algorithms Devising the algorithm (i.e, method) Expressing the algorithm (computer language) Validating the algorithm (proof of correctness) translational semantics operational semantics denotational semantics axiomatic semantics 13 October 20155

6 Algorithm Analysis of Algorithms Determination of time and space requirements Implementation and Program Testing Not in this class 13 October 20156

7 Pseudocode Conventions Comments: // Blocks: {} Identifiers and Records: Since pseudocode, code is not object-oriented. The use of records is how pre-OO languages grouped information into compound datatypes or structures. Note the use of * to indicate links to other records. Assignment: := Booleans: true and false Arrays: A[i,j] Loops: Use of for,while,repeat-until Conditionals: if then else :... : : : else : } I/O: since pseudocode use read and write rather than specific call Procedures: Algorithm Name ( ) Use of return 13 October 20157

8 Example of Algorithms Suppose you had the Binary search identified in the text (Example1.1). Check out how the text will "walk-through" the conceptualization (Algorithm 1.1 and 1.2)through proof of the algorithm (Thm. 1.1). In addition, the OO code would look something like this: void BinarySearch(Type a[], int n) …… Go and read abt recursion, induction and mathematical functions appendix section of text 13 October 20158

9 Recursion Recursion is a general method of solving problems by reducing them to simpler problems of a similar type. General Algorithm (problem solving tool) of Divide and Conquer Postpone work (if defined recursively (inductively), work is easy) For a web-oriented example, consider designing a "web-crawler" that will search every hyperlink that is accessible from a specific page. Pseudo-code - yes, I do know that this little example would have a problem with circular links Recursive_URL_search(link) Repeat find next_link Recursive_URL_search (next_link) until No_more_links 13 October 20159

10 Recursion ctd.. Three important aspects to always remember in code consider halt make sure get to halt must call self When... why recursion? If problem itself is recursively defined To describe a backtracking procedure Provability of correctness (induction) Ease of programming Why not? space efficiency time efficiency One can always take a recursive program and do it non-recursively. 13 October 201510

11 Recursion ctd… For any recursive problem one needs to consider two features: Are solutions easy to give for special states (stop state)? (need to identify a "trivial" case) Given a state (not the stop state) are there clear rules for proceeding to a new state that is either a stop state leads to a stop state I.e., find a method to solve the "complex" case in terms of a "simpler" case (the conquer is easier if divide) Quiz write the binary search, factorial and fibonacci series using recursion 13 October 201511


Download ppt "Introduction Algorithms and Conventions The design and analysis of algorithms is the core subject matter of Computer Science. Given a problem, we want."

Similar presentations


Ads by Google