CSE 221/ICT221 Analysis and Design of Algorithms Lecture 03: Introduction to algorithms analysis - PowerPoint PPT Presentation

Loading...

PPT – CSE 221/ICT221 Analysis and Design of Algorithms Lecture 03: Introduction to algorithms analysis PowerPoint presentation | free to download - id: 61aa14-ODJkN



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

CSE 221/ICT221 Analysis and Design of Algorithms Lecture 03: Introduction to algorithms analysis

Description:

CSE 221/ICT221 Analysis and Design of Algorithms Lecture 03: Introduction to algorithms analysis Asst. Dr.Surasak Mungsing E-mail: Surasak.mu_at_spu.ac.th – PowerPoint PPT presentation

Number of Views:210
Avg rating:3.0/5.0
Slides: 25
Provided by: ICT70
Learn more at: http://csits.spu.ac.th
Category:

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: CSE 221/ICT221 Analysis and Design of Algorithms Lecture 03: Introduction to algorithms analysis


1
CSE 221/ICT221 Analysis and Design of
Algorithms Lecture 03 Introduction to
algorithms analysis
  • Asst. Dr.Surasak Mungsing
  • E-mail Surasak.mu_at_spu.ac.th

2
Meaning of Algorithm
  • Algorithm
  • Recipe for getting things done successfully
  • "Recipe" well defined steps of doing
  • "things" computation problems which defined
    input/output
  • "done" solved within definite time and steps
  • "successfully" done correctly
  • Any special method of solving a certain kind of
    problem - Webster Dictionary

3
Computer Program
  • A computer program (also a software program, or
    just a program) is a sequence of instructions
    written to perform a specified task for a
    computer.
  • A computer program in the form of a
    human-readable, computer programming language is
    called source code. Source code may be converted
    into an executable image by a compiler or
    executed immediately with the aid of an
    interpreter.
  • Algorithm is a step by step outline or flowchart
    how to solve a problem, but program is an
    implemented coding of a solution to a problem
    based on the algorithm.
  • http//wiki.answers.com/Q/What_is_the_differences
    _between_algorithm_and_programixzz1GXvHCUbb

CSE221/ICT221 Analysis and Design of Algorithms
4
Example
Problem Find the smallest integer from a given
set of integers stored in an array
INPUT
Algorithm
instance
OUTPUT
m a1 for I2 to size of input if m gt
aI then maI return m
11
25, 90, 53, 23, 11, 34
Data-Structure
CSE221/ICT221 Analysis and Design of Algorithms
5
Problem
Problem Find the smallest integer from a given
set of integers stored in an array
Algorithm A
CSE221/ICT221 Analysis and Design of Algorithms
6
Algorithm B (use two temporary arrays)
  • copy the input a to array t1
  • assign n ? size of input
  • While n gt 1
  • For i ? 1 to n /2
  • t2 i ? min (t1 2i , t1 2i
    1 )
  • copy array t2 to t1
  • n ?n/2
  • Output t21

CSE221/ICT221 Analysis and Design of Algorithms
7
Algorithm C
  1. Sort the input in increasing order.
  2. Return the first element of the sorted data.

black box
Sorting
CSE221/ICT221 Analysis and Design of Algorithms
8
Algorithm D
Test each data whether it is the smallest one
  • i ? 0
  • flag ? true
  • while flag
  • i ? i 1
  • min ? a i
  • flag ? false
  • for j ? 1 to size of input
  • if min gt a i then flag ?
    true
  • 3. output min

CSE221/ICT221 Analysis and Design of Algorithms
9
Which algorithm is better?
  • All algorithms can solve the problem
    correctly, but which one is better?
  • Consideration is based on running time (number of
    operations needed) and amount of memory used
  • ????????
  • ?????????????????????????????????????????????????
    ??????????????????????????????

CSE221/ICT221 Analysis and Design of Algorithms
10
Correctness, efficiency and measurement model
  • Correctness ability to solve the problem
    correct ly in all cases
  • Efficiency required resources for
    algorithm to work correctly
  • Time number of execution
  • Space memory space required
  • Measurement model worst case
  • average case
    best case

CSE221/ICT221 Analysis and Design of Algorithms
11
Time vs. Size of Input
Input Size
Measurement parameterized by the size of the
input.
The algorithms A,B,C are implemented and run in a
PC. Algorithms D is implemented and run in a
supercomputer.
CSE221/ICT221 Analysis and Design of Algorithms
12
What is Algorithm Analysis?
  • Measurement of time complexity of algorithms
  • Techniques that drastically reduce the running
    time of an algorithm
  • A mathematical framework that more rigorously
    describes the running time of an algorithm

CSE221/ICT221 Analysis and Design of Algorithms
13
Time required for small size of inputs
CSE221/ICT221 Analysis and Design of Algorithms
14
Time required for intermediate size of inputs
CSE221/ICT221 Analysis and Design of Algorithms
15
Asymtotic behavior
  • A line whose distance to a given curve tends to
    zero. An asymptote may or may not intersect its
    associated curve.
  • Asymptote
  • The x and y axes are asymptotes of the hyperbola
    xy 1.
  • Asymptotic
  • 1. (Mathematics) of or referring to an asymptote
  • 2. (Mathematics) (of a function, series, formula,
    etc.) approaching a given value or condition, as
    a variable or an expression containing a variable
    approaches a limit, usually infinity

16
Asymptotic Performance
  • asymptotic performance
  • In mathematics, computer science, and related
    fields, big-O notation (along with the closely
    related big-Omega notation, big-Theta notation,
    and little o notation) describes the limiting
    behavior of a function when the argument tends
    towards a particular value or infinity, usually
    in terms of simpler functions.
  • Efficiency of an algorithm
  • Running time
  • Memory/storage requirements
  • Bandwidth/power requirements/logic gates/etc.

CSE221/ICT221 Analysis and Design of Algorithms
17
Analysis
  • In computer science, best, worst and average
    cases of a given algorithm express what the
    resource usage is at least, at most and on
    average, respectively. Usually the resource being
    considered is running time, but it could also be
    memory or other resources.
  • Best case
  • The term best-case performance is used in
    computer science to describe the way an algorithm
    behaves under optimal conditions.
  • Worst case
  • the worst-case execution time is often of
    particular concern since it is important to know
    how much time might be needed in the worst case
    to guarantee that the algorithm will always
    finish on time.
  • Average case
  • Random (equally likely) inputs
  • Real-life inputs

CSE221/ICT221 Analysis and Design of Algorithms
18
Growth rate of functions
CSE221/ICT221 Analysis and Design of Algorithms
19
Classification of functions based on growth rate
  • asymptotic growth rate, asymptotic order, or
    order of functions
  • Comparison of functions by ignoring constant
    factors and small input
  • big oh O(g), big theta ?(g) and big omega ?(g)

?(g) functions with growth rates at least as
fast as function g
?(g) functions with growth rates as fast as
function g
O(g) functions with growth rates not faster than
that of function g
CSE221/ICT221 Analysis and Design of Algorithms
20
Classifying functions by their Asymptotic Growth
Rates
  • O(g(n)), Big-Oh of g of n, the Asymptotic Upper
    Bound
  • ?(g(n)), Theta of g of n, the Asymptotic Tight
    Bound and
  • ?(g(n)), Omega of g of n, the Asymptotic Lower
    Bound.

CSE221/ICT221 Analysis and Design of Algorithms
21
Example
  • Example f(n) n2 5n 13.
  • The constant 13 is not change, when n is larger
    so there is no significant for considering the
    lower order terms , which is 5n, when in
    comparison with the term in the order of n2
  • Therefore we may sat that f(n) O(n2)
  • Question What is the meaning of f(n)
    O(g(n))?
  • Answer This means f is the same order of
    magnitude as g

CSE221/ICT221 Analysis and Design of Algorithms
22
The meaning of Big O
  • Q What is the meaning of f1(n) O(1)?
  • A f1(n) O(1) means that for all ngt a certain
    value ( i.e. n0 ), f1 will be bounded by a
    constant value
  • Q What is the meaning of f2(n) O(n log n)?
  • A f2(n) O(n lg n) means that for all ngt a
    certain value ( i.e. n0 ) f2 will be bounded by
    a constant number times n log n or f2 is in the
    same order of magnitude as f(n log n).
  • In general, f(n) O(g(n)) means f(n) and g(n)
    are in the same order of magnitude (i.e. O(g(n))

CSE221/ICT221 Analysis and Design of Algorithms
23
Exercise
  1. What is the different between algorithms and
    programs?
  2. What factors influence the performance of an
    algorithm?
  3. How do we measure the performance of algorithms?
  4. What are Big O, Big Theta, Big Omega?
  5. Write Big-O of functions in ascending order

CSE221/ICT221 Analysis and Design of Algorithms
24
(No Transcript)
About PowerShow.com