Analysis of algorithms -- Preface

Source: Internet
Author: User

Analysis of algorithms:

  • First part of the course is focused on analysis.
  • Second part of the course is focused on design.

The Analysis of algorithm is the theoretical study. (algorithm analysis is a theoretical study)

The Theoretical Study of Computer-program performance and resource usage. (theoretical research is about computer performance and resource utilization)

In programming, what is more important than performance?

  • Correctness
  • Simplicity
  • Maintainability
  • Cost
  • Stability
  • Functionablity
  • Fearures
  • Modularity
  • Security
  • Scalability
  • User-friendly

Why do we bother and why study algorithms and performance?

  • Algorithms is the feasible versus infeasible.
  • Algorithms give you a Lauguage of talking about program behavior.
  • We study algorithms performance is it's tons of fun.

The problem of sorting (Sorting Problem)

  • Input: sequence <A1, A2, a3... an>
  • Output: permutation <A1, a2... an>

Such that: A1 <A2 <... <

Insertion-sort:

for (int i = 1; i < a.length; i++) {            key=a[i];            int j=i-1;            while (j>=0&&a[j]>key) {                a[j+1]=a[j];                a[j]=key;                j--;            }                        for (int k = 0; k < a.length; k++) {                System.out.print(a[k]+" ");            }            System.out.println();                    }
}

Running time:

One thing it depends on is the input itself.

  • Depends on Input Self (eg: already sorted)
  • Depends on input size (eg: 6 elements vs 6*109)

-- Parameterize things in the input size.

  • Want upper bounds. guarantee to the user

Kinds of analysis:

  • Worst-case analysis (usually): T (n) = max time on any input of size N.
  • Average case analysis (sometimes): T (n) = expected time over all inputs of size N.
  • Best-case analysis (bogus: Hypothetical) No Good.

What is insertion sorts worst-case time?

Depends n computer.

  • Relative Speed (on same machine)
  • Absolute speed (on defferent machine)

Big idea of algorithms:

On same machine analysis algorithms performance Use Asymptotic Analysis (progressive Analysis)

Asymptotic Analysis:

  • Ignore machine-dependent Constants
  • Look at the growth of the running time, look at growth of T (n) as N-> ∞

Asymptotic notation (progressive Notation)

Upload-notation:

  • Drop low order terms (discard its lower class)
  • Ignore leading constants (ignore the previous constant factor)
  • Ex: 3n3 + 90n2-5n + 6046 = accept (N3)

Insertion-Sort worst-case sorted: T (n) = Sigma round (j) = round (N2)

Is insertion sort fast?

It's turns out for small n It is moderately fast; but it is not at all for large N.

 

Analysis of algorithms -- Preface

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.