Professional Documents
Culture Documents
Bc120401155 (Faiza Munir) : Solution: Code Line Number Instruction/code Time Taken Comments
Bc120401155 (Faiza Munir) : Solution: Code Line Number Instruction/code Time Taken Comments
CS502
Solution of question no 2:
Solution:
Code line number
01
02
03
Instruction/code
yz =0;
xw=0;
for(i=m; i>-6 i=i-6)
Time taken
1
1
(m/2+1)+1
Comments
It will take constant time
It will also take constant time
Outer independent loop1:
apply rule 2 mentioned
above in guidelines as
here step size is 2 so
value of k=2 and m
will control the
number of iterations
and rule gives you m/2
and base limit is -2
thats why we added
1 more here.
04
xw++;
m/2 +1
05
(n/1)+1=n+1
06
{ yz=yz+1;}
07
for (i=1;i<=n;i=i*5)
Log5n+1
08
for (j=1;j<=5n;j*12
5n(log5n)+1
09 a
for(k=n;k<-5; k=k-4)
(n/1)+1=n+1
09 b
x=x+12
13
While(k<=z)
As entrance in loop is
m/2+1 time
Outer independent loop2:
Again apply rule 2 here step
size is 1 so value of
k=1.
Other logic is same as
in above statement 3
only difference is of
m and n.
Entrance in a loop will be n
times.
Here step size is multiplied by
5 thats why log to the base 5
(rule 3)
As for each iteration
of outer loop this loop
will execute for 5n times
K is equal to n, k less than -5, k
is equal to -4 and loop is
executed to -5 times.
Entrance in a loop will be x
times.
While loop is use there.
15
k=k*2
K is equal to k multiple by 2.
17
(n/1)+1=n+1
Solution of question no 2:
Function no Given order
1
2
n/1000000
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
n/1000000