Uploaded by Muhammed Hussein Sophy Mustafa

Assignment 2

advertisement
‫محمد حسين صوفي مصطفي‬
‫‪G6‬‬
‫‪1|Page‬‬
Question one
int main() {
int *nums, steps, *names;
16B
int n, s, m = 1000;
cin>> n >> S;
1 step , 12B
2 step
nums = new int[n];
1 step , 4n B
steps = new int[s];
1 step , 4s B
names = new int[m];
1 step , 4m B
for(int i = 0; i < n; i++){
1+1+(1+1+4)*n step , 4B
cout<<"Enter value of: " << i << endl;
cin>> nums[i];
3 step
1 step
}
int i = 0;
1 step , 4 B
while(i<s) {
1+(1+6)*s step
cout<<"enter steps of: " << i << endl;
cin>>steps[i++];
3 step
3 step
}
return 0;
}
1. # of steps =1+2+1+1+1+1+1+1+(1+1+4)*n+1+(1+6)*s =20+7n+6s
2|Page
2. 20+7n+6s =O(𝑛 + 𝑠)
3. # of bytes=16+12+4n+4s+4m++4+4=O(s+n+m)
Question two
int main() {
string *student, *teacher;
int s, t;
cin >> s >> t;
16B
8B
2 step
student = new string [s];
1 step , 8s B
2 step , 4𝑡 2 B
teacher =new string [int (pow(t, 2))];
for (int i=0; i<s; i++){
1+1+(1+1+(3+2+4+4s))*s step , 4B
cout<< "student: << i<<endl;
cout<< student[i] <<"=>";
3 step
2 step
for (int j=i, k=j; j<s, k < t; s++, k++){
cout<< "Teacher:" << k;
cout<< teacher [k]<< endl;
1+1+1+1+(1+1+1+1+4)*s=4+4s step , 8B
2 step
2 step
}
}
return 0;
}
4. # of steps =2+1+2+1+1+(1+1+(3+2+4+4s))*s=7+11s+ 4𝑠 2
5. 7+11s+ 4𝑠 2 =O(𝑠 2 )
6. # of bytes=16+8+8s+4𝑡 2 +4+8=O(s+𝑡 2 )
3|Page
4|Page
Download