The theoretical study of computer program performance and resource useage.
 
First, analysis and then design.
 
Questions:
1 In programming, what is more important than performance(有什么比性能更重要)?
correctness, simplicity(简洁性), maintainability, stability, modularity(模块化,避免修改功能以外的代码), efficiency, programmer's time, security, 
scalability(可扩展性),  Functionality(特性多), user friendliness (用户友好)
2 why study algorithms and performance?(那为什么还要学习算法?)
user friendliness(提高性能也会用户友好) ,feasible versus infeasible(内存占用多或速度慢会导致不可行), you can use algorithms to pay for these other things that you want(like user friendilness, security, ).
like communication and memory and so forth,同performance一样需要节约.. for fun.
 
Problem :Sorting(排序问题)
Insertion Sort: move the key and copy to a position to compare if it is corrent
 
Running time:(运行时间)
Depends on input(e.g. already sorted)
Depends on input size(6 elem. vs 6 * 10^9 elem.) -- parametionze in input size
want upper bounds(想知道它运行时间的上限) -- guarantee to user
 
Kinds of anaylysis:(如何分析)
Worst-case(usually): T(n) = max time on any imput of size n
Average-case (sometimes) T(n) = expected time over all inputs of size n(每种输入的概率*时间,求和平均
 -- statistical distribution of inputs(Need assumption of statistic distribution, like normal distr.)
Best-case: (bogus 假象) just for cheat,为特定输入给出特定输出,not for all cases。
 
What is ins-sort's w-c time?
    Depends on computer
        -- relative speed (on same machine) 在相同机器上比较相对速度
        -- absolute sppeed (on diff machine) 真的会有某个算法不关在什么计算机上运行都最快吗?这会很困惑
 
BIG IDEA:
Asymtotic analysis: 渐近分析
1 Ignore machine dependent constants(忽略与机器相关的常量)
2 look at growth of T(n) as n - > infinity
 
Asymptotic notation(渐近符号)
theta-notation: drop lowner order terms Ignore leading constants
    Ex: 3n^3 + 90n^2 -5n -6046 = theta(n^3)
As n-> infinity , theta(n^2) alg. always beats a theta(n^3) alg.(即使在不同的机器上,极其差别也只是constants diff)
会由一个点开始,theta(n^2)与theta(n^3)消耗相同或更少
 
Insertion Sort:(插入排序)
 
T(n) = 求和(j = 2-> n):theta(j) = theta(n^2)(arithmetic serias算数级数)
 
Is insertion sort fast?
    -- moderately so, for small n(对于很小的n,适度的快)
    -- not at all for largen
 
Merge Sort:(归并排序)
 
 
    1 If n == 1,  done                                                     (theta(1))
    2 Recursively sort: A[1... n/2] and A[(n/2+1) ... n]    (2T(n/2))
    3 Merge two sorted list                                            (theta(n))
 
Key subroutine is Merge:(子集合并)
两个子列,20 13 7 2, 12 11 9 1, 两个列中的最小值比较,拿走1,在比较两个列中的最小值,拿走2,当某一个子列空了,另一个子列整个拿走。操作数是固定的,因此:
Time = theta(n) on n total elems. 在下面即为c*n
 
T(n) = theta(1), if n = 1 (usually omit)
T(n) = 2T(n/2) + theta(n) if n > 1
 
Recrusion tree:(递归树)
         T(n) = 2T(n/2) +c*n (c is a contant) 可以写成树状:(高度是lgn, 叶子数为n)
                                =  2(2T(n/4) + c*n/2)) + c*n
                                = ... 
                                = lgn个c*n以及叶子上的n个theta(1),即为theta(n))
                                = c*n*lgn+ theta(n)
                                = theta(n*lgn)(去掉低阶项)
 
Result: theta(n*lgn) is faster then theta(n^2) when the element size is larger than a number.

[MIT Intro. to algo]Lecture 1: 课程介绍,算法优势,插入算法和归并算法分析,渐近符号的更多相关文章

  1. [学习笔记] CS131 Computer Vision: Foundations and Applications:Lecture 1 课程介绍

    课程大纲:http://vision.stanford.edu/teaching/cs131_fall1718/syllabus.html 课程定位: 课程交叉: what is (computer) ...

  2. MIT 6.828 课程介绍

    MIT 6.828 课程介绍 本文是对MIT 6.828操作系统课程介绍的简单摘录,详细介绍见6.828: Learning by doing以及朱佳顺的推荐一门课:6.828.学习资源均可以在课程主 ...

  3. 优雅智慧女性课程班 - 公开课程 - 课程介绍 - 中国人民大学商学院EDP中心

    优雅智慧女性课程班 - 公开课程 - 课程介绍 - 中国人民大学商学院EDP中心 优雅智慧女性课程班 课程总览 思想睿智成熟,外表美丽自信,气质优雅端庄,是魅力女性所应具备的特性.在当今不确定环境下, ...

  4. Vue+koa2开发一款全栈小程序(1.课程介绍+2.ES6入门)

    1.课程介绍 1.课程概述 1.做什么? Vue+koa2开发一款全栈小程序 2.哪些功能? 个人中心.图书列表.图书详情.图书评论.个人评论列表 3.技术栈 小程序.Vue.js.koa2.koa- ...

  5. 爬虫--Scrapy框架课程介绍

    Scrapy框架课程介绍: 框架的简介和基础使用 持久化存储 代理和cookie 日志等级和请求传参 CrawlSpider 基于redis的分布式爬虫 一scrapy框架的简介和基础使用 a)    ...

  6. web安全之SQL注入--第一章 课程介绍

    课程介绍1.什么是SQL注入?2.如何寻找SQL注入漏洞?3.如何进行sql注入攻击?4.如何预防sql注入5.课程总结

  7. python入门课程 第一章 课程介绍

    1-1 Python入门课程介绍特点:    优雅.明确.简单适合领域:    web网站和各种网络服务    系统工具和脚本    作为"胶水"语言把其他语言开发的模块包装起来方 ...

  8. 01.课程介绍 & 02.最小可行化产品MVP

    01.课程介绍 02.最小可行化产品MVP 产品开发过程 最小化和可用之间找到一个平衡点

  9. JS--- part6课程介绍 & part5复习

    part6 课程介绍 scroll系列:-----重点,每个属性是什么意思 封装scroll系列的相关的属性,固定导航栏案例---事件浏览器的滚动条事件--能够写出来 封装动画函数---缓动动画--- ...

随机推荐

  1. CORS (Cross Origin Resources Share) 跨域

    CORS 跨域 1 什么是跨域问题 基于安全考虑,浏览器会限制使用脚本发起任何跨域请求. 所谓的跨域请求,就是与当前页面的 http/ip/port 不一样的请求. 但在实际运用中,跨域获取数据的需求 ...

  2. 2、基于wsgiref模块DIY一个web框架

    一 web框架 Web框架(Web framework)是一种开发框架,用来支持动态网站.网络应用和网络服务的开发.这大多数的web框架提供了一套开发和部署网站的方式,也为web行为提供了一套通用的方 ...

  3. JavaScript的DOM操作获取元素的大小

    通过 style 内联获取元素的大小 需要注意的是style 获取只能获取到行内 style 属性的 CSS 样式中的宽和高,如果有获取:如果没有则返回空. <!DOCTYPE html> ...

  4. poj 2289 Jamie's Contact Groups【二分+最大流】【二分图多重匹配问题】

    题目链接:http://poj.org/problem?id=2289 Jamie's Contact Groups Time Limit: 7000MS   Memory Limit: 65536K ...

  5. loj6119 「2017 山东二轮集训 Day7」国王

    题目描述 在某个神奇的大陆上,有一个国家,这片大陆的所有城市间的道路网可以看做是一棵树,每个城市要么是工业城市,要么是农业城市,这个国家的人认为一条路径是 exciting 的,当且仅当这条路径上的工 ...

  6. Payment:微信支付配置文件设置说明

    项目GitHub地址:https://github.com/helei112g/payment 微信支付个人觉得在帐号设置上有些麻烦,帐号太多啦,支付宝目前就是一个应用基本涵盖了所有的接口开发. 可能 ...

  7. javascript中对数组对象的深度拷贝

    在前端开发的某些逻辑中,经常需要对现有的js对象创建副本,避免污染原始数据的情况. 如果是简单的一维数组对象,可以使用两个原生方法: 1.splice var arr1 = ['a', 'b', 'c ...

  8. 【bzoj 4675】 点对游戏

    题目 发现一个人如果最终拿走了\(k\)个点,那么这个人的答案就是 \[\frac{\binom{n-2}{k-2}\sum_{i=1}^{n}\sum_{j=1}^{n}[dis(i,j)\in M ...

  9. Day2 CSS

    什么是CSS 层叠样式表(cascading style sheet) 控制页面元素的显示方式.(添加样式) CSS语法 行间样式 行内式是在标记的style属性中设定CSS样式.这种方式没有体现出C ...

  10. virtualbox+vagrant学习-4-Vagrantfile-1-简介

    Vagrantfile Vagrantfile的主要功能是描述项目所需的机器类型,以及如何配置和提供这些机器.之所以称为Vagrantfiles,是因为文件的实际文本文件名是Vagrantfile(除 ...