Design and Analysis of Algorithms: by Syed Farooq Zaidi
Design and Analysis of Algorithms: by Syed Farooq Zaidi
Knowledge vs Technique
TIP2: Regular in CLASSES
•Quizzes 5 – 10 15%
•Assignment 2 – 3 10%
•Project 1 10%
•Mid-Term 15%
Plagiarism Cheating یمانی-ے ا
--- ب
دھوکا -م-را-ح
• 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
– Keven Slavin
What are algorithms?
– Cormen Book
What are algorithms?
– Cormen Book
What are algorithms?
– 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
•https://www.youtube.com/watch?v=6hfOvs8pY1k
•https://www.youtube.com/watch?v=ENWVRcMGDoU
Analysis of algorithms
!
Improved max difference
•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)
•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
•Asymptotic Analysis
End of Lecture!