Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

1. Write an algorithm which calculates Fibonacci numbers with the indices from 1 till the n without using indices.

n
is given natural number; (0.5 points)

a=1;
b=1;
for(i=3; i<n;i++)
c=a+b;
a=b;
b=c;
2. Write an algorithm which calculates the value of an expression:
S=1+1/x+1/x2+1/x3+…+1/xn
n is given natural number and x (x≠0) is given integer number; (0.5 points)
S[0]=1;
a[0]=1;
For (i=1;i<n;i++){
a[i]=a[i-1]/x;
S[i]=S[i-1]+a[i];
}

3. Write an algorithm (using a Dynamic Programming) which from the given matrix B with size NxM builds matrix C
with same size, an element C[i,j] of which is maximal from elements that lie in the left and upper side of the
position (i,j) (including) of the matrix B; (1 points)

B[0][0]=A[0][0];
for(j=1; j<m;j++)
B[0][j]=max(B[0][j-1],A[0][j]);
For (i=1;i<n;i++)
B[i][0]=max(B[i-1][0],A[i][0]);
for(i=1;i<n;i++)
for(j=1;j<m;j++){
B[i][j]=max(B[i][j-1],B[i-1][j])
B[i][j]=max(B[i][j],A[i][j]
}

4. Given a binary array:


0 1 0 1 0 1
1 1 1 1 1 0
1 1 1 1 0 1
1 1 1 1 1 0
1 0 1 1 1 1

0 1 0 1 0 1
1 1 1 1 1 0
1 1 1 1 0 1
1 1 1 1 1 0
1 0 1 1 1 1
You need to find a square block in this array with maximal size that consists of only 1’s; . Build the dynamic array
with the same size and fill it by solutions of subtasks. Find the size of the block that satisfies the conditions
described above; (0.5 points)

array with solution of subtasks :


0 1 0 1 0 1
1 1 1 1 1 0
1 2 2 2 0 1
1 2 3 3 1 0
1 0 1 2 2 1
Answer of task : max=3
5. Which is a right recurrent relation from the following equations (i-natural number) : (0.5 points)
ა) P(i)=P(i-1)*i, i≥2
P(1)=1;
ბ) S(i)=S(i-1)+1/i, i≥1
S(0)=0;
გ) S(i)=S(i-1)+S(i-2), i≥2
S(1)=1;
დ) S(i)=S(i-1)+(-1)i*xi/i, i≥1
S(0)=1.
ე) S(i)=S(i-1)-ai;
ვ) S(i)=S(i div 2)+1, i≥2
S(0)=1;

გ) is the correct answer

You might also like