Lecture 1 Analysis of Algorithms

本文探讨了计算机程序性能和资源使用的理论研究,强调了正确性、简单性和可维护性等概念的重要性,并通过插入排序算法示例介绍了算法分析的基本原理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Analysis of Algorithms

The theoretical study of computer program performance and resource usage.

Performance: time

Resource: communication, RAM memory or disk memory and so on.

 

What's more important than performance?

Correctness, Simplicity, Maintainability, Robustness, Features, Functionality, Modularity, Security, User-friendliness.

 

Why study algorithm and performance?

They are the fundamental thing for above.


Problem: sorting

Input: sequence <a1, a2, ..., an> of numbers

Output: permutation <a1’, a2’, ..., an’>, s.t. a1’ <= a2’ <= ... <= an’

 

Insertion Sort:

Insertion-Sort(A,n) //Sorts 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:

-Depends on input (eg. Already sorted)

-Depends on input size (6 elem. VS 6*10**9)

    -parameterize in input size

-Want upper bounds

    -guarantee to the user


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 statistic of distribution: uniform distribution)

Best-case (bogus) cheat


What is insertion sort's worst-case time?

Depends on computer

-relative speed (on same machine)

-absolute speed (on different machine)

 

BIG IDEA!  Asymptotic analysis

1. Ignore machine dependent constants;

2. Look at growth of T(n) as n -> infinity.





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值