WKES3311:ANALISIS ALGORITMA - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

WKES3311:ANALISIS ALGORITMA

Description:

To make statement we say: f(n) Worst / best/average ... EXAMPLE 1 ... For T(n) a non-negatively valued function, T(n) is in set (g(n)) if there exist two ... – PowerPoint PPT presentation

Number of Views:63
Avg rating:3.0/5.0
Slides: 24
Provided by: UM17
Category:

less

Transcript and Presenter's Notes

Title: WKES3311:ANALISIS ALGORITMA


1
WKES3311ANALISIS ALGORITMA
2
WHICH ALGORITHM?
  • The higher growth rate?
  • OR
  • The lower growth rate?

3
ASYMPTOTIC ANALYSIS
  • Refers to the study of an algorithm as the input
    size gets big or reaches a limit
  • It has its limitation

4
ALGORITHM BEHAVIOUR
  • Terms describing the running time equation for an
    algorithm

5
UPPER BOUND O(f(n)) BIG OH
  • The highest growth rate that an algorithm can
    have
  • To make statement we say

Worst / best/average
f(n)
6
UPPER BOUND PRECISE STATEMENT
  • For T(n) a non-negatively valued function, T(n)
    is in set if there exist two positive
    constants c and n0 such that for all n gt
    n0

7
EXAMPLE 1
  • Consider the sequential search algorithm for
    finding a specific value in an array of integers

8
EXAMPLE 2
  • For a particular algorithm, T(n) c1n2 c2n in
    the average case where c1 and c2 are positive
    numbers

9
LOWER BOUND ?(g(n)) BIG OMEGA DEFINITION
  • For T(n) a non-negatively valued function, T(n)
    is in set ?(g(n)) if there exist two
  • OR
  • T(n) is in the set ?(g(n)) if there exists a
    positive constant c such that

10
EXAMPLE 1
  • Assume T(n)c1n2 c2n for c1 and c2 gt 0.
  • So, T(n) ? c1n2 for c c1 and n01.

11
EXAMPLE 2
12
?(h(n)) THE BIG THETA
  • When the upper and lower bound for an algorithm
    are the same within a constant factor we indicate
    this by using ?(big-Theta) notation.

13
EXAMPLE 1
  • Sequential Search Algorithm
  • So we say that this algorithm is both in O(n) and
    ?(n) OR JUST ?(n)

14
SIMPLIFYING RULES
  • If f(n) is in
    then f(n) is in O(h(n))
  • If f(n) for any
    constant kgt0, then f(n) is in O(g(n)
  • If f1(n) is in is in
    O(g2(n)),
    O(max(g1(n),g2(n)))
  • If f1(n) is in O(g1(n)) and f2(n) is in
  • Rule also holds for ? and ? notations

15
CALCULATING THE RUNNING TIME
  • Example 1
  • Since the assignment statement takes constant
    time, it is ?(1)

16
EXAMPLE 2
  • sum 0
  • for (i1iltni)
  • sum n

17
EXAMPLE 3
  • Asignment (sum0)
  • Second loop
  • First loop
  • c3j(sum)
  • Therefore its c3
  • sum 0
  • for (j1jltnj) //First for loop
  • for (i1iltji)// is a double loop
  • sum
  • for (k0kltnk) // Second for loop
  • Akk
  • By rule(3),

18
EXAMPLE 4
  • sum10
  • for (k1kltnk2) // Do log n times
  • for(j1jltnj) // Do n times
  • sum
  • sum20
  • For(k1kltnk22) // Do log n times
  • for(j1jltkj) // Do k times
  • sum2
  • simply
  • simply

19
EXAMPLE 5
  • Long fact (int n) //Compute n!
  • //To fit n! in a long variable, require nlt12
  • Assert((ngt0)(nlt12)), Input out of range)
  • if (nlt1) return 1
  • return n fact(n-1)

20
RECURRENCE RELATIONSHIP T(n)T(n-1) 1
  • T(n) T(n-1)1
  • (T(n-2)1)1, how can we write this in terms of
    summation?
  • T(n-3)3 , therefore we conclude
  • T(n) T(n-(n-1))

21
PROOF BY INDUCTION
  • Theorem1 T(n) T(n-1) 1 T(1)0 has
    closed-form solution T(n)n-1
  • Proof To prove the base case we observe

22
SPACE BOUNDS
  • The
    to measure space are similar to those used to
  • Concepts of can also
    be applied with

23
HOMEWORKS
  • What are the space requirements for a two
    dimensional array?
  • What are the space requirements for n Boolean
    flags?
Write a Comment
User Comments (0)
About PowerShow.com