update,
This commit is contained in:
37
it114105/itp4510/Lab04/Lab4.1/README.md.original
Normal file
37
it114105/itp4510/Lab04/Lab4.1/README.md.original
Normal 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)
|
||||
```
|
Reference in New Issue
Block a user