Lecture # 1-3
Todayโ€™s Agenda
ODefinition
OAlgorithm Writing Styles
OHistory
OIntroduction to the syllabus
Algorithm?
Definition of Algorithm
OAny computing problem can be
solved by executing a series of
actions in a specific order, that is
called algorithm
OAlgorithm is a well-defined
computational function or
procedure that take some value or
set of values as an input and
produces some value or set of
value as an output
Algorithms
Algorithm is a function or procedure which takes an
input and produces some output
f(n) is a step by step solution of a
problem
f(n)
Input(n)
Output (n`)
Algorithm Writing Style..
OAlgorithm can be written in any manner
unless they provide the solution of a
problem (Correct )
OWhy to write Algorithm?
OTwo styles are mostly commonly used:
OPseudo-code
OFlow Chart
Algorithms (Pseudo-code)
Algorithms (Flowchart)
Ovoid bubbleSort(int Size, number[]){
Ofor(int i=0;i<Size-1;i++){
O for(int j=0;j<Size-1;j++){
Oif(number[j]<number[j+1]){
O int temp=number[j];
O number[j]=number[j+1];
O number[j+1]=temp;
O }
O }
O}
Algorithms (c++ Code)
What is Preferableโ€ฆ.
Pseudo-code
Algorithms (Pseudo-code)
Pseudo-code conventions in page
20 & 21
Text Book
Oโ€œIntroduction to
Algorithmsโ€, Thomas H.
Cormen, Charles E, Leiserson,
Ronald L. Rivest, Clifford Stein.
MIT Press, Third Edition
Algorithm History
OFirst used by Abu Jaโ€™far Muhammed
Ibn Musa al-Khowarizmi (780-850)
OMember โ€œhouse of wisdomโ€ in
Baghdad
OOriginal word โ€œalgorismโ€ and this
word evolved into Algorithm in
eighteen century
Algorithm History
OHis book โ€œHindu Numeralsโ€ is
basis of modern decimal
notation
OHe give the concept of โ€œzeroโ€
OWestern Europe first learned
Algebra from him
OAlgebra comes from al-jabr, part
of title of his book Kitab al-jabr
wโ€™al Muquabala
Summary of Last Discussion
An algorithm is a concrete and
step by step solution of some
computational problem written in
pseudo code form which take a
value or (set of Values ) as input
and generate a value or (set of
Values ) as output
Algorithms (Pseudo-code)
f(n)
Input(n)
Output (n`)
Algorithms (Pseudo-code)
Algorithms are:
โ€ข Correct
โ€ข Algorithms are generic (Not
written for specific size and type
of input)
Introduction To The
Course
Introduction To The Course
1. Basic concepts
O Algorithm definition and importance in CS
O Analyzing Algorithm, Algorithm designing
O Growth of function Asymptotic Notation
O Recurrence and Mathematical Induction: The
substitution method, Recursion Tree Method, The Master
Method
2. Sorting
O Heapsort: Heap sort, maintaining a heap property,
Building a heap, the heap sort algorithm.
O Quicksort: Description of Quick sort, Performance of
Quick sort.
O Sorting in linear time: Lower bound for sorting,
Counting sort, Radix sort, Bucket sort.
3. Advance Design Techniques
O Dynamic Programming: Dynamic Programming,
Matrix Chain Multiplication, Knapsack Problem.
O Greedy Algorithm: Elements of Greedy Algorithm,
Huffman Code
Introduction To The Course
4. Graph Algorithms
O Elementary Graph Algorithm: Some concepts
about Graphs, Representation of graphs, Breath
First Search, Depth First Search, Topological
sort.
O Minimum Spanning Tree: Krushkal Algorithm,
Prims Algorithm.
O Single Source shortest Paths: Bellman Ford
Algorithm, Single Source Shortest paths in direct
acyclic graph, Dijkstraโ€™s Algorithm.
O All Pairs shortest Paths: Floyd Warshall
Algorithm
5. NP-Complete Problems
O Polynomial time
O Polynomial time verification
O NP-completeness and reducibility
Importance of studying this
subject
OImproves problem solving skill
OGives mathematical foundations for
analyzing algorithms
OSelection among lots of candidate
solutions
OLearn good designing techniques
OCore area of computer science and
computer programming.
In the Last Lecture
ODefinition
ORepresentation of Algorithms
OPseudo-Code
OFlow Chart
OHistory
OCourse Introduction
Searching
OSearching an elements from array
(Linear Search)
OLinearSearch( Record[1โ€ฆ..n], m)
Searching
LinearSearch( Record[1โ€ฆ..n], m)
1. k=false
2. for I =1 to n
3. if Record[i]==m
4. K=true;
5. break;
6. if k==true
7. print โ€œElement foundโ€
Todays Agenda
OAnalysis of Algorithms
(Criteria)
OHow Efficient an Algorithm is
?
OUnderstanding Design and
Analysis ( A Selection
Problem )
Criterion for analyzing
Efficiency of Algorithm is measured in
terms of computation recourses
used:
O Running time (Most Often)
O Memory used
OEtc.
We should be agree on some
criterion
Mathematical Model of
computation
OAnalysis should be
independent
OArchitecture
OProgramming Language
OFor this we need to assume
an Architecture?
Random Access Machine
(RAM)
OSingle Process : Instruction
are executed one by one (not
parallelism)
OInfinitely large random access
memory
Writing Good Algorithmsโ€ฆ
OUnderstand the problem
ODevelop Thinking habit
OThink Easy (Build on easy
solutions)
Design And Analysis
In order to understand design
and analysis procedure we will
do an example
Selection Problem
OSuppose you want to purchase a Laptop
OYou want to pick fastest Laptop
OBut fast Laptops are expensive
OYou cannot decide which one is more
important price or speed
Selection Problem
ODefinitely do not want a Laptop if
there is a another Laptop that is
both fast and cheaper
OWe say that fast cheap Laptops
โ€œdominatesโ€ the slow expensive
OSo given a list of Laptops we
want those that are not
dominated by the other?
Criterion for selection
Two criterion for selection:
OSpeed
OPrice
Mathematical Model
O P is in two dimensional space and its coordinates are
P = (p.x , p.y)
(x,y)
O x is speed of Laptop
O y is negation of price
We can say about y
O High value of y mean cheap Laptop and low y means
Laptop is expensive
O A point p is said to be dominated by a point q if p.x
<= q.x and p.y <= q.y
O In an array of points (Laptops) P={p1,p2,p3,โ€ฆ.,pn} a
maximal point is not dominated by any other point
Example
OGiven a set of point P={p1,p2,p3,โ€ฆ.,pn }
output the maximal points
OThose points of P such that pi is not
dominated by any other point

Algo_lecture1-3.pptx

  • 1.
  • 2.
    Todayโ€™s Agenda ODefinition OAlgorithm WritingStyles OHistory OIntroduction to the syllabus
  • 3.
  • 4.
    Definition of Algorithm OAnycomputing problem can be solved by executing a series of actions in a specific order, that is called algorithm OAlgorithm is a well-defined computational function or procedure that take some value or set of values as an input and produces some value or set of value as an output
  • 5.
    Algorithms Algorithm is afunction or procedure which takes an input and produces some output f(n) is a step by step solution of a problem f(n) Input(n) Output (n`)
  • 6.
    Algorithm Writing Style.. OAlgorithmcan be written in any manner unless they provide the solution of a problem (Correct ) OWhy to write Algorithm? OTwo styles are mostly commonly used: OPseudo-code OFlow Chart
  • 7.
  • 8.
  • 9.
    Ovoid bubbleSort(int Size,number[]){ Ofor(int i=0;i<Size-1;i++){ O for(int j=0;j<Size-1;j++){ Oif(number[j]<number[j+1]){ O int temp=number[j]; O number[j]=number[j+1]; O number[j+1]=temp; O } O } O} Algorithms (c++ Code)
  • 10.
  • 11.
  • 12.
    Text Book Oโ€œIntroduction to Algorithmsโ€,Thomas H. Cormen, Charles E, Leiserson, Ronald L. Rivest, Clifford Stein. MIT Press, Third Edition
  • 13.
    Algorithm History OFirst usedby Abu Jaโ€™far Muhammed Ibn Musa al-Khowarizmi (780-850) OMember โ€œhouse of wisdomโ€ in Baghdad OOriginal word โ€œalgorismโ€ and this word evolved into Algorithm in eighteen century
  • 14.
    Algorithm History OHis bookโ€œHindu Numeralsโ€ is basis of modern decimal notation OHe give the concept of โ€œzeroโ€ OWestern Europe first learned Algebra from him OAlgebra comes from al-jabr, part of title of his book Kitab al-jabr wโ€™al Muquabala
  • 15.
    Summary of LastDiscussion An algorithm is a concrete and step by step solution of some computational problem written in pseudo code form which take a value or (set of Values ) as input and generate a value or (set of Values ) as output
  • 16.
  • 17.
    Algorithms (Pseudo-code) Algorithms are: โ€ขCorrect โ€ข Algorithms are generic (Not written for specific size and type of input)
  • 18.
  • 19.
    Introduction To TheCourse 1. Basic concepts O Algorithm definition and importance in CS O Analyzing Algorithm, Algorithm designing O Growth of function Asymptotic Notation O Recurrence and Mathematical Induction: The substitution method, Recursion Tree Method, The Master Method 2. Sorting O Heapsort: Heap sort, maintaining a heap property, Building a heap, the heap sort algorithm. O Quicksort: Description of Quick sort, Performance of Quick sort. O Sorting in linear time: Lower bound for sorting, Counting sort, Radix sort, Bucket sort. 3. Advance Design Techniques O Dynamic Programming: Dynamic Programming, Matrix Chain Multiplication, Knapsack Problem. O Greedy Algorithm: Elements of Greedy Algorithm, Huffman Code
  • 20.
    Introduction To TheCourse 4. Graph Algorithms O Elementary Graph Algorithm: Some concepts about Graphs, Representation of graphs, Breath First Search, Depth First Search, Topological sort. O Minimum Spanning Tree: Krushkal Algorithm, Prims Algorithm. O Single Source shortest Paths: Bellman Ford Algorithm, Single Source Shortest paths in direct acyclic graph, Dijkstraโ€™s Algorithm. O All Pairs shortest Paths: Floyd Warshall Algorithm 5. NP-Complete Problems O Polynomial time O Polynomial time verification O NP-completeness and reducibility
  • 21.
    Importance of studyingthis subject OImproves problem solving skill OGives mathematical foundations for analyzing algorithms OSelection among lots of candidate solutions OLearn good designing techniques OCore area of computer science and computer programming.
  • 22.
    In the LastLecture ODefinition ORepresentation of Algorithms OPseudo-Code OFlow Chart OHistory OCourse Introduction
  • 23.
    Searching OSearching an elementsfrom array (Linear Search) OLinearSearch( Record[1โ€ฆ..n], m)
  • 24.
    Searching LinearSearch( Record[1โ€ฆ..n], m) 1.k=false 2. for I =1 to n 3. if Record[i]==m 4. K=true; 5. break; 6. if k==true 7. print โ€œElement foundโ€
  • 25.
    Todays Agenda OAnalysis ofAlgorithms (Criteria) OHow Efficient an Algorithm is ? OUnderstanding Design and Analysis ( A Selection Problem )
  • 26.
    Criterion for analyzing Efficiencyof Algorithm is measured in terms of computation recourses used: O Running time (Most Often) O Memory used OEtc. We should be agree on some criterion
  • 27.
    Mathematical Model of computation OAnalysisshould be independent OArchitecture OProgramming Language OFor this we need to assume an Architecture?
  • 28.
    Random Access Machine (RAM) OSingleProcess : Instruction are executed one by one (not parallelism) OInfinitely large random access memory
  • 29.
    Writing Good Algorithmsโ€ฆ OUnderstandthe problem ODevelop Thinking habit OThink Easy (Build on easy solutions)
  • 30.
    Design And Analysis Inorder to understand design and analysis procedure we will do an example
  • 31.
    Selection Problem OSuppose youwant to purchase a Laptop OYou want to pick fastest Laptop OBut fast Laptops are expensive OYou cannot decide which one is more important price or speed
  • 32.
    Selection Problem ODefinitely donot want a Laptop if there is a another Laptop that is both fast and cheaper OWe say that fast cheap Laptops โ€œdominatesโ€ the slow expensive OSo given a list of Laptops we want those that are not dominated by the other?
  • 33.
    Criterion for selection Twocriterion for selection: OSpeed OPrice
  • 34.
    Mathematical Model O Pis in two dimensional space and its coordinates are P = (p.x , p.y) (x,y) O x is speed of Laptop O y is negation of price We can say about y O High value of y mean cheap Laptop and low y means Laptop is expensive O A point p is said to be dominated by a point q if p.x <= q.x and p.y <= q.y O In an array of points (Laptops) P={p1,p2,p3,โ€ฆ.,pn} a maximal point is not dominated by any other point
  • 35.
    Example OGiven a setof point P={p1,p2,p3,โ€ฆ.,pn } output the maximal points OThose points of P such that pi is not dominated by any other point