0% found this document useful (0 votes)
28 views18 pages

Lec 1

Uploaded by

Saman Akram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views18 pages

Lec 1

Uploaded by

Saman Akram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Design and analysis of

algorithms
Introduction to DAA
Lecture 1
Why we need to study this subject?

 This course introduces the design and analysis of algorithms.


 Perhaps it is meaningful to discuss a very important question first: Why should we study
algorithms?
 It is commonly believed that in order to obtain high speed computation, it suffices to have
a very high speed computer.
 This, however, is not entirely true. We illustrate this with an experiment whose results
make it clear that a good algorithm implemented on a slow computer may perform much
better than a bad algorithm implemented on a fast computer.
More Information

 Textbook
 Introduction to Algorithms 3rd , Thomas H.
Corman, Charles E. Leiserson, Ronald L. Rivest
and Clifford Stein
 Algorithms, (4th edition, 2011), Robert Sedgewick, Kevin Wayne
 Algorithm Design, (1st edition, 2013/2014)
Jon Kleinberg, Eva Tardos.
Outline
Design and analysis of algorithm

Problem

Algorithm
+ Data structure

Program

Input Computer Output


What is algorithm

 The word algorithm comes from name of Persian author “Abu Jaffar Mohammad” in
825AD.
 Def
An algorithm is a sequence of computational steps that transform the input into the output.
 Algorithm is any well-defined computational procedure that takes some value, or set of values, as input
and produces some value, or set of values, as output.
 Another def.
Finite set of steps to solve a problem.
Fundamentals for algorithm

 Input (zero input or more input)


 Output (at least one)
 Definiteness ( no confusion for computer, unambigious)
 Finiteness (always terminate)
 Effectiveness
Fields in this course

 How to device algorithm?


 How to validate?
 How to analyse ?
 How to test?
Design of algorithms

Different ways of representing an algorithm is


 Natural language
 Pseudo code
 Flow chart
Difference between algorithm, pseudo code
and program
 Algorithm  Pseudo code  Program
 A step by step method to  It is simple version of  It is exact code in any
solve a problem . programing code that does particular
 not require any strict programming
Its written in natural
programming language language.
language.
syntax.
 For example a recipe for
preparing a dish.
Natural language/ Algorithm

 Natural language is general way to solve any problem


 For e.g to perform addition of two numbers we write in natural language
 Step1: read the first number (assume a)
 Step2:read the second number (assume b)
 Step3:add 2 numbers(a and b)and store the result in a variable c
 Step4:display the result
Pseudo code

Combination of natural language and programming language construct For e.g.to perform
addition of two numbers we write in pseudo-code
 //this algo perform addition of two integers
 //input two integers a and b
 // output of two integers
 C=a+b
 Write c
Flow Chart
What is a program?

 A program is the expression of an algorithm in a programming language


 a set of instructions which the computer will follow to solve a problem
What is analysis

 Analysis is process of comparing two algorithms w.r.t time and space.


 Analysis can be of two types
1:Prior
Analysis before execution
Independent of hardware just focus on iterations
Give approx. value
2:Posterior
Analysis after execution
Always depend on hardware
Give exact value
Why need algorithm analysis ?

 writing a working program is not good enough


 The program may be inefficient!
 If the program is run on a large data set, then the running time becomes an issue
Complexity of an algorithm

 What is the complexity of an algorithm?


 Complexity (or efficiency) of an algorithm is a function that describes the efficiency of an
algorithm in terms of time and space.
 There are two types of complexity:
 1.Time complexity:
 Time complexity means the amount of time required by an algorithm to run.
 It expressed as an order of magnitude / degree
Complexity of an algorithm

 2.space complexity:
 Space complexity means the amount of space required by an algorithm to run.It expressed as an order of
magnitude.There are two important factors to compute the space complexity:constant and instant
characterstic.
 e.g
 factorial(n)
 if n=0 then
 return 1;
 else
 return*factorial(n-1);
 endif
 space complexity of program = constant size + variable size

You might also like