0% found this document useful (0 votes)
45 views

Design and Analysis of Algorithms: by Syed Farooq Zaidi

This document provides tips and guidelines for passing a course on design and analysis of algorithms. It outlines three main tips: 1) understand both knowledge of algorithms as well as technical skills, 2) regularly attend and participate in class by taking notes, and 3) do well on semester work like assignments, quizzes and projects which provide more opportunities to earn high scores. It also warns against plagiarism, emphasizes putting in sincere effort, knowing classmates to stay on track, and understanding what algorithms are through definitions and examples.

Uploaded by

umairprimus
Copyright
© © All Rights Reserved
Available Formats
Download as PPSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Design and Analysis of Algorithms: by Syed Farooq Zaidi

This document provides tips and guidelines for passing a course on design and analysis of algorithms. It outlines three main tips: 1) understand both knowledge of algorithms as well as technical skills, 2) regularly attend and participate in class by taking notes, and 3) do well on semester work like assignments, quizzes and projects which provide more opportunities to earn high scores. It also warns against plagiarism, emphasizes putting in sincere effort, knowing classmates to stay on track, and understanding what algorithms are through definitions and examples.

Uploaded by

umairprimus
Copyright
© © All Rights Reserved
Available Formats
Download as PPSX, PDF, TXT or read online on Scribd
You are on page 1/ 38

Design and Analysis of Algorithms

By Syed Farooq Zaidi


Why?

•Calculate the complexity.


•Know where and when to use a particular algorithm.
Course guidelines

Tips tricks and insight to pass this course.


Tip 1: Know and HOW

Knowledge vs Technique
TIP2: Regular in CLASSES

•Have a Notebook and pencil at hand.


•Practice every week

•READ, READ and READ!


Tip3: Semester work

You have more chances to score high in semester


work.
Tip3: Semester work

•You have more chances to score high in semester work.

•Quizzes 5 – 10 15%

•Assignment 2 – 3 10%

•Project 1 10%

•Mid-Term 15%
Plagiarism  Cheating ‫یمانی‬-‫ے ا‬
---‫ ب‬
‫ دھوکا‬ -‫م‬-‫را‬-‫ح‬

MAKE YOUR SEMESTER WORK 0


Plagiarism  Cheating ‫یمانی‬-‫ے ا‬
---‫ ب‬ ‫ دھوکا‬ -‫م‬-‫را‬-‫ح‬

•‫ے کا کام اپنے نام سے جمع کرانا‬-‫کسی دوسر‬

•Plagiarism is the representation of another's, thoughts,


ideas, code, program, solutions or expressions as one's own
original work.
Tip4: Effort

•Put in sincere effort.


•You job to meet deadlines.

• Quizzes 5 – 10 15%
• Assignment2 – 3 10%
• Project 1 10%
• Mid-Term 15%
Tip 5: Know your classmates

•Have friends!
•Join study (this is the part of life you’ll miss the most)
•Keep check on each other regarding assignments, quizzes
and projects.
Why are you here?
https://youtu.be/GO5FwsblpT8
What are algorithms
Feedback from students

•‫یقہ‬-‫کسی بھی چیز کا طر‬


•Set of rules to do some work
•Any procedure or formula for solving a problem
•Sequence of actions
•The code you can not justify to others is called algorithms
•Small procedure or no. of steps required for problem
solving.
What is an algorithm

“Algorithms are basically the math that computers


use to decide stuff.”

– Keven Slavin
What are algorithms?

“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.”

– Cormen Book
What are algorithms?

“sequence of computational steps”

– Cormen Book
What are algorithms?

“An algorithm is the description of a pattern of


behaviour, expressed in terms of a well-understood,
finite repertoire of named (so-called "primitive")
actions of which it is assumed a priori that they can
be done (i.e. can be caused to happen).”

– Edger Dijkstra
Definition of algorithm by edger Dijkstra
•An algorithm is the description of a pattern of behaviour, expressed in terms of a well-understood, finite repertoire of named (so-called
"primitive") actions of which it is assumed a priori that they can be done (i.e. can be caused to happen).

•In writing down an algorithm, we start by considering the happening to take place as a process, dissected into a sequence of sub-actions to
be done in succession. If such a sub-action occurs in the well-understood, finite repertoire of named actions, the algorithm refers to it by
its name. If such a sub-action does not occur in the finite repertoire, the algorithm eventually refers to it by means of a sub-algorithm in
which the sub-action, in its turn, is regarded as a process, etc. until at the end all has been reduced to actions from the well-understood,
finite repertoire.

•The notion of an algorithm, of an executable precept for the establishing of a certain net effect, is very well known from daily life: knitting
patterns, directions for use, recipes and musical scores are all algorithms. And if one asks the way to the railway station in an unfamiliar
town, one asks essentially for an algorithm, for the description of a pattern of behaviour which, when followed, will lead to the desired goal.

•In our definition of an algorithm we have stressed that the primitive actions should be executable, that they should be done. "Go to the
other side of the square." is perfectly acceptable, "Go to hell.", however, is not an algorithm but a curse, because it cannot be done.

•Besides that we have stressed that the repertoire should be well-understood: between the one who composed the algorithm and the one who
intends to follow it there should be no misunderstanding about this repertoire. (In this respect knitting patterns are, as a rule, excellent,
recipes are of moderate quality while the instructions one gets when asking the way are usually incredibly bad!
Where it all started

•Muhammad ibn Musa Al Khwarizmi (780 – 850)


• https://youtu.be/FsSCSebRDiU?t=248
Other useful links

•https://www.youtube.com/watch?v=6hfOvs8pY1k

•https://www.youtube.com/watch?v=ENWVRcMGDoU
Analysis of algorithms

The theoretical study of computer program


performance and resource usage.
Revision
•What are algorithms
•Well-defined finite sequence of actions
•Take Input and give output
•Math for computers
•sequence of computational steps
•Tips
•Balance b/w Knowledge vs Technique
•Regular in Class -> Take notes -> book ->
•Avoid Plagiarism -> Cheating
•Communication
•Have Friends
•LMS keep checking
•Assignments, quizzes, projects -> score more on semester work

•Pale blue dot.


Lets look at some Algorithms!

function smthCool(takes array a of int) : returns int


let r = 0, create counting variables i & j; 3
for (i = 0; i < n; i++) do
for (j = i+1; j < n; j++) do 6
9
if (abs (a[j] - a[i]) > r) then
r = abs (a[j] - a[i]);
end for 1
end for
return r; 4
end smthCool Let's run it for this array!
How many times?

•How many times does the for-loop i runs?


•How many times does the for-loop j runs?
•How many times the whole array is traversed?
•What if we had 10,
•50,
•100 &
•10000 numbers?
•What if we had n numbers?
Do you have what it takes?

•Can you improve the algorithm?

!
Improved max difference

Find the max difference!


Function smthCool1(intput a array of int): return int
Begin
3
let p = a[0] and q=a[0] be 0;
for(i=1; i < n ; i++) 6
begin
if(p > a[i]) then p = a[i]; 9
if(q < a[i]) then q = a[i];
end 1
return q-p;
end
4
How many times?

•How many times the whole array is traversed?


•What if we had 1000 numbers?
•What if we had n numbers?
What have we learned?

•There are slow algorithms and fast algorithms!


How do we tell fast and slow for complex algorithms?
How to tell which algorithm is Fast?

•Execution time
•Dependent on compiler,
•System
•Memory
•Etc.

•Running Time
•What is running time?
Example : SORTING PROBLEM

•THE PROBLEM
•Input : <a1, a2, a3, a4, a5, …>
•Output: <a’1, a’2, a’3, a’4, a’5, …>| a’n < a’n+1
SOLUTION

3 6 7 8 9 2 4
for i from 1 to N
key = a[i]
j = i - 1
while j >= 0 and a[j] > key
a[j+1] = a[j]
j = j - 1
a[j+1] = key
next i
Running time

•Input
•What if the array is already sorted?
•What if the array size is increased?
•Parameterize (we talk in terms of input size n)

•Absolute running time – (depended on hardware and


software)
•Relative running time – (depends only on the algorithm)
Kinds of Analysis

•Worst-Case (usually)
•T(n) – max time on any input of size n.

•Average-Case (sometimes)
•T(n) – expected time on all inputs of size n.
•assumptions
•Best-Case (almost never)
Asymptotic analysis

•The BIG IDEA – Algorithms

•Asymptotic Analysis
End of Lecture!

You might also like