Algorithms are the threads that tie together most of the subfields of computer science.



Similar documents
Chapter 2: Algorithm Discovery and Design. Invitation to Computer Science, C++ Version, Third Edition

Binary Number System. 16. Binary Numbers. Base 10 digits: Base 2 digits: 0 1

Section IV.1: Recursive Algorithms and Recursion Trees

Why? A central concept in Computer Science. Algorithms are ubiquitous.

a 11 x 1 + a 12 x a 1n x n = b 1 a 21 x 1 + a 22 x a 2n x n = b 2.

[Refer Slide Time: 05:10]

CS 103X: Discrete Structures Homework Assignment 3 Solutions

Moving from CS 61A Scheme to CS 61B Java

Specimen 2015 am/pm Time allowed: 1hr 30mins

Efficiency of algorithms. Algorithms. Efficiency of algorithms. Binary search and linear search. Best, worst and average case.

Factoring & Primality

Cubic Functions: Global Analysis

CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis. Linda Shapiro Winter 2015

The Epsilon-Delta Limit Definition:

Today s Topics. Primes & Greatest Common Divisors

Set Theory Basic Concepts and Definitions

The Goldberg Rao Algorithm for the Maximum Flow Problem

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

PROG0101 Fundamentals of Programming PROG0101 FUNDAMENTALS OF PROGRAMMING. Chapter 3 Algorithms

1 Solving LPs: The Simplex Algorithm of George Dantzig

5. Factoring by the QF method

Introducing Formal Methods. Software Engineering and Formal Methods

8 Primes and Modular Arithmetic

Solution of Linear Systems

Python Programming: An Introduction to Computer Science

A simple criterion on degree sequences of graphs

Recursive Algorithms. Recursion. Motivating Example Factorial Recall the factorial function. { 1 if n = 1 n! = n (n 1)! if n > 1

HOMEWORK 5 SOLUTIONS. n!f n (1) lim. ln x n! + xn x. 1 = G n 1 (x). (2) k + 1 n. (n 1)!

Chapter One Introduction to Programming

Algebraic and Transcendental Numbers

Regular Languages and Finite Automata

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Elementary Number Theory and Methods of Proof. CSE 215, Foundations of Computer Science Stony Brook University

10CS35: Data Structures Using C

The Factor Theorem and a corollary of the Fundamental Theorem of Algebra

Pseudo code Tutorial and Exercises Teacher s Version

U.C. Berkeley CS276: Cryptography Handout 0.1 Luca Trevisan January, Notes on Algebra

Verification of Imperative Programs in Theorema

Models of Sequential Computation

On the number of lines of theorems in the formal system MIU

(IALC, Chapters 8 and 9) Introduction to Turing s life, Turing machines, universal machines, unsolvable problems.

Computer Programming. Course Details An Introduction to Computational Tools. Prof. Mauro Gaspari:

MASSACHUSETTS INSTITUTE OF TECHNOLOGY 6.436J/15.085J Fall 2008 Lecture 5 9/17/2008 RANDOM VARIABLES

Regular Expressions with Nested Levels of Back Referencing Form a Hierarchy

Mathematical Induction. Lecture 10-11

Lecture Notes on Polynomials

Modeling, Computers, and Error Analysis Mathematical Modeling and Engineering Problem-Solving

Flowchart Techniques

Binary Heap Algorithms

Discrete Optimization

Complexity Theory. IE 661: Scheduling Theory Fall 2003 Satyaki Ghosh Dastidar

Sources: On the Web: Slides will be available on:

1 Approximating Set Cover

TECHNICAL UNIVERSITY OF CRETE DATA STRUCTURES FILE STRUCTURES

The Mixed Binary Euclid Algorithm

RN-Codings: New Insights and Some Applications

ALGORITHMS AND FLOWCHARTS

How To Program A Computer

Faster deterministic integer factorisation

Classification - Examples

Execution of A Requirement Model in Software Development

What is Linear Programming?

A Formal Model of Program Dependences and Its Implications for Software Testing, Debugging, and Maintenance

InvGen: An Efficient Invariant Generator

24 Uses of Turing Machines

Practical Guide to the Simplex Method of Linear Programming

t := maxγ ν subject to ν {0,1,2,...} and f(x c +γ ν d) f(x c )+cγ ν f (x c ;d).

A Static Analyzer for Large Safety-Critical Software. Considered Programs and Semantics. Automatic Program Verification by Abstract Interpretation

Static Analysis. Find the Bug! : Analysis of Software Artifacts. Jonathan Aldrich. disable interrupts. ERROR: returning with interrupts disabled

FACTORING SPARSE POLYNOMIALS

Measuring the Performance of an Agent

1. (First passage/hitting times/gambler s ruin problem:) Suppose that X has a discrete state space and let i be a fixed state. Let

9.2 Summation Notation

Algorithm & Flowchart & Pseudo code. Staff Incharge: S.Sasirekha

! Solve problem to optimality. ! Solve problem in poly-time. ! Solve arbitrary instances of the problem. #-approximation algorithm.

Chapter 4. Polynomial and Rational Functions. 4.1 Polynomial Functions and Their Graphs

5.1 Radical Notation and Rational Exponents

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser)

10.2 Series and Convergence

Software development and programming. Software

Lecture 3: Finding integer solutions to systems of linear equations

FACTORING POLYNOMIALS IN THE RING OF FORMAL POWER SERIES OVER Z

ML for the Working Programmer

Prime Numbers and Irreducible Polynomials

RN-coding of Numbers: New Insights and Some Applications

Instructor Özgür ZEYDAN (PhD) CIV 112 Computer Programming

8 Divisibility and prime numbers

Programming Languages CIS 443

Integer Factorization using the Quadratic Sieve

1.2 Solving a System of Linear Equations

Numerical Matrix Analysis

Information Theory and Coding Prof. S. N. Merchant Department of Electrical Engineering Indian Institute of Technology, Bombay

(Refer Slide Time: 01:52)

Catalan Numbers. Thomas A. Dowling, Department of Mathematics, Ohio State Uni- versity.

MACM 101 Discrete Mathematics I

NUMBER SYSTEMS. William Stallings

Lecture 6: Finite Fields (PART 3) PART 3: Polynomial Arithmetic. Theoretical Underpinnings of Modern Cryptography

Real Roots of Univariate Polynomials with Real Coefficients

Loop Invariants and Binary Search

Transcription:

Algorithms Algorithms 1 Algorithms are the threads that tie together most of the subfields of computer science. Something magically beautiful happens when a sequence of commands and decisions is able to marshal a collection of data into organized patterns or to discover hidden structure. Donald Knuth

Definition effective method (or procedure) Algorithms 2 a procedure that reduces the solution of some class of problems to a series of rote steps which, if followed to the letter, and as far as may be necessary, is bound to: - always give some answer rather than ever give no answer; - always give the right answer and never give a wrong answer; - always be completed in a finite number of steps, rather than in an infinite number; - work for all instances of problems of the class. algorithm an effective method expressed as a finite list of well-defined instructions for calculating a function

Properties of an Algorithm Algorithms 3 An algorithm must possess the following properties: finiteness: definiteness: input: output: effectiveness: The algorithm must always terminate after a finite number of steps. Each step must be precisely defined; the actions to be carried out must be rigorously and unambiguously specified for each case. An algorithm has zero or more inputs, taken from a specified set of objects. An algorithm has one or more outputs, which have a specified relation to the inputs. All operations to be performed must be sufficiently basic that they can be done exactly and in finite length. Knuth

Problems vs Algorithms vs Programs Algorithms 4 For each problem or class of problems, there may be many different algorithms. For each algorithm, there may be many different implementations (programs). p r o b l e m algorithm 1 algorithm 2. algorithm k program 1 program 2 program n

Expressing Algorithms Algorithms 5 An algorithm may be expressed in a number of ways, including: natural language: flow charts: pseudo-code: programming language: usually verbose and ambiguous avoid most (if not all) issues of ambiguity; difficult to modify w/o specialized tools; largely standardized also avoids most issues of ambiguity; vaguely resembles common elements of programming languages; no particular agreement on syntax tend to require expressing low-level details that are not necessary for a high-level understanding

Common Elements of Algorithms Algorithms 6 acquire data (input) computation selection iteration some means of reading values from an external source; most algorithms require data values to define the specific problem (e.g., coefficients of a polynomial) some means of performing arithmetic computations, comparisons, testing logical conditions, and so forth... some means of choosing among two or more possible courses of action, based upon initial data, user input and/or computed results some means of repeatedly executing a collection of instructions, for a fixed number of times or until some logical condition holds report results (output) some means of reporting computed results to the user, or requesting additional data from the user

pseudo-language Algorithms 7 See the posted notes on pseudo-language notation.

Simple Example: Area of a Trapezoid Algorithms 8 algorithm AreaOfTrapezoid takes number Height, number lowerbase, number upperbase # Computes the area of a trapezoid. # Pre: input values must be non-negative real numbers. # number averagewidth, areaoftrapezoid averagewidth := ( upperbase + lowerbase ) / 2 areaoftrapezoid := averagewidth * Height display areaoftrapezoid halt

Simple Example: N Factorial Algorithms 9 algorithm Factorial takes number N # Computes N! = 1 * 2 *. * N-1 * N, for N >= 1 # Pre: input value must be a non-negative integer. # number nfactorial nfactorial := 1 while N > 1 nfactorial := nfactorial * N N := N - 1 endwhile display nfactorial halt

Example: Finding Longest Run Algorithms 10 algorithm LongestRun takes list number List, number Sz # Given a list of values, finds the length of the longest sequence # of values that are in strictly increasing order. # Pre: input List must contain Sz elements. # number currentposition # specifies list element currently # being examined number maxrunlength # stores length of longest run seen # so far number thisrunlength # stores length of current run if Sz <= 0 # if list is empty, no runs... display 0 halt endif currentposition := 1 # start with first element in list maxrunlength := 1 # it forms a run of length 1 thisrunlength := 1 # continues on next slide...

Example: Finding Longest Run Algorithms 11 #...continued from previous slide while currentposition < Sz if ( List[currentPosition] < List[currentPosition + 1] ) thisrunlength := thisrunlength + 1 else if ( thisrunlength > maxrunlength ) maxrunlength := thisrunlength endif thisrunlength := 1 endif currentposition := currentposition + 1 endwhile display maxrunlength halt QTP: is this algorithm correct?

Testing Correctness Algorithms 12 How do we know whether an algorithm is actually correct? First, the logical analysis of the problem we performed in order to design the algorithm should give us confidence that we have identified a valid procedure for finding a solution. Second, we can test the algorithm by choosing different sets of input values, carrying out the algorithm, and checking to see if the resulting solution does, in fact, work. BUT no matter how much testing we do, unless there are only a finite number of possible input values for the algorithm to consider, testing can never prove that the algorithm produces correct results in all cases.

Proving Correctness Algorithms 13 We can attempt to construct a formal, mathematical proof that, if the algorithm is given valid input values then the results obtained from the algorithm must be a solution to the problem. We should expect that such a proof be provided for every algorithm. In the absence of such a proof, we should view the purported algorithm as nothing more than a heuristic procedure, which may or may not yield the expected results.

Measuring Performance Algorithms 14 How can we talk precisely about the "cost" of running an algorithm? What does "cost" mean? Time? Space? Both? Something else? And, if we settle on one thing to measure, how do we actually obtain a measurement that makes sense? This is primarily a topic for a course in algorithms, like CS 3114 or CS 4104.