You are on page 1of 31

Course Objectives

Develop skills needed for at designing correct and efficient algorithms Gain familiarity with a number of classical problems that occur frequently in real-world applications. Inculcate skills to understand mathematical notations in algorithms and their simple mathematical proofs, particularly inductive proofs Understand basic data structures and to use them in algorithms

Design and Theory of Algorithms


(Course Outline)
Preliminaries : different types of algorithms, notations, proof techniques, and limits. Elementary Algorithms : problems and instances, efficiency of algorithms, analyses of algorithms, examples of algorithms. Asymptotic Notation : different notations and their graph examples, standard notations and their common functions. Analysis of Algorithms : analysing control structures, using barometer, different examples for analysis and solving recurrences. Structures: use of arrays, stacks, queues, records, pointers, lists, graphs, trees, associate tables, heaps and binomial heaps. Tree Algorithms: understanding & making trees, and their algorithms. Heap Algorithms : developing heaps, binomial heaps, disjoint structures, and their algorithms, Greedy Algorithms : characteristics, minimum spanning and shortest path algorithms.

Grading
Your final grade in the course will be determined by the following scheme:
Final exam Two sessional exams Homework + quizzes : : : 50% 30% 20%

Textbooks
Advised:
Cormen, Leiserson, Rivest & Stein, Introduction to Algorithms, 2nd Edition, The MIT Press, 2001. Brassard & Bratley, Fundamentals of Algorithmics, Prentice-Hall International, 1999.

ALGORITHM
A statement of the steps to be followed in performing a task or solving a problem. In a computer program the steps of an algorithm are specified in a specific computer language. Each step is written on a new line and stated as briefly as possible

PHRASES FOR WRITING ALGORITHM


Phrases much as mentioned below are used to link sequences of steps if required:(i) if then _________ _________ _________ else _________ _________ _________

PHRASES FOR WRITING ALGORITHM


(ii) Repeat _________ _________ _________ until _________ _________ _________

PHRASES FOR WRITING ALGORITHM


(iii) while .. do _________ _________ _________ (iv) do _________ _________ _________ while

AN ALGORITHM FOR REPLYING TO FRIENDS LETTER


Read friends letter Decide what to write Write letter in reply

ALGORITHM TO ACCEPT / REJECT HOLIDAY


Repeat Read holiday leaflet if it is in July and costs less than Rs 8000 and is at a place not visited before then Accept the holiday else Reject the holiday Until a holiday is accepted

ALGORITHM FOR USING PUBLIC TELEPHONE


Repeat Get money ready Lift receiver If dialing tone then Dial number If number obtainable and not engaged then Repeat wait Until someone answers or waited long enough If answered then Insert money

ALGORITHM FOR USING PUBLIC TELEPHONE


If right number and person you want is available then Have conversation Replace receiver else Replace receiver Try again later Until conversation completed

FLOW DIAGRAM SYMBOLS


START or END process

input or output

decision

connector

FLOWCHART OF REPLYING TO A LETTER FROM A FRIEND


START

read friends letter

decide what to write

write letter in reply

END

START

A
read holiday leaflet NO is it in July? YES NO is the cost less than RS 8000? YES has he been before? NO accept holiday Reject holiday YES

Flowchart of accepting or rejecting a holiday

END

START get more money try again lift receiver

FLOW CHART FOR USING PUBLIC TELEPHONE

replace receiver

NO

dialing tone? YES dial number

A
YES
Number unobtainable?

NO YES engaged?
is someone answering?

NO

wait
NO waiting long enough? YES

NO

insert money

continued

A
NO

right number?

NO

is person you want available?

have conversation

replace receiver

END

PROBABILISITIC ALGORITHM
In this algorithm, chosen values are used in such a way that the probability of chosen each value is known and controlled For example chosen a number between 1 and 6

APPROXIMATE ALGORITHM
In this algorithm, answer is obtained that is as prcised as required in decimal notation. In other words it specifies the error we are willing to accept For example, two figures accuracy or 8 figures or whatever is required

HEURISTIC ALGORITHM
This type of algorithm is based largely on optimism and often with minimal theoretical support. Here error can not be controlled but may be estimated how large it is.

ALGORITHMICS
It is the science that lets designers study and evaluate the effect of algorithms based on various factors so that the best algorithm is selected to meet a particular task in given circumstances. It is also the science that tells how to design a new algorithm for a particular job.

CLASSIC MULTIPLICATION ALGORITHMS

(981 x 1234)
981 1234 3924 2943 1962 981 1210554
American

981 1234 981 1962 2943 3924 1210554


English

MULTIPLICATION (981 x 1234) (a la russe algorithm)


981 490 245 122 61 30 15 7 3 1 1234 2468 4936 9872 19744 39488 78976 157952 315904 631808 1234 4936 19744 78976 157952 315904 631808 1210554

MULTIPLICATION (981 x 1234)


(Divide-and-Conquer Algorithm)

Multiply i) ii) iii) iv) 09 09 81 81 12 34 12 34

Shift 4 2 2 0

Result 108. 306.. 972.. 2754 1210554

MULTIPLICATION (9 x 12)
(Divide-and-Conquer Algorithm)

Multiply i) ii) iii) iv) 0 0 9 9 1 2 1 2

Shift 2 1 1 0

Result 0.. 0. 9. 18 108

PARAMETERS FOR SELECTION OF AN ALGORITHM


Priority of Task Type of Available Computing Equipment Nature of Problem Speed of Execution Storage Requirement Programming Effort

A good choice can save both money and time, and can successfully solve the problem

NOTATION OF PROGRAMS
No need of well-structured language English phrases are used for simplicity and clarity Mathematical language is used whenever appropriate Algorithm needs effort to transcribe steps into a computer programming language

NOTATION OF PROGRAMS
For simplicity: Declarations are omitted All variables used in functions or procedures are implicitly understood as local variable unless the context makes it clear otherwise

begin - - - end statements are omitted


Phrases such if, while, for etc are used to indent the statements or instructions Type of parameters are procedures and functions. not declared in

NOTATION OF PROGRAMS
Scalar Array parameters parameters (treated are as local by variable) are passed by value passed reference

MATHEMATICAL NOTATIONS
Propositional Calculus (i) Conjunction (ii) Disjunction (iii) Negation true if p is false (iv) p q (if p then q) (p = q) (v) p q p q ( p and q) p V q ( p or q) (not p) ( p) true if both p & q are true true if at least one of p or q is true

Algorithm for a la russe Method


function russe (m,n) result repeat if m is odd then result m n until m = 0 return result m2 n+n result + n 0

You might also like