【听课笔记】算法导论1

课程地址

http://v.163.com/special/opencourse/algorithms.html

今天课程地址:

http://open.163.com/movie/2010/12/G/F/M6UTT5U0I_M6V2T1JGF.html

讨论performance

Analysis of Algorithms: the study of computer program performance ans resource usage.

Thinking: What is more important than performance?

Functionality, modularity, user-friendliness, security...

Then why study algs and perf?

performance is like the "money", you can buy other stuff...这个有点不懂,讨论一下

 

Problem sorting

Insertion sort

每次保证在第i位置之前的都是sort好的

8 2 4 9 3 6  i = 1

2 8 4 9 3 6  i = 2

2 4 8 9 3 6  i = 3

2 4 8 9 3 6  i = 4

2 3 4 8 9 6  i = 5

2 3 4 6 8 9  done

Running time analysis

  • Depends on input (best case, wrost case)
  • Depends on input size

wrost case, ave case, best case

BIG IDEA: Asymptotc analysis 渐进分析

  • Ignore machine dependent
  • Look at the growth

Θ notation, 比的是n在无限大时的情况~所以n^2肯定比n^3快哒。

Wrost case:

Θ(n^2)

 

Merge sort A[1,..., n]

1, if n =1, done

2, recursively sort A[1,..., n/2] and A[n/2 + 1, ..., n]

3, merge 2 sorted lists

T(n) = 2T(n/2) + Θ(n) if n > 1

T(n) = cn*lgn + Θ(n) = Θ(nlgn)   c代表常数

 

你可能感兴趣的:(算法导论)