算法分析
来源:互联网 发布:成都魔方软件 编辑:程序博客网 时间:2024/04/30 06:47
Insertion sort...A[1,2,...,n]
for j <- 2 to n
i <- j - 1
key <- A[j]
while i > 0 and key > A[i]
A[i+1] <-A[i]
i <- i - 1
A[i+1] <- key
Running time:
Depends on input(e.g. already sorted)
Depends on input size
parameterize things in the input, time = f(input), so the time is a function of input
We want the time upper bonds
guarentee to the user
Kinds of analysis:
Worst-case(usually)
T(n) = max time on any input of size n
Depends on computer
relative speed(on same machine)
absolute speed(on different machine)
Average-case(sometimes)
T(n) = expected time over all inputs of size n, need assumption of standard distribution
Best-case(bogus)
BIG IDEA - asymptotic analysis
Ignore machine-dependent constants
look at the growth of T(n) as n->infinity
Asymptotic notation
theta notation, drop low order terms and ignore leading constant
E.g. 3n3+9n2-50n+23 = θ(n3)
Insertion sort analysis
worst-case input: reverse sorted
T(n) = sum[j from 2 to n] ( θ(j) ) = θ(n2)
Merge sort analysis
Important subroutine: merge. T(n') = θ(n')
analysis recursion as tree. recurse for lg(n) times.
so total time consuming T(n) = θ(nlgn)
- 算法分析
- 算法分析
- 算法分析
- 算法分析
- 算法分析
- 算法分析
- 算法分析
- 算法分析
- 算法分析
- 算法分析
- 算法分析
- 算法分析
- 算法分析
- 算法分析
- 算法分析
- 算法分析
- 算法分析
- 算法分析
- c++ 中的explicit
- FLEX 程序设计基础
- Apache 使用localhost(127.0.01 )可以访问,但是使用本机IP(局域网)不能访问的解决办法
- Printf()函数简单实现
- 传入一个table,文件名,导出Excel的方法
- 算法分析
- 这半年比较忙,去UK3次,就为了交付项目并且协助测试。
- 调试程序,发现有内存泄漏
- A poll() example
- 如何选型AnyChat SDK/ RTX/华途bigant /V2 Flash/视高等一系类音视频产品
- linux字符界面和图形界面切换方法
- 扒网页~~~
- java 方法参数引用常见错误
- C专家编程 笔记