update,
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
# Extra Lab - Algorithm Complexity
|
||||
|
||||
### Q1
|
||||
```
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = 0; j < n / 2; j++) {
|
||||
for (int k = 0; k < n / 1000; k++) {
|
||||
//something to run
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
### Q2
|
||||
```
|
||||
for (int x = n; x > 10; x /= 2) {
|
||||
//something to run
|
||||
}
|
||||
```
|
||||
|
||||
### Q3
|
||||
```
|
||||
int g = 1;
|
||||
while (g < n) {
|
||||
for (int v = 1; v < n - 9; v++) {
|
||||
//something to run
|
||||
}
|
||||
g *= 3;
|
||||
}
|
||||
```
|
||||
|
||||
### Q4
|
||||
```
|
||||
int i = 1;
|
||||
while (i < n) {
|
||||
i *= 2;
|
||||
method1(n);
|
||||
}
|
||||
|
||||
public static void method1(int n) {
|
||||
for (int i = 0; i < n / 4; i++) {
|
||||
//something to run
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Q5
|
||||
```
|
||||
public static void method2(int n) {
|
||||
//something to run
|
||||
if (n > 10)
|
||||
method2(n / 5);
|
||||
}
|
||||
```
|
||||
|
||||
### Q6
|
||||
```
|
||||
public static int method3(int n) {
|
||||
//something to run
|
||||
if (n > 10) {
|
||||
return (method3(n - 6));
|
||||
} else
|
||||
return 1;
|
||||
}
|
||||
```
|
||||
|
||||
### Q7
|
||||
```
|
||||
public static int method4(int n) {
|
||||
//something to run
|
||||
if (n > 1) {
|
||||
return (method4(n - 1) + method4(n - 1));
|
||||
} else
|
||||
return 1;
|
||||
}
|
||||
```
|
||||
|
||||
## Answer
|
||||
```
|
||||
q1 O(n^3)
|
||||
|
||||
q2 O(log n)
|
||||
|
||||
q3 O(n log n)
|
||||
|
||||
q4 O(n log n)
|
||||
|
||||
q5 O(log n)
|
||||
|
||||
q6 O(n)
|
||||
|
||||
q7 O(2^n)
|
||||
```
|
7
_resources/it114105/itp4510/extra/README.md.original
Normal file
7
_resources/it114105/itp4510/extra/README.md.original
Normal file
@@ -0,0 +1,7 @@
|
||||
### Extra Lab
|
||||
|
||||
<ol>
|
||||
<li><a href="./SpecialLab/">Special Lab : create java code (in one file) for the class diagram</a>
|
||||
</li>
|
||||
<li><a hre="./AlgoComplexity/">Algorithm/ Methods Complexities</a>
|
||||
</ol>
|
47
_resources/it114105/itp4510/extra/SpecialLab/Main.java
Normal file
47
_resources/it114105/itp4510/extra/SpecialLab/Main.java
Normal file
@@ -0,0 +1,47 @@
|
||||
interface Payable {
|
||||
public double getPayAmt();
|
||||
}
|
||||
|
||||
class Invoice implements Payable{
|
||||
private String invid;
|
||||
public double getPayAmt(){
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
class Employee extends Person implements Payable {
|
||||
private String empid;
|
||||
public Employee(String empid){
|
||||
this.empid = empid;
|
||||
}
|
||||
public double getPayAmt(){
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
abstract class Person {
|
||||
private String name;
|
||||
public String getName(){
|
||||
return name;
|
||||
}
|
||||
public void setName(String name){
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
class Customer extends Person {
|
||||
private String custid;
|
||||
public Address address;
|
||||
|
||||
public Customer(){
|
||||
this.address = new Address();
|
||||
}
|
||||
}
|
||||
|
||||
class Address {
|
||||
private String room;
|
||||
private String street;
|
||||
public String getAddress(){
|
||||
return "";
|
||||
}
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
# Special Lab
|
||||
Question: create java code (in one file) for the below class diagram
|
||||
|
||||
<img src="./class_diagram.png"/>
|
||||
* There are some mistake, you need to fix it.
|
BIN
_resources/it114105/itp4510/extra/SpecialLab/class_diagram.png
(Stored with Git LFS)
Normal file
BIN
_resources/it114105/itp4510/extra/SpecialLab/class_diagram.png
(Stored with Git LFS)
Normal file
Binary file not shown.
Reference in New Issue
Block a user