Lecture 5-6

[toc]

Lecture 5-6

P2.What is complexity analysis?

什么是算法復雜度

  • The complexity of an algorithm is the amount of resources it needs in order to execute.
    • Time complexity - Amount of time the algorithm needs
    • Space complexity - Amount of memory the algorithm needs

P4-5.Basic operations of an algorithm & What is a basic operation?

  • 不同算法的Basic operation是什么。排序中的遍歷過程、merge比較
  • A basic operation can be seen as an operation that is fundamental for the performance of a particular algorithm.
  • The performance of the algorithm is in principle proportional(成正比) to the number of basic operations.

不同算法的Basic operation是什么

  • In sorting algorithms: comparing two elements
  • Graph traversal: traversing an edge
  • For some algorithms a basic operation can be a whole loop, including all operations inside the loop

P7.Complexity as a function of the input - Examples

  • 常見算法的復雜度、最好的情況、最壞的情況、在什么情況下最好


    時間復雜度.png
  • 當已經排好序的情況下最好

P20.Average and Worst case analysis

  • 掌握最壞的情況、不用掌握平均的
  • The worst-case complexity W(n) of an algorithm is the maximum number of basic operations performed for any input of n.
  • The average-case complexity A(n) of an algorithm is the average number of basic operations performed by the algorithm, where each input I occurs with some probability p(I).

P23.Relative growth rate of functions

  • 給出一個表達式,可以用Big O的形式表達出來、去掉常數項和低次項還有系數

P29.Example: O(n^3),Ω(n^3), and Θ(n^3)

  • 上下界、O的上界、Ω的下界、Θ的確界
  • 各個界的概念無需記住


    各個界.jpg
  • 例子


    example.jpg
  • 考點
    給出一個表達式,可以用Big O的形式表達出來、去掉常數項和低次項還有系數

P36.P and NP

  • NP中N 的含義、NP是否等于P、一般是不等、說明原因。 證明一個問題是NP問題,寫出步驟。P與NP的關系(目前認為兩者不等,如果P與NP相等會怎么樣,那么所有的問題都是可解的)
  • P is the class of problems that can be solved by plynomial bound algorithms.
  • NP(non-deterministic polynomial-time) is more complicated to describe.

    ? It contains problems that we believe are more difficult to solve

    than those in P.

    ? We believe that they cannot be solved using any polynomial

    bound algorithm.

    ? However, we do not know whether this is true or not.

證明一個問題是NP問題,寫出步驟。

P44. NP-complete

什么是NP-complete

  • 所有的P問題都可以歸約到它。All problems in NP can be reduced to it.

如何證明一個問題(P2)是NP-complete

  1. So P2 is a NP problem.
  2. P1 is a NP complete, all other problems R in NP can be polynomially reduced to P1.
  3. Show P1 can be polynomially reduced to P2

P46.How to show that a problem is N P complete I

  • 過于具體、可以簡化

P47.How to show that a problem is N P complete II

  • 具體證明步驟、會證明
  • 把第二條分成兩點

P48.Amortized analysis - Initial example

  • 只需要掌握基本概念、 a sequence of operations是關鍵詞
  • Amortized analysis is a technique for analyzing the running time of repeated operations on a data structure.
  • The cost for a single insert might be much worse than the amortized analysis. 單次的操作開銷可能會比均攤分析的時間復雜度高,因為均攤分析計算的是平均的時間復雜度

  • It is used when one is interested in calculating a worst-case average bound per operation for any sequence of operations

  • It does not say anything about the cost of a specific operation in the sequence.

  • It is particular useful in situations where there are few expensive (slow) operations that are compensated by many inexpensive (fast)operations.

P52.Amortized or worst-case analysis

  • In applications where it is important that all operations have a low cost, it might be more appropriate to use a worst-case analysis than an amortized analysis.

P53.Amortized vs average-case analysis

  • 兩者并不一樣、AC是發生的概率,并不考慮多個步驟再平均
  • Amortized analysis provides an upper bound on the average cost per operation whereas average-case analysis provides an average cost per iteration, where consideration is taken to the probability of the occurrence of dierent inputs.

  • Amortized analysis provides an upper bound on the running time of a sequence of operations. Average-case analysis provides no such bound.

  • Amortized analysis needs no information about the probability on inputs.

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • 學校社團招新的時候,桑落選了個剛成立的社團——手繪社,因個人愛好。社團人不多,她填了表格就算完事,成了社團一員。這...
    風墨瀾閱讀 197評論 0 0
  • 人工智能相關研究報告 (20萬字) 看了多篇各有側重的研報或者出版物,其中一半做了精讀,一半泛讀;偏技術的仍然啃得...
    凜二凡閱讀 419評論 1 0
  • 將本賬期、本通道里面的支付全部設置為短款、撤銷/退款記錄為長款 找出本賬期所有的對賬文件 打開每一個文件, 遍歷每...
    賈旭007閱讀 374評論 0 0
  • 《悲慘世界》里有很多關系:親情、友情、敵對、愛情等等。讓我為之心情波動起伏的是其中的愛情。 芳玎被老混蛋騙,我感覺...
    钅犭豸閱讀 623評論 0 1