KEMBAR78
Design and analysis of algorithms - Abstract View | PPTX
Design and Analysis of
Algorithms
Waqas Nawaz, Ph.D.
Innopolis University, Russia
Outline
 Introduction
 Motivation
 Designing an Algorithm
 Analysis of Algorithms
 Conclusion
 References
2
Introduction
 Algorithm
 A set of well defined rules to solve a computation problem
 Specific examples: Find Minimum! and Multiplication
 Design: the description of algorithm (pseudo language) and
proof of its correctness
 Analysis: performance evaluation (complexity analysis)
3
AlgorithmInput Output
American British
input
output
N1 
N2 
Motivation: Algorithm Efficiency vs. CPU
Speed
 Task: Sort n=106 numbers
 Computer A = 109 instructions/second
 Algorithm A = 2n2 instructions
 Computer B = 107 instructions/second
 Algorithm B = 50nlgn instructions
 A =
 B =
4
  seconds2000
second/nsinstructio10
nsinstructio102
9
26


  seconds100
second/nsinstructio10
nsinstructiolg101050
7
66


20 times better!!
Algorithm Design Techniques
 Brute Force & Exhaustive
Search
 follow definition / try all
possibilities
 Divide & Conquer
 break problem into distinct
subproblems
 Transformation
 convert problem to another
one
 Dynamic Programming
 break problem into overlapping
subproblems
 Greedy
 repeatedly do what is best now
 Iterative Improvement
 repeatedly improve current
solution
 Randomization
 use random numbers
5
Analysis of Algorithms
 Worst case: (e.g. cards reversely ordered)
 Provides an upper bound on running time
 An absolute guarantee that the algorithm would
not run longer, no matter what the inputs are
 Best case: (e.g., cards already ordered)
 Input is the one for which the algorithm runs the
fastest
 Average case: (general case)
 Provides a prediction about the running time
 Assumes that the input is random
6
2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A
Conclusion
 We studied the importance of designing and analysis of algorithm
 Different methods and approaches are discussed to create and
evaluate an algorithm
 It helps us to utilize resources effectively to achieve desired results
in a reasonable time
 Related Study Materials
 Text Books
 Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest and Clifford Stein,
Introduction to Algorithms, Third Edition, 2009.
 Kleinberg and Tardos, Algorithm Design, 2005.
 Online Lectures by Tim Roughgarden on Algorithms: Design and Analysis,
Part 1, Stanford University
7
References
1. Adil Khan, Course slides on Data structure and algorithms, Innopolis
University, 2016.
2. Monica Nicolescu, course slides on Analysis of Algorithms
CS 477/677.
3. Arjun Dasgupta et. al., CSE5311, DESIGN AND ANALYSIS OF
ALGORITHMS.
4. Jennifer Welch, CSCE 411, Design and Analysis of Algorithms, 2013.
5. Anany Levitin, Fundamentals of the Analysis of Algorithm Efficiency,
2nd edition, chapter 2.
8
Appendix: Farmer Crosses River Puzzle
 A farmer wants to cross a river and
take with him a wolf, a goat, and a
cabbage.
 There is a boat that can fit himself
plus either the wolf, the goat, or
the cabbage.
 If the wolf and the goat are alone on
one shore, the wolf will eat the goat.
 If the goat and the cabbage are
alone on the shore, the goat will eat
the cabbage.
 How can the farmer bring the wolf,
the goat, and the cabbage across
the river?
9
Appendix: Our Machine Model
 RAM: Generic Random Access Machine
 Executes operations sequentially
 Set of primitive operations:
 Arithmetic. Logical, Comparisons, Function calls
 Simplifying assumption: all ops cost 1 unit
 Eliminates dependence on the speed of our computer,
otherwise impossible to verify and to compare
10
Sample Algorithm
FINDING LARGEST NUMBER
INPUT: unsorted array ‘A[n]’of n numbers
OUTPUT: largest number
----------------------------------------------------------
1 large ← A[j]
2 for j ← 2 to length[A]
3 if large < A[j]
4 large ← A[j]
5 end
Space and Time Analysis
(Largest Number Scan Algorithm)
SPACE S(n): One “word” is required to run the algorithm (step
1…to store variable ‘large’)
TIME T(n): n-1 comparisons are required to find the largest
(every comparison takes one cycle)
running time execution time
for basic operation
Number of times
basic operation is
executed
input size
T(n) ≈ copC(n)

Design and analysis of algorithms - Abstract View

  • 1.
    Design and Analysisof Algorithms Waqas Nawaz, Ph.D. Innopolis University, Russia
  • 2.
    Outline  Introduction  Motivation Designing an Algorithm  Analysis of Algorithms  Conclusion  References 2
  • 3.
    Introduction  Algorithm  Aset of well defined rules to solve a computation problem  Specific examples: Find Minimum! and Multiplication  Design: the description of algorithm (pseudo language) and proof of its correctness  Analysis: performance evaluation (complexity analysis) 3 AlgorithmInput Output American British input output N1  N2 
  • 4.
    Motivation: Algorithm Efficiencyvs. CPU Speed  Task: Sort n=106 numbers  Computer A = 109 instructions/second  Algorithm A = 2n2 instructions  Computer B = 107 instructions/second  Algorithm B = 50nlgn instructions  A =  B = 4   seconds2000 second/nsinstructio10 nsinstructio102 9 26     seconds100 second/nsinstructio10 nsinstructiolg101050 7 66   20 times better!!
  • 5.
    Algorithm Design Techniques Brute Force & Exhaustive Search  follow definition / try all possibilities  Divide & Conquer  break problem into distinct subproblems  Transformation  convert problem to another one  Dynamic Programming  break problem into overlapping subproblems  Greedy  repeatedly do what is best now  Iterative Improvement  repeatedly improve current solution  Randomization  use random numbers 5
  • 6.
    Analysis of Algorithms Worst case: (e.g. cards reversely ordered)  Provides an upper bound on running time  An absolute guarantee that the algorithm would not run longer, no matter what the inputs are  Best case: (e.g., cards already ordered)  Input is the one for which the algorithm runs the fastest  Average case: (general case)  Provides a prediction about the running time  Assumes that the input is random 6 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A
  • 7.
    Conclusion  We studiedthe importance of designing and analysis of algorithm  Different methods and approaches are discussed to create and evaluate an algorithm  It helps us to utilize resources effectively to achieve desired results in a reasonable time  Related Study Materials  Text Books  Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest and Clifford Stein, Introduction to Algorithms, Third Edition, 2009.  Kleinberg and Tardos, Algorithm Design, 2005.  Online Lectures by Tim Roughgarden on Algorithms: Design and Analysis, Part 1, Stanford University 7
  • 8.
    References 1. Adil Khan,Course slides on Data structure and algorithms, Innopolis University, 2016. 2. Monica Nicolescu, course slides on Analysis of Algorithms CS 477/677. 3. Arjun Dasgupta et. al., CSE5311, DESIGN AND ANALYSIS OF ALGORITHMS. 4. Jennifer Welch, CSCE 411, Design and Analysis of Algorithms, 2013. 5. Anany Levitin, Fundamentals of the Analysis of Algorithm Efficiency, 2nd edition, chapter 2. 8
  • 9.
    Appendix: Farmer CrossesRiver Puzzle  A farmer wants to cross a river and take with him a wolf, a goat, and a cabbage.  There is a boat that can fit himself plus either the wolf, the goat, or the cabbage.  If the wolf and the goat are alone on one shore, the wolf will eat the goat.  If the goat and the cabbage are alone on the shore, the goat will eat the cabbage.  How can the farmer bring the wolf, the goat, and the cabbage across the river? 9
  • 10.
    Appendix: Our MachineModel  RAM: Generic Random Access Machine  Executes operations sequentially  Set of primitive operations:  Arithmetic. Logical, Comparisons, Function calls  Simplifying assumption: all ops cost 1 unit  Eliminates dependence on the speed of our computer, otherwise impossible to verify and to compare 10
  • 11.
    Sample Algorithm FINDING LARGESTNUMBER INPUT: unsorted array ‘A[n]’of n numbers OUTPUT: largest number ---------------------------------------------------------- 1 large ← A[j] 2 for j ← 2 to length[A] 3 if large < A[j] 4 large ← A[j] 5 end
  • 12.
    Space and TimeAnalysis (Largest Number Scan Algorithm) SPACE S(n): One “word” is required to run the algorithm (step 1…to store variable ‘large’) TIME T(n): n-1 comparisons are required to find the largest (every comparison takes one cycle) running time execution time for basic operation Number of times basic operation is executed input size T(n) ≈ copC(n)