1. 程式人生 > >Introduction to Algorithms演算法導論筆記-Lecture1

Introduction to Algorithms演算法導論筆記-Lecture1

Introduction to Algorithms演算法導論筆記

演算法導論Lesson1

課程簡介:

內容主要包括

  • 演算法的含義、意義的簡要介紹;
  • 演算法的分析;
  • 插入排序、合併排序
  • 如下圖:
    如下圖:

這裡寫圖片描述
preface
Analysis of Algorithms
The theoretical study of computer program
performance and resource usage

What’s more important than perf?
cost, ux
Why study algs and perf?
infeasable ->feasable
perf like the currency in economy
Perf is the precondition to have good ux.
bottom of heap
Speed is always fun.

Problem Sorting
input sequence [a1,a2,…,an] of numbers
output permutation[a1’,a2’,…,an’] to sorted as smaller->bigger

Insertion Sort
這裡寫圖片描述
Running time:
- depends on input(e.g. sorted already)
- depends on input size( 6 elem. vs 6*10**9)

Kinds of analysis

  • Worst-case(usually)

    T(n) =max time on any input of size n

  • Average-case:(sometimes)

    T(n)=expected time over all inputs of size n
    (Need assumption of stat. distr.)

  • Best-case:(bogus)
    cheat

What’s my sort’s worst time?
Depends on computer

  • relative speed(on same machine)
  • absolute speed(on different machines)
    BIG DATA
    漸進分析
    look at the growth of time when n->infinity
    Asymptotic notation:

    O(n**3) Drop low-order such as n**2,n,constant and leading constant.

    arithmetic series(算術級數,等差級數)
    教授居然說,我們這裡有高手知道算數級數,溝通就好辦了。
    Merge Sort

    這裡寫圖片描述

    1. If n=1, done
    2. Recursively sort
      a[1,…n/2] and
      a[n/2+1,…n]
    3. Merge 2 sorted lists.
      Key Subroutine: Merge
      20 12
      13 11
      7 9
      2 1
      1 2 7 9 11 13 12 20

小結:
兩種排序演算法
對於排序問題,本節課提供了兩種演算法,分別是插入排序和合並排序。

插入排序是O(n*n),合併排序是O(nlgn)

其中合併排序運用了遞迴呼叫和分治策略,這兩個內容將分別在後續兩節中介紹。