This commit is contained in:
louiscklaw
2025-02-01 01:58:47 +08:00
parent b3da7aaef5
commit 04dbefcbaf
1259 changed files with 280657 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
### Q1
For each of the following code snippets, identify the critical section(s), compute the time (T(n)) each one takes, and specify the asymptotic complexity using Big-O.
(i)
```
for(int k=0; k<n; k+=3) {
for(int p=n; p>6; p--) {
System.out.println(p%2);
}
}
O(n^2)
```
(ii)
```
for(int k=0;k<=n/8;k++) {
System.out.println(k);
}
System.out.println(“Next”);
for (int p=n; p>=1;p--) {
System.out.println(p%2);
}
O(n)
```
(iii)
```
for (int k=0; k<n-1; k++) {
for (int m=k+1; m<n; m++) {
System.out.println(k*m);
}
}
O(n^2)
```