Algorithms Algorithms An algorithm must be seen to

Algorithms

Algorithms “ An algorithm must be seen to be believed ” Donald Knuth

What are Algorithms? • Is all universe an algorithm? ? • Right or Wrong !!!!! q Computer Science is the Study of Algorithms.

What are Algorithms? • A computer algorithm is a detailed step-by-step method for solving a problem by using a computer. • An algorithm is a sequence of unambiguous instructions for solving a problem in a finite amount of time. • An Algorithm is well defined computational procedure that takes some value, or set of values, as input and produces some value, or set of values as output. • More generally, an Algorithm is any well defined computational procedure that takes collection of elements as input and produces a collection of elements as output.

What are Algorithms? Input output Algorithm

Algorithms: Real Life Examples • Many Real-Life Examples • Cooking: Recipe for preparing a dish • Origami: The Art of Paper Folding • Directions: How to go to Changi Airport • Remember: • Framework: How to give instructions; • Alg: The actual step-by-step instructions; • Abstraction: Decomposing / Simplifying

Algorithms: Real Life Example: Cooking • Framework: “Cooking or Recipe language” • Algorithm: “Recipe for a Dish” (step by step instructions on how to cook a dish) • Problem Decomposition • Preparing Ingredients; • Preparing Sauce;

Real Life Examples: Issues • Problems/Difficulties: • Imprecise Instructions; • Job can often be done even if instructions are not followed precisely • Modifications may be done by the person following the instructions; • But, NOT for a Computer • Needs to told PRECISELY what to do; • Instructions must be PRECISE; • Cannot be vague or ambiguous

Expressing Algorithms to Computer • To communicate algorithm to computer • Need way to “represent” the algorithm • Cannot use English • Can use computer language • machine language and • programming languages (Java, Pascal, C) • But, these are too tedious (&technical)

Popular Algorithms, Factors of Dependence • Most basic and popular algorithms are • Sorting algorithms • Searching algorithms Which algorithm is best? • Mainly, it depends upon various factors, for example in case of sorting • • The number of items to be sorted The extent to which the items are already sorted Possible restrictions on the item values The kind of storage device to be used etc.

One Problem, Many Algorithms Problem • The statement of the problem specifies, in general terms, the desired input/output relationship. Algorithm • The algorithm describes a specific computational procedure for achieving input/output relationship. Example • One might need to sort a sequence of numbers into nondecreasing order. Algorithms • Various algorithms e. g. merge sort, quick sort, heap sorts etc.

Important Design Techniques • Brute Force • • • Straightforward, naive approach • Mostly expensive Divide-and-Conquer • Divide into smaller sub-problems Iterative Improvement • Improve one change at a time Decrease-and-Conquer • Decrease instance size Transform-and-Conquer • Modify problem first and then solve it Space and Time Tradeoffs • Use more space now to save time later

Efficiency of Algorithm Can we do Exact Measure of Efficiency ? • Exact, not asymptotic, measure of efficiency can be sometimes computed but it usually requires certain assumptions concerning implementation
- Slides: 13