【正文】
。 ?時間效率主要用它的輸入規(guī)模的函數(shù)來度量,該函數(shù)計算算法基本操作的執(zhí)行次數(shù)。 Engineering 27 動態(tài)算法可視法 Analysis and Design of Computer Algorithms Yunnan University School of Information Science amp。 Engineering 25 靜態(tài)算法可視法 Analysis and Design of Computer Algorithms Yunnan University School of Information Science amp。 Engineering 24 算法可視法 ?通過使用圖形來傳達(dá)關(guān)于算法的一些有用信息。 Engineering 22 算法的經(jīng)驗分析 ?對算法效率做經(jīng)驗分析的通用方案 ?了解試驗的目的 ?決定用來度量效率的量度 M和度量單位(單位時間內(nèi)的操作次數(shù)) ?決定輸入樣本的特性 ?為實驗準(zhǔn)備算法的程序?qū)崿F(xiàn) ?生成輸入樣本 ?對輸入樣本進行計算,并記錄觀察到的實驗數(shù)據(jù) ?分析獲得的實驗數(shù)據(jù) Analysis and Design of Computer Algorithms Yunnan University School of Information Science amp。 Analysis and Design of Computer Algorithms Yunnan University School of Information Science amp。 Engineering 19 分析遞歸算法效率的通用方案 ?決定用哪個參數(shù)作為輸入規(guī)模的度量 ?找出算法的基本操作 ?檢查對相同規(guī)模的輸入,基本操作的執(zhí)行次數(shù)是否相同,如果不同,必須對最差、平均及最優(yōu)效率單獨研究 ?建立一個遞推關(guān)系式及相應(yīng)的初始條件 ?求解這個遞歸關(guān)系式,或者至少確定解的增長次數(shù) Analysis and Design of Computer Algorithms Yunnan University School of Information Science amp。 Engineering 18 遞歸算法的數(shù)學(xué)分析 ?例:對于任意非負(fù)整數(shù) n,計算 F(n)=n!的值。 Analysis and Design of Computer Algorithms Yunnan University School of Information Science amp。 4. 建立一個算法基本操作執(zhí)行次數(shù)的求和表達(dá)式。 2. 找出算法的基本操作。 算法 MaxElement(A[0..n1] //求給定數(shù)組中的最大元素 //輸入:實數(shù)數(shù)組 A[0..n1] //輸出: A中的最大元素 maxval ?A[0] for i ? 1 to n1 do if A[i] maxval maxval ? A[i] return maxval 考慮: 1. 循環(huán)中的操作有 比較 和 賦值 ,取哪一個作為基本操作? 2. 輸入規(guī)模是多少? 基本操作為:比較運算