From 300a781fab5756d5608f78287a94be820eacc9ba Mon Sep 17 00:00:00 2001 From: Nan Lei Date: Tue, 19 Mar 2024 02:28:16 +0800 Subject: [PATCH] Update code comment of quadratic in time_complexity (#1155) --- codes/c/chapter_computational_complexity/time_complexity.c | 2 +- codes/cpp/chapter_computational_complexity/time_complexity.cpp | 2 +- .../csharp/chapter_computational_complexity/time_complexity.cs | 2 +- .../dart/chapter_computational_complexity/time_complexity.dart | 2 +- codes/go/chapter_computational_complexity/time_complexity.go | 2 +- .../java/chapter_computational_complexity/time_complexity.java | 2 +- .../chapter_computational_complexity/time_complexity.js | 2 +- .../kotlin/chapter_computational_complexity/time_complexity.kt | 2 +- .../python/chapter_computational_complexity/time_complexity.py | 2 +- .../chapter_computational_complexity/time_complexity.md | 2 +- codes/rust/chapter_computational_complexity/time_complexity.rs | 2 +- .../chapter_computational_complexity/time_complexity.swift | 2 +- .../chapter_computational_complexity/time_complexity.ts | 2 +- codes/zig/chapter_computational_complexity/time_complexity.zig | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/codes/c/chapter_computational_complexity/time_complexity.c b/codes/c/chapter_computational_complexity/time_complexity.c index dda7e0181..5236279d6 100644 --- a/codes/c/chapter_computational_complexity/time_complexity.c +++ b/codes/c/chapter_computational_complexity/time_complexity.c @@ -39,7 +39,7 @@ int arrayTraversal(int *nums, int n) { /* 平方阶 */ int quadratic(int n) { int count = 0; - // 循环次数与数组长度成平方关系 + // 循环次数与数据大小 n 成平方关系 for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { count++; diff --git a/codes/cpp/chapter_computational_complexity/time_complexity.cpp b/codes/cpp/chapter_computational_complexity/time_complexity.cpp index 845e62c6f..100498269 100644 --- a/codes/cpp/chapter_computational_complexity/time_complexity.cpp +++ b/codes/cpp/chapter_computational_complexity/time_complexity.cpp @@ -36,7 +36,7 @@ int arrayTraversal(vector &nums) { /* 平方阶 */ int quadratic(int n) { int count = 0; - // 循环次数与数组长度成平方关系 + // 循环次数与数据大小 n 成平方关系 for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { count++; diff --git a/codes/csharp/chapter_computational_complexity/time_complexity.cs b/codes/csharp/chapter_computational_complexity/time_complexity.cs index 22427d36c..51fd9ab4c 100644 --- a/codes/csharp/chapter_computational_complexity/time_complexity.cs +++ b/codes/csharp/chapter_computational_complexity/time_complexity.cs @@ -71,7 +71,7 @@ public class time_complexity { /* 平方阶 */ int Quadratic(int n) { int count = 0; - // 循环次数与数组长度成平方关系 + // 循环次数与数据大小 n 成平方关系 for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { count++; diff --git a/codes/dart/chapter_computational_complexity/time_complexity.dart b/codes/dart/chapter_computational_complexity/time_complexity.dart index 18b17c6f9..0ca83b43f 100644 --- a/codes/dart/chapter_computational_complexity/time_complexity.dart +++ b/codes/dart/chapter_computational_complexity/time_complexity.dart @@ -38,7 +38,7 @@ int arrayTraversal(List nums) { /* 平方阶 */ int quadratic(int n) { int count = 0; - // 循环次数与数组长度成平方关系 + // 循环次数与数据大小 n 成平方关系 for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { count++; diff --git a/codes/go/chapter_computational_complexity/time_complexity.go b/codes/go/chapter_computational_complexity/time_complexity.go index cdf66eaf8..9d001de11 100644 --- a/codes/go/chapter_computational_complexity/time_complexity.go +++ b/codes/go/chapter_computational_complexity/time_complexity.go @@ -36,7 +36,7 @@ func arrayTraversal(nums []int) int { /* 平方阶 */ func quadratic(n int) int { count := 0 - // 循环次数与数组长度成平方关系 + // 循环次数与数据大小 n 成平方关系 for i := 0; i < n; i++ { for j := 0; j < n; j++ { count++ diff --git a/codes/java/chapter_computational_complexity/time_complexity.java b/codes/java/chapter_computational_complexity/time_complexity.java index fdc6c85d7..47698b949 100644 --- a/codes/java/chapter_computational_complexity/time_complexity.java +++ b/codes/java/chapter_computational_complexity/time_complexity.java @@ -37,7 +37,7 @@ public class time_complexity { /* 平方阶 */ static int quadratic(int n) { int count = 0; - // 循环次数与数组长度成平方关系 + // 循环次数与数据大小 n 成平方关系 for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { count++; diff --git a/codes/javascript/chapter_computational_complexity/time_complexity.js b/codes/javascript/chapter_computational_complexity/time_complexity.js index 938f860a5..3d3ab4e19 100644 --- a/codes/javascript/chapter_computational_complexity/time_complexity.js +++ b/codes/javascript/chapter_computational_complexity/time_complexity.js @@ -32,7 +32,7 @@ function arrayTraversal(nums) { /* 平方阶 */ function quadratic(n) { let count = 0; - // 循环次数与数组长度成平方关系 + // 循环次数与数据大小 n 成平方关系 for (let i = 0; i < n; i++) { for (let j = 0; j < n; j++) { count++; diff --git a/codes/kotlin/chapter_computational_complexity/time_complexity.kt b/codes/kotlin/chapter_computational_complexity/time_complexity.kt index 485001408..4addb982f 100644 --- a/codes/kotlin/chapter_computational_complexity/time_complexity.kt +++ b/codes/kotlin/chapter_computational_complexity/time_complexity.kt @@ -37,7 +37,7 @@ fun arrayTraversal(nums: IntArray): Int { /* 平方阶 */ fun quadratic(n: Int): Int { var count = 0 - // 循环次数与数组长度成平方关系 + // 循环次数与数据大小 n 成平方关系 for (i in 0.. int: def quadratic(n: int) -> int: """平方阶""" count = 0 - # 循环次数与数组长度成平方关系 + # 循环次数与数据大小 n 成平方关系 for i in range(n): for j in range(n): count += 1 diff --git a/codes/pythontutor/chapter_computational_complexity/time_complexity.md b/codes/pythontutor/chapter_computational_complexity/time_complexity.md index 9cec3c897..0eb992ce3 100644 --- a/codes/pythontutor/chapter_computational_complexity/time_complexity.md +++ b/codes/pythontutor/chapter_computational_complexity/time_complexity.md @@ -14,7 +14,7 @@ https://pythontutor.com/render.html#code=def%20linear%28n%29%20-%3E%20int%3A%0A% https://pythontutor.com/render.html#code=def%20array_traversal%28nums%3A%20list%5Bint%5D%29%20-%3E%20int%3A%0A%20%20%20%20%22%22%22%E7%BA%BF%E6%80%A7%E9%98%B6%EF%BC%88%E9%81%8D%E5%8E%86%E6%95%B0%E7%BB%84%EF%BC%89%22%22%22%0A%20%20%20%20count%20%3D%200%0A%20%20%20%20%23%20%E5%BE%AA%E7%8E%AF%E6%AC%A1%E6%95%B0%E4%B8%8E%E6%95%B0%E7%BB%84%E9%95%BF%E5%BA%A6%E6%88%90%E6%AD%A3%E6%AF%94%0A%20%20%20%20for%20num%20in%20nums%3A%0A%20%20%20%20%20%20%20%20count%20%2B%3D%201%0A%20%20%20%20return%20count%0A%0A%22%22%22Driver%20Code%22%22%22%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20n%20%3D%208%0A%20%20%20%20print%28%22%E8%BE%93%E5%85%A5%E6%95%B0%E6%8D%AE%E5%A4%A7%E5%B0%8F%20n%20%3D%22,%20n%29%0A%0A%20%20%20%20count%20%3D%20array_traversal%28%5B0%5D%20*%20n%29%0A%20%20%20%20print%28%22%E7%BA%BF%E6%80%A7%E9%98%B6%EF%BC%88%E9%81%8D%E5%8E%86%E6%95%B0%E7%BB%84%EF%BC%89%E7%9A%84%E6%93%8D%E4%BD%9C%E6%95%B0%E9%87%8F%20%3D%22,%20count%29&cumulative=false&curInstr=3&heapPrimitives=nevernest&mode=display&origin=opt-frontend.js&py=311&rawInputLstJSON=%5B%5D&textReferences=false -https://pythontutor.com/render.html#code=def%20quadratic%28n%29%20-%3E%20int%3A%0A%20%20%20%20%22%22%22%E5%B9%B3%E6%96%B9%E9%98%B6%22%22%22%0A%20%20%20%20count%20%3D%200%0A%20%20%20%20%23%20%E5%BE%AA%E7%8E%AF%E6%AC%A1%E6%95%B0%E4%B8%8E%E6%95%B0%E7%BB%84%E9%95%BF%E5%BA%A6%E6%88%90%E5%B9%B3%E6%96%B9%E5%85%B3%E7%B3%BB%0A%20%20%20%20for%20i%20in%20range%28n%29%3A%0A%20%20%20%20%20%20%20%20for%20j%20in%20range%28n%29%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20count%20%2B%3D%201%0A%20%20%20%20return%20count%0A%0A%22%22%22Driver%20Code%22%22%22%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20n%20%3D%208%0A%20%20%20%20print%28%22%E8%BE%93%E5%85%A5%E6%95%B0%E6%8D%AE%E5%A4%A7%E5%B0%8F%20n%20%3D%22,%20n%29%0A%0A%20%20%20%20count%20%3D%20quadratic%28n%29%0A%20%20%20%20print%28%22%E5%B9%B3%E6%96%B9%E9%98%B6%E7%9A%84%E6%93%8D%E4%BD%9C%E6%95%B0%E9%87%8F%20%3D%22,%20count%29&cumulative=false&curInstr=3&heapPrimitives=nevernest&mode=display&origin=opt-frontend.js&py=311&rawInputLstJSON=%5B%5D&textReferences=false +https://pythontutor.com/render.html#code=def%20quadratic%28n%29%20-%3E%20int%3A%0A%20%20%20%20%22%22%22%E5%B9%B3%E6%96%B9%E9%98%B6%22%22%22%0A%20%20%20%20count%20%3D%200%0A%20%20%20%20%23%20%E5%BE%AA%E7%8E%AF%E6%AC%A1%E6%95%B0%E4%B8%8E%E6%95%B0%E6%8D%AE%E5%A4%A7%E5%B0%8F%20n%20%E6%88%90%E5%B9%B3%E6%96%B9%E5%85%B3%E7%B3%BB%0A%20%20%20%20for%20i%20in%20range%28n%29%3A%0A%20%20%20%20%20%20%20%20for%20j%20in%20range%28n%29%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20count%20%2B%3D%201%0A%20%20%20%20return%20count%0A%0A%22%22%22Driver%20Code%22%22%22%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20n%20%3D%208%0A%20%20%20%20print%28%22%E8%BE%93%E5%85%A5%E6%95%B0%E6%8D%AE%E5%A4%A7%E5%B0%8F%20n%20%3D%22,%20n%29%0A%0A%20%20%20%20count%20%3D%20quadratic%28n%29%0A%20%20%20%20print%28%22%E5%B9%B3%E6%96%B9%E9%98%B6%E7%9A%84%E6%93%8D%E4%BD%9C%E6%95%B0%E9%87%8F%20%3D%22,%20count%29&cumulative=false&curInstr=3&heapPrimitives=nevernest&mode=display&origin=opt-frontend.js&py=311&rawInputLstJSON=%5B%5D&textReferences=false https://pythontutor.com/render.html#code=def%20bubble_sort%28nums%3A%20list%5Bint%5D%29%20-%3E%20int%3A%0A%20%20%20%20%22%22%22%E5%B9%B3%E6%96%B9%E9%98%B6%EF%BC%88%E5%86%92%E6%B3%A1%E6%8E%92%E5%BA%8F%EF%BC%89%22%22%22%0A%20%20%20%20count%20%3D%200%20%20%23%20%E8%AE%A1%E6%95%B0%E5%99%A8%0A%20%20%20%20%23%20%E5%A4%96%E5%BE%AA%E7%8E%AF%EF%BC%9A%E6%9C%AA%E6%8E%92%E5%BA%8F%E5%8C%BA%E9%97%B4%E4%B8%BA%20%5B0,%20i%5D%0A%20%20%20%20for%20i%20in%20range%28len%28nums%29%20-%201,%200,%20-1%29%3A%0A%20%20%20%20%20%20%20%20%23%20%E5%86%85%E5%BE%AA%E7%8E%AF%EF%BC%9A%E5%B0%86%E6%9C%AA%E6%8E%92%E5%BA%8F%E5%8C%BA%E9%97%B4%20%5B0,%20i%5D%20%E4%B8%AD%E7%9A%84%E6%9C%80%E5%A4%A7%E5%85%83%E7%B4%A0%E4%BA%A4%E6%8D%A2%E8%87%B3%E8%AF%A5%E5%8C%BA%E9%97%B4%E7%9A%84%E6%9C%80%E5%8F%B3%E7%AB%AF%0A%20%20%20%20%20%20%20%20for%20j%20in%20range%28i%29%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20nums%5Bj%5D%20%3E%20nums%5Bj%20%2B%201%5D%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20%E4%BA%A4%E6%8D%A2%20nums%5Bj%5D%20%E4%B8%8E%20nums%5Bj%20%2B%201%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20tmp%20%3D%20nums%5Bj%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20nums%5Bj%5D%20%3D%20nums%5Bj%20%2B%201%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20nums%5Bj%20%2B%201%5D%20%3D%20tmp%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20count%20%2B%3D%203%20%20%23%20%E5%85%83%E7%B4%A0%E4%BA%A4%E6%8D%A2%E5%8C%85%E5%90%AB%203%20%E4%B8%AA%E5%8D%95%E5%85%83%E6%93%8D%E4%BD%9C%0A%20%20%20%20return%20count%0A%0A%22%22%22Driver%20Code%22%22%22%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20n%20%3D%208%0A%20%20%20%20print%28%22%E8%BE%93%E5%85%A5%E6%95%B0%E6%8D%AE%E5%A4%A7%E5%B0%8F%20n%20%3D%22,%20n%29%0A%0A%20%20%20%20nums%20%3D%20%5Bi%20for%20i%20in%20range%28n,%200,%20-1%29%5D%20%20%23%20%5Bn,%20n-1,%20...,%202,%201%5D%0A%20%20%20%20count%20%3D%20bubble_sort%28nums%29%0A%20%20%20%20print%28%22%E5%B9%B3%E6%96%B9%E9%98%B6%EF%BC%88%E5%86%92%E6%B3%A1%E6%8E%92%E5%BA%8F%EF%BC%89%E7%9A%84%E6%93%8D%E4%BD%9C%E6%95%B0%E9%87%8F%20%3D%22,%20count%29&cumulative=false&curInstr=3&heapPrimitives=nevernest&mode=display&origin=opt-frontend.js&py=311&rawInputLstJSON=%5B%5D&textReferences=false diff --git a/codes/rust/chapter_computational_complexity/time_complexity.rs b/codes/rust/chapter_computational_complexity/time_complexity.rs index 3464b98d1..a0951bd53 100644 --- a/codes/rust/chapter_computational_complexity/time_complexity.rs +++ b/codes/rust/chapter_computational_complexity/time_complexity.rs @@ -37,7 +37,7 @@ fn array_traversal(nums: &[i32]) -> i32 { /* 平方阶 */ fn quadratic(n: i32) -> i32 { let mut count = 0; - // 循环次数与数组长度成平方关系 + // 循环次数与数据大小 n 成平方关系 for _ in 0..n { for _ in 0..n { count += 1; diff --git a/codes/swift/chapter_computational_complexity/time_complexity.swift b/codes/swift/chapter_computational_complexity/time_complexity.swift index 23caaae39..3581752be 100644 --- a/codes/swift/chapter_computational_complexity/time_complexity.swift +++ b/codes/swift/chapter_computational_complexity/time_complexity.swift @@ -36,7 +36,7 @@ func arrayTraversal(nums: [Int]) -> Int { /* 平方阶 */ func quadratic(n: Int) -> Int { var count = 0 - // 循环次数与数组长度成平方关系 + // 循环次数与数据大小 n 成平方关系 for _ in 0 ..< n { for _ in 0 ..< n { count += 1 diff --git a/codes/typescript/chapter_computational_complexity/time_complexity.ts b/codes/typescript/chapter_computational_complexity/time_complexity.ts index f99d393dd..9b7bc4481 100644 --- a/codes/typescript/chapter_computational_complexity/time_complexity.ts +++ b/codes/typescript/chapter_computational_complexity/time_complexity.ts @@ -32,7 +32,7 @@ function arrayTraversal(nums: number[]): number { /* 平方阶 */ function quadratic(n: number): number { let count = 0; - // 循环次数与数组长度成平方关系 + // 循环次数与数据大小 n 成平方关系 for (let i = 0; i < n; i++) { for (let j = 0; j < n; j++) { count++; diff --git a/codes/zig/chapter_computational_complexity/time_complexity.zig b/codes/zig/chapter_computational_complexity/time_complexity.zig index 737367118..3437c7e1c 100644 --- a/codes/zig/chapter_computational_complexity/time_complexity.zig +++ b/codes/zig/chapter_computational_complexity/time_complexity.zig @@ -40,7 +40,7 @@ fn arrayTraversal(nums: []i32) i32 { fn quadratic(n: i32) i32 { var count: i32 = 0; var i: i32 = 0; - // 循环次数与数组长度成平方关系 + // 循环次数与数据大小 n 成平方关系 while (i < n) : (i += 1) { var j: i32 = 0; while (j < n) : (j += 1) {