# 循環複雜度

「循環複雜度」的名稱有時會讓人誤解，因為此複雜度不只計算程式中的迴圈（循環）個數。循環複雜度是指程式的控制流圖中，若將結束點到啟始點再增加一個邊時，控制流圖中的圈（幾個邊形成封閉路徑）的個數[2]

M = EN + 2P

E 為圖中邊的個數
N 為圖中節點的個數
P 為圖中連通分量的個數

M = EN + P

π - s + 2

π是程式中決策點的個數
s為結束點的個數[3][4]

## 註解

1. ^ 此處的結構化特別強調一個函式只有單一的結束點

## 參考資料

1. ^ A J Sojev. Basis Path Testing. [2012-09-30]. （原始内容存档于2012-04-26）.
2. McCabe. A Complexity Measure (PDF). IEEE Transactions on Software Engineering. December 1976: 308–320 [2012-10-01]. （原始内容 (PDF)存档于2022-05-30）.
3. Belzer, Kent, Holzman and Williams. Encyclopedia of Computer Science and Technology. CRC Press. 1992: 367–368.
4. ^ Harrison. Applying Mccabe's complexity measure to multiple-exit programs. Software: Practice and Experience (J Wiley & Sons). October 1984.
5. ^ McCabe, Watson. Structured Testing: A Testing Methodology Using the Cyclomatic Complexity Metric. 1996. （原始内容存档于2012-08-28）.
6. ^ Stein; Cox, Glenn; Etzkorn, Letha; et al. Exploring the relationship between cohesion and complexity. Journal of Computer Science. 2005, 1 (2): 137–144 [2012-10-02]. doi:10.3844/jcssp.2005.137.144. （原始内容存档于2019-12-02）.
7. ^ Kan. Metrics and Models in Software Quality Engineering. Addison-Wesley. 2003: 316–317. ISBN 0-201-72915-6.
8. ^ Les Hatton. The role of empiricism in improving the reliability of future software. 2008. version 1.1. （原始内容存档于2012-11-03）.