List ADTs - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

List ADTs

Description:

How to compare two algorithms (both solving same problem) in terms of their efficiency ... If we run algorithms on different computer we will get different times ... – PowerPoint PPT presentation

Number of Views:40
Avg rating:3.0/5.0
Slides: 24
Provided by: bal1
Category:
Tags: adts | list

less

Transcript and Presenter's Notes

Title: List ADTs


1
Algorithm Analysis
Capt Balazs Michelson 366
2
Algorithm Analysis
  • In other words Analysis of Algorithms
  • Analysis examination of a complex, its elements,
    and their relations
  • Algorithm step-by-step procedure for solving a
    problem or accomplishing some end
  • Both from Mirriam-Webster dictionary

3
Algorithm
  • Well defined computational procedure
  • May take some value or set of values as input
  • Produces some value or set of values as output
  • Sequence of computational steps to transform
    input to output
  • Tool for solving a well-specified (computational)
    problem

4
Algorithm Analysis
  • Were going to look at
  • How to analyze measure efficiency of algorithms
  • How to compare two algorithms (both solving same
    problem) in terms of their efficiency

5
Better Algorithms
  • Robust able to deal with unexpected or
    erroneous inputs
  • Time how fast it is
  • Space how much memory or bandwidth it takes
  • Ease how easy it is to implement, understand,
    or modify

Where well focus
Hard to measure
Easy to measure
6
Algorithm
  • Well defined problem

7
  • We have two algorithms, we can only use one
  • Choose the better one
  • What does it mean to be better?

8
Time Analysis of alg1 alg2
  • We use System.currentTimeMillis() to figure out
    how long the algorithms take

k
9
alg1 alg2
  • The execution times are not constant
  • Both grow as k increases.
  • For given algorithm, the running time is a
    function of input (in this case k)
  • Shape of graph is important
  • Rate at which it grows as k increases
  • Growth rate of an algorithms run-time function
    is very important

10
Time Analysis
  • If we run algorithms on different computer we
    will get different times
  • Processor speed, operating system, memory, etc.
  • So run time wont really tell us an algorithms
    speed We need a better way

11
So, How to Analyze Time?
  • Time to execute a basic step varies from
    machine to machine
  • We cant use execution time
  • What can we use to tell how fast an algorithm is
    in terms that transcend individual machines

12
Basic Steps
  • Basic Step primitive operation or a set of
    operations that typically take same amount of
    time
  • assigning values, method calls, arithmetic,
    comparison, array index, following a
    pointer/reference, returning from method, etc.
  • We have some flexibility here
  • One person's basic step is another person's
    multiple steps
  • On a basic level, taking the not of a boolean is
    one step because it involves one bit, but adding
    two 32-bit numbers is 32 (or more!) steps
  • The important thing is Be consistent in what a
    step is

13
Counting Steps
14
  • The number of steps is a function of the input
    size (n)

15
Function of Input
  • Not only is number of steps dependant on size of
    input, but also the input itself.
  • Ex Search for an element in an array.
  • if element is at the front, then 1step
  • if element not present or at the end, then n
    steps
  • Same algorithm, same input size, different input
    yields different behaviors
  • We can talk about best case, worst case and
    average case running times.

click
16
Function of Input
  • Can compare two methods
  • f(n) 12n 22
  • g(n) n2 7

17
Linear vs. Quadriatic
  • g(n) is smaller than f(n) for small values of n
    (up to about n 14), but eventually g(n)
    overtakes f(n)
  • Comparing linear function to quadratic quadratic
    function will eventually overtake (dominate)
    linear function regardless of coefficients and
    constants
  • We dont care much about small values of n, were
    interested in what happens when n gets extremely
    large

18
f_alg1
19
f_alg2
20
Comparison
  • alg_1 takes k2 6k 19 steps. While alg_2
    takes 5k 13 steps
  • We are interested in long-term growth rate of the
    functions
  • we can ignore constants and lower order terms
  • alg_2 is said to have a linear growth rate
  • alg_1 is said to grow like k2

21
Common growth rates
22
(No Transcript)
23
Algorithm Analysis
  • For a given algorithm, the running time is a
    function of the input.
  • The growth rate of an algorithms run-time
    function is very important.
  • It doesnt matter what the constant coefficients
    are for a given function (i.e., linear vs.
    quadratic). There will always be a point where
    the function with the faster growth rate will
    dominate the function with the slower growth
    rate.
  • Since we are interested in the long-term growth
    rate of the functions we can ignore the constants
    and lower order terms
  • Were typically interested in worst case bounds.
Write a Comment
User Comments (0)
About PowerShow.com