跳到主要內容

簡易檢索 / 詳目顯示

研究生: 何東穎
Dong-Ying He
論文名稱: 以演算法程式設計競賽試題為例使用Big-O AST靜態分析函式時間複雜度
Static Analysis of Time Complexity with Big-O AST: A Case Study of Algorithmic Competitive Programming Problems
指導教授: 莊永裕
Yung-Yu Zhuang
口試委員:
學位類別: 碩士
Master
系所名稱: 資訊電機學院 - 軟體工程研究所
Graduate Institute of Software Engineering
論文出版年: 2019
畢業學年度: 107
語文別: 中文
論文頁數: 54
中文關鍵詞: 靜態分析抽象語法樹大O符號時間複雜度演算法
外文關鍵詞: Static Analysis, Abstract Syntax Tree, Big-O, Time Complexity, Algorithm
相關次數: 點閱:14下載:0
分享至:
查詢本校圖書館目錄 查詢臺灣博碩士論文知識加值系統 勘誤回報
  • 評估一演算法效率的好壞最常見方式是分析其演算法的時間複雜度。一般而言,時間複雜度的分析最常使用Big-O作為評估的標準。且時間複雜度的分析並非是一個簡單的問題,目前有許多研究探討使用靜態分析或動態分析的方式分析時間複雜度,本研究介紹了各個研究應用在程式設計競賽中的不足之處,並說明如何利用Big-O AST達到與程式語言無關,靜態分析函式時間複雜度的方法。
    本研究提出從AST分析結構化程式設計中循序結構、重覆結構、選擇結構的時間複雜度的方法,並且考慮了函式呼叫的時間複雜度計算與遞迴的偵測。我們使用Python實作本研究,將工具命名為BigO-Calc。
    本研究使用挑戰程序設計競賽書中演算法問題的五個演算法實作與本論文For迴圈$O(log(M))$的範例分析函式的時間複雜度。在六個範例共九個函式的時間複雜度分析上,BigO-Calc能夠正確的分析三個範例共五個函式的時間複雜度。


    The most common way to evaluate an algorithm is analyze the time complexity of target algorithm. In general, analyzing the time complexity of an algorithm is using big O notation. Time complexity analysis is not an easy question, there are many study of how to analyze time complexity by static analysis or dynamic analysis. We point out the weak point of others methodology applied to programming contest. In this paper, we present how to statically analyze function time complexity and how to do language independent analysis by Big-O AST.
    In this paper, we present how to analyze the time complexity of this three architecture: sequence architecture, repetition architecture, selection architecture which are introduced by "structured programming". We also calculate function call's time complexity and show how to detect recursion. We had implemented this tool by Python, and named BigO-Calc.
    To evaluate BigO-Calc we analyze five algorithm questions which contain eight functions from book "挑戰程序設計", and one for loop example which the time complexity is $O(log(M))$. The result of evaluation is Big-O Calc can analyze five functions from three algorithm questions.

    一、緒論1 1.1 演算法程式設計競賽................................................... 1 1.2 多數演算法程式設計競賽採用動態分析分析時間複雜度...... 2 1.3 時間複雜度與Big-O.................................................... 2 1.4 程式碼分析............................................................... 3 1.5 目前針對時間複雜度分析的方法在演算法程式設計競賽中 的適切性......................................................................... 4 1.5.1 從測試資料集變化分析....................................... 5 1.5.2 從中介碼、機械碼分析....................................... 5 1.5.3 從控制流程圖分析............................................. 6 1.5.4 從抽象語法樹進行靜態分析................................. 7 二、動機8 2.1 以演算法程式設計競賽試題為例.................................... 8 2.2 本研究開發一靜態分析工具.......................................... 12 2.3 相關研究應用於演算法程式設計競賽.............................. 13 2.3.1 Complexity....................................................... 14 2.3.2 Automated Big-O Analysis of Algorithms ................ 15 2.3.3 CAMPY .......................................................... 16 2.3.4 ALGator.......................................................... 16 2.3.5 Asymptus ........................................................ 17 三、使用Big-O AST 靜態分析函式時間複雜度18 3.1 Big-O AST................................................................ 18 3.2 時間複雜度計算......................................................... 19 3.2.1 循序結構複雜度分析.......................................... 19 3.2.2 選擇結構複雜度分析.......................................... 20 3.2.3 重覆結構複雜度分析.......................................... 21 3.2.4 函式呼叫分析................................................... 24 四、實作26 4.1 抽象語法樹生成階段................................................... 28 4.2 抽象語法樹轉換階段................................................... 29 4.3 時間複雜度計算階段................................................... 30 4.4 時間複雜度化簡階段................................................... 31 五、評估33 5.1 評估函式時間複雜度分析的正確性................................. 33 5.2 分析與解釋............................................................... 34 5.3 評估總結.................................................................. 35 六、相關研究36 6.1 A Novel Method to Find Time Complexity of an Algorithm by Using Control Flow Graph............................................... 36 6.2 An Abstract to Calculate Big O Factors of Time and Space Complexity of Machine Code................................................ 37 七、未來展望38 八、結論39 參考文獻40

    [1] 何東穎、莊永裕, “使用AST 進行靜態程式碼分析函式時間複雜度,” TANET 2018,
    pp. 1–6, 2018 臺灣網際網路研討會, 2018.
    [2] “icpc 官方網站.” https://icpc.baylor.edu/.
    [3] J. Hartmanis and R. E. Stearns, “On the computational complexity of algorithms,”
    Transactions of the American Mathematical Society, vol. 117, pp. 285–306, 1965.
    [4] D. E. Knuth, The Art of Computer Programming, Volume 3: (2Nd Ed.) Sorting and
    Searching. Redwood City, CA, USA: Addison Wesley Longman Publishing Co., Inc.,
    1998.
    [5] S. C. Johnson, “Lint, a c program checker,” in COMP. SCI. TECH. REP, pp. 78–
    1273, 1978.
    [6] S. L. Graham, P. B. Kessler, and M. K. Mckusick, “Gprof: A call graph execution
    profiler,” in Proceedings of the 1982 SIGPLAN Symposium on Compiler Construction,
    SIGPLAN ’82, (New York, NY, USA), pp. 120–126, ACM, 1982.
    [7] R. Vaz, V. Shah, A. Sawhney, and R. Deolekar, “Automated big-o analysis of algorithms,”
    in 2017 International Conference on Nascent Technologies in Engineering
    (ICNTE), pp. 1–6, Jan 2017.
    [8] M. Rav, “Complexity.” https://github.com/Mortal/complexity.
    [9] T. Dobravec, “Estimating the time complexity of the algorithms by counting the
    java bytecode instructions,” in 2017 IEEE 14th International Scientific Conference
    on Informatics, pp. 74–79, Nov 2017.
    [10] A. Srikanth, B. Sahin, and W. R. Harris, “Complexity verification using guided
    theorem enumeration,” in Proceedings of the 44th ACM SIGPLAN Symposium on
    Principles of Programming Languages, POPL 2017, (New York, NY, USA), pp. 639–
    652, ACM, 2017.
    [11] F. Demontiê, J. Cezar, M. Bigonha, F. Campos, and F. Magno Quintão Pereira,
    “Automatic inference of loop complexity through polynomial interpolation,” in Proceedings
    of the 19th Brazilian Symposium on Programming Languages - Volume 9325,
    (New York, NY, USA), pp. 1–15, Springer-Verlag New York, Inc., 2015.
    [12] S. Gayathri Devi, K. Selvam, and S. P. Rajagopalan, “An abstract to calculate big o
    factors of time and space complexity of machine code,” in International Conference
    on Sustainable Energy and Intelligent Systems (SEISCON 2011), pp. 844–847, July
    2011.
    [13] K. S. Kumar and D. Malathi, “A novel method to find time complexity of an algorithm
    by using control flow graph,” in 2017 International Conference on Technical
    Advancements in Computers and Communications (ICTACC), pp. 66–68, April 2017.
    [14] 秋葉拓哉, 岩田陽一, 北川宜稔, et al., 挑戰程序設計競賽(第2 版). 人民郵電出
    版社, 第2 版ed. 巫澤俊, 莊俊元, 李津羽.
    [15] “Bigo-calc.” https://github.com/ncu-psl/BigO-Calc.
    [16] “Soot framework.” http://sable.github.io/soot/.
    [17] “Z3 theorem prover.” https://github.com/Z3Prover/z3.
    [18] E. W. Dijkstra, “Structured programming,” ch. Chapter I: Notes on Structured Programming,
    pp. 1–82, London, UK, UK: Academic Press Ltd., 1972.
    [19] “Java 版本實作.” https://github.com/ncu-psl/BigO-Calc/tree/origin-javacalc,
    2018. 已停止維護.
    [20] T. Parr, The Definitive ANTLR 4 Reference. Pragmatic Bookshelf, 2nd ed., 2013.
    [21] E. Bendersky, “pycparser.” https://github.com/eliben/pycparser.
    [22] C. Thunes, “javalang.” https://github.com/c2nes/javalang.
    [23] A. S. Novikov, A. N. Ivutin, A. G. Troshina, and S. N. Vasiliev, “The approach to
    finding errors in program code based on static analysis methodology,” in 2017 6th
    Mediterranean Conference on Embedded Computing (MECO), pp. 1–4, June 2017.
    [24] “Sympy 官方網站.” https://www.sympy.org/en/index.html.
    [25] “Domjudge 官方網站.” https://www.domjudge.org/.
    [26] “青島大學線上評判系統(qduoj).” https://qduoj.com/.

    QR CODE
    :::