Skip to content

Commit 7dcd5c7

Browse files
authored
Update Time_Complexity.md
修改了一些细节方面的问题,比如else拼写错啦,然后函数掉了一个反括号等等
1 parent f2402ff commit 7dcd5c7

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

website/content/ChapterOne/Time_Complexity.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ weight: 3
3434

3535
```c
3636
void hello (int n){
37-
for( int sz = 1 ; sz < n ; sz += sz)
38-
for( int i = 1 ; i < n ; i ++)
37+
for( int sz = 1 ; sz < n ; sz += sz )
38+
for( int i = 1 ; i < n ; i ++ )
3939
cout << "Hello" << endl;
4040
}
4141
```
@@ -45,7 +45,7 @@ void hello (int n){
4545
```c
4646
bool isPrime (int n){
4747
for( int x = 2 ; x * x <= n ; x ++ )
48-
if( n % x == 0)
48+
if( n % x == 0 )
4949
return false;
5050
return true;
5151
}
@@ -67,7 +67,7 @@ bool isPrime (int n){
6767
int sum( int n ){
6868
assert( n >= 0 )
6969
int ret = 0;
70-
for ( int i = 0 ; i <= n ; i++)
70+
for ( int i = 0 ; i <= n ; i ++ )
7171
ret += i;
7272
return ret;
7373
}
@@ -80,7 +80,7 @@ int sum( int n ){
8080
assert( n >= 0 )
8181
if ( n == 0 )
8282
return 0;
83-
return n + sum( n - 1);
83+
return n + sum( n - 1 );
8484
}
8585
```
8686

@@ -96,14 +96,14 @@ int sum( int n ){
9696

9797
```c
9898
int binarySearch(int arr[], int l, int r, int target){
99-
if( l > r)
99+
if( l > r )
100100
return -1;
101-
int mid = l + (r-l)/2;//防溢出
101+
int mid = l + ( r - l ) / 2; // 防溢出
102102
if(arr[mid] == target)
103103
return mid;
104-
else if (arr[mid]>target)
104+
else if (arr[mid] > target)
105105
return binarySearch(arr,l,mid-1,target);
106-
eles
106+
else
107107
return binarySearch(arr,mid+1,r,target);
108108
}
109109

@@ -119,16 +119,16 @@ int binarySearch(int arr[], int l, int r, int target){
119119
```c
120120
int f(int n){
121121
assert( n >= 0 );
122-
if( n ==0 )
122+
if( n == 0 )
123123
return 1;
124124
return f( n - 1 ) + f ( n - 1 );
125-
125+
}
126126
```
127127

128128
上述这次递归调用的次数为 2^0^ + 2^1^ + 2^2^ + …… + 2^n^ = 2^n+1^ - 1 = O(2^n)
129129

130130

131-
> 关于更加复杂的递归的复杂度分析,请参考,主定理。主定理中针对各种复杂情况都给出了正确的结论。
131+
> 关于更加复杂的递归的复杂度分析,请参考主定理。主定理中针对各种复杂情况都给出了正确的结论。
132132
133133

134134
----------------------------------------------

0 commit comments

Comments
 (0)