算法导论--初级1

算法分析是关于计算机程序性能(performance)与资源利用(communicationmemory)的理论研究。Correctness, simplicity, maintainability, costtime, robustnessfeature, security, user-friendliness et al. may important than performance. performance会决定算法的feasible or infeasible,是算法实现的基础。performance应用于尚未成熟领域。


sorting problem:input sequence<a1,a2,……an>, output is permutation(rearrangement) of those numbers<b1,b2,……bn>, where b1<=b2<=……<=bn。

插入排序Insertion sort: sorting A[1..n]

for j <- 2 to n

    do    key <- A[j]

            i <- j-1

    while i > 0 and A[i] > key

        do   A[i+1] <- A[i]

               i <- i-1

    A[i+1]<-key

running time:input data itself(sorted), input data size(parametrize in input size), upper bounds(guarantee to user)


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(make an assumption of the statical distribution of the inputs -> expected time, uniform distribution)

Best-case(bogus假象): 


for insertion sort:Asymptotic analysis 渐近分析(ignore machine-dependant constants, look the growth of actual running time)

Worst-case: (in reverse order)T(n)=n^2,适合小数据,不适合大数据



并归排序Merge sort: sorting 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

Key subroutine: Merge, Time = n。

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

~Recursion tree. -----T(n) = nlog n

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值