• Analysis of Algorithms--preface


    Analysis of Algorithms:

    • First part of the course is focused on analysis.
    • Second part of the course is focused on design.

    The analysis of algorithm is the theoretical study.(算法分析是理论研究)

    The theoretical study of computer-program performance and resource usage.(理论研究是关于计算机性能和资源利用的研究)

    In programming, what is more important than performance?

    • correctness
    • simplicity
    • maintainability
    • cost
    • stability
    • functionablity
    • fearures
    • modularity
    • security
    • scalability
    • user-friendly

    Why do we bother and why study algorithms and performance?

    • Algorithms is the feasible versus infeasible.
    • Algorithms give you a lauguage of talking about program behavior.
    • We study algorithms performance is it's tons of fun.

    The problem of sorting(排序问题)

    • input:sequence<a1,a2,a3...an>
    • output:permutation<A1,A2...An>

    Such that:A1<A2<...<An

    Insertion-Sort:

    for (int i = 1; i < a.length; i++) {
                key=a[i];
                int j=i-1;
                while (j>=0&&a[j]>key) {
                    a[j+1]=a[j];
                    a[j]=key;
                    j--;
                }
                
                for (int k = 0; k < a.length; k++) {
                    System.out.print(a[k]+" ");
                }
                System.out.println();
                
            }
    }

    running time:

      one thing it depends on is the input itself.

    • Depends on input self(eg:already sorted)
    • Depends on input size(eg:6 elements vs 6*109)

      --parameterize things in the input size.

    • want upper bounds.guarantee to the user

    Kinds of analysis:

    • 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.
    • best-case analysis(bogus:假象)No good.

    What is insertion sorts worst-case time?

      Depends n computer.

    • relative speed (on same machine) 
    • absolute speed (on defferent machine)

    BIG Idea of algorithms:

    on same machine analysis algorithms performance use asymptotic analysis(渐进分析)

    asymptotic analysis:

    • ignore machine-dependent constants
    • look at the growth of the running time,look at growth of T(n) as n->∞

    asymptotic notation(渐进符号Θ)

    Θ-notation:

    • drop low order terms(弃去它的低阶级)
    • ignore leading constants(忽略前面的常量因子)
    • EX:3n3+90n2-5n+6046=Θ(n3)

    Insertion-Sort worst-case sorted:T(n)=∑Θ(j)=Θ(n2)

    Is insertion sort fast?

    It's turns out for small n it is moderately fast;but it is not at all for large n.

  • 相关阅读:
    怎么判断自己在不在一家好公司?
    超全!互联网大厂的薪资和职级一览
    Nginx 又一牛 X 功能!流量拷贝
    时间管理之四象限法则
    罗永浩一个坑位卖60万脏钱背后:放下面子赚钱,才是成年人最大的体面
    2020 年 4月全国程序员工资出炉
    一次 SQL 查询优化原理分析(900W+ 数据,从 17s 到 300ms)
    “Hey Siri” 背后的黑科技大揭秘!
    一文讲透高薪的本质!
    python UnicodeDecodeError: 'gbk' codec can't decode byte 0x99 in position 87: illegal multibyte sequence异常解决
  • 原文地址:https://www.cnblogs.com/chuji1988/p/4008070.html
Copyright © 2020-2023  润新知