You are on page 1of 8

Assignment#1 Computer Science

Q2. The origami is totally done and will be handled and discussed with the TA.
Q3.

Q4.

Q5.
def Fib (n)
if (n == 0)
return 0;
else if (n == 1)
return 1;
else
return fib(n - 1) + fib(n - 2);

Q6. " Bonus Best case analysis in insertion sort "


As shown in Q3. A psoudocode for insertion sort
The difference in the best case analysis is that the program will NOT go through the while loop not at all
as the array will be already sorted so the condition of ( A[wait -1]>original ) always fail .
So, T(n) would be = (c1 + c3 )*(n-1) which is time complexity of O(n).
Q7.
No.5 in the lab sheet:
Psoudocode:
Sum(n^2)
{
For i 1 to n
A[i] i * i ;
m length(A) ;
sum 0;
for i 1 to m
sum sum + A[i];
return sum;
}
No.8 in the lab sheet:
Psoudocode:
i2;
while i > = 2
{ If is prime devisors are 2 OR 3 OR both
return i ;
}
** the code is not in the strict sense as its not terminating

Name : Mahmoud Mohamed Bahaa El Din Khedr


ID no. 201301069

You might also like