Você está na página 1de 10

Bangladesh Informatics Olympiad 2013

Divisional Competition
(ID Number):

___________________________________________________

(Name):

___________________________________________________

(Class):

___________________________________________________

(Institution):

___________________________________________________

(Date of Birth): ___________________________________________________

: (Phone):

___________________________________________________

(E-mail):

___________________________________________________

(Instructions):
(You can answer either in

.
Bangla or English.)

(The answers should be as brief as possible.)

.
.

(Topics mentioned

under Required knowledge are described at the end of the question paper.)
.

(For general solutions Mathematical formula, step by description or programming


code - anything is acceptable.)
.

(Partial

answers will also be evaluated, so we encourage you to answer as much as you can.)

marks.)

(Number of questions is 10. Each question carries 20

1
Question 1:

? (You are

given an even number N, Find the summation of all even numbers between 1 and N)
(Write the general formula) [10]

i)
ii)

N=10 (Find the summation when N=10) [2]

iii)

N=100 (Find the summation when N=100) [3]

iv)

N=2000000000 (Find the summation when N=2000000000) [5]

Question 2:
(Required Knowledge):
(Binary Numbers)
B

V
0

1)

0
X (X

(You are given a binary

number B and a value V. At the beginning V is 0. Starting from left to right for every digit of the binary
number you will change that value of V. Suppose the next digit is X ( X is obviously 0 or 1).You will
change V in the following process)

V
of V)

(Previous Value

(Value of X)

B=110
)

V=0
1

V=0

X=1 ,

V=1

1.

V=1

X=1,

V=0

V=0

X=0,

V=0

(New Value of V)

2
(Suppose B=110.Then at the beginning V=0;
1) Leftmost digit is 1. As X=1 and V=0 , so now V=1.
2) Next digit is 1.As X=1 and V=1 , now V will be 0
3) Next digit is 0. As X=0 and V=0 , now V will be 0.
So final value of V is 0.)
i) B

(Propose a general

method to find the final value of V for any binary number B) [10]
ii) V

10110001110010 (Find V when B is the binary

number 10110001110010) [2]


iii) V

B 1234

(Find V when B is the Binary representation of

the decimal number 1234) [3]


iv) V

B 123456789101112

(Find V when B is the Binary

representation of the decimal number 123456789101112) [5]


Question 3:
0

, 0011, 0, 1, 110, 1010, 1111

? (A bit string consists of only 0

and 1. For example, 0011, 0, 1, 110, 1010, 1111 are some bit strings. How many bit strings of
length N has more 1s than 0s?)
i) N=3

? (How many string is there for N=3?) [2]

ii) N=10

? (How many string is there for N=10?) [3]

iii) N=500

? (How many string is there for N=500?) [5]


(Propose a general solution of N length bit string) [10]

iv) N
Question 4:
(Required Knowledge):
(Tree)
,

(You are given a rooted tree with N nodes. You are currently in the root. You want to visit all the
nodes of the tree at least once. You need one second to go from one node to an adjacent node)

i)
,
?

N (How much

time do you need, if you have to go back to the


root in minimum amount of time after visiting all
the nodes? Total number of node including root is
N) [6]
ii)
,
?

N (Find the

minimum possible time you need if you stop right


after visiting all the nodes. Total number of node
including root is N) [10]

iii)

(i)

Figure Q4(iii)

(ii)

(Find the time for cases (i) and (ii) for


the tree in figure) [4]

Question 5::
(Required Knowledge):
/

(Stack/Queue)

popS

pushQ(X)

popQ

[2,1]
[2,1]

pushS(X) X
X

pushS(1)

pushS(3)

pushS(2)

[3,2,1] popS

, pushQ(1), pushQ(2), pushQ(5)

[1,2,5] popQ

[2,5]

,
(You are given a stack and a

queue. Given functions are pushS(X) which pushes the value X in top of the stack, popS which pops the
value from stack top, pushQ(x) which pushes the value X in back of the queue and popQ which pops the
value in front of the queue. For example, if we execute pushS(1) and pushS(2) the stack will look like [2,1]
from top to bottom. And then if we pushS(3) then the stack becomes [3,2,1]. After a popS it becomes
[2,1]. Similarly for pushQ(1), pushQ(2) and pushQ(5) the queue looks like [1,2,5] from front to back. After
a popQ it becomes [2,5]. Now given a set of instructions executed one after one, write the condition of the
stack and queue after executing each instructions. the first two is done for your convenience) [20]

4
i) pushS(1) Answer: [1],[]
ii) pushS(2) Answer: [2,1],[]
iii) pushQ(5)
iv) popS
v) popQ
vi) pushQ(10)
vii) pushS(3)
viii) pushQ(20)
ix) pushS(popQ)
x) popS
xi) popS
xii) popQ
Question 6:
(Required Knowledge):
/

(Stack/Queue)
reverse(k)

[1,3,5,4,6], reverse(3)

[5,3,1,4,6].

reverse(3), reverse(4), reverse(3)

reverse(2)

[1,3,4,5,6]

[1,3,5,4,6]

(You are given a stack and a operation reverse(k) which


reverses the order of the top k element of the stack. For example, if a stack is [1,3,5,4,6], after reverse(3)
it becomes [5,3,1,4,6]. Using only this operation sort a stack from lowest to highest value. For the stack
[1,3,5,4,6] in example we can perform reverse(3), reverse(4), reverse(3) and reverse(2) to get [1,3,4,5,6].
Try to do this using minimal number of operations.)
i)

(Write the operation sequence for the stack

[1,7,5,2,4,3,6]

[1,7,5,2,4,3,6]) [7]
(Write the general steps to solve the problem) [13]

ii)
Question 7:
(Required Knowledge):
(Recurrence Relation)
i) b(n)

(Find of the value of b(n)) [4]

b(n) = 2b(n-1) + 3, where b(0) = 3, n >= 0


1 n=3
2 n = 10

ii) a(n)

(Find of the value of a(n)) [6]

a(n) = a(n-1) + 7b(n - 2) where a(0) = 2, n >= 0 [b(n)

(The definition of

b(n) is mentioned in question i)]


1 n=3
2 n = 10
iii) F(n,k)

(Find of the value of F(n,k)) [10]

F(n,k) = 2F(n-1,k) + F(n-1,k-1) where, F(0,k) = 1, F(n,0) = 1, n >= 0 and k >= 0


1
2

n = 2, k = 2
n = 5, k = 3

Question 8:
(Required Knowledge):
(Recurrence Relation)
n

(How many n-digit numbers are there, where the sum of every adjacent digit is less than or equal to 3?)
n=3

30

(Example: For n = 3, there can be 30 such numbers.)

[000, 001, 002, 003, 010, 011, 012, 020, 021, 030, 100, 101, 102, 103, 110, 111,112, 120, 121, 200, 201,
202, 203, 210, 211, 212, 300, 301, 302, 303]
i) n = 4

(Find the result for n = 4.) [3]

ii) n = 7

(Find the result for n = 7.) [5]

iii)

(Find a recursive solution of the problem.) [12]

Question 9::

x
5

5
5

1
1*2=2 5

2 5
2

1
(1

5)

12

12

1, 2, 3 12 1,2
3*2=6 12

12

3
6

(1, 2, 3, 4, 6


12)

?
[5]

1
2

100

[15]
(Professor K invented a process to find how many factors (divisors) are there of a number n. The process
is:

Find out the number of positive integers between 1 and the square root of n, which are factors of
n. Let this value to be x.

The answer is twice the value of x

For example: For n = 5, Only 1 and 2 is less than the square root of 5. Of them only 1 divides 5. So
according to the process of professor K the number of factors is 1*2 = 2. 5 has 2 divisors (1 and 2)
For n = 12, Only 1, 2 and 3 are less than the square root of 12. Of them 1, 2 and 3 divides 12. So
according to the process of professor K the number of factors is 3*2 = 6. 12 has 6 divisors (1, 2, 3, 4, 6,
12)
Do you think professor Ks process is correct?
1 If not, show an example for which the process will fail. [5]
2 For how many numbers between 1 and 100 this process will fail?) [15]

Question 10::

n
k

PP.P(

n = 4, k = 3, m = 2
)
i) n, m

.PPP, PPP., P.P.

ii) n = 5, k = 3, m = 2 [3]
iii) n = 1000000000, k = 30, m = 25 [5]

PP..
[12]

7
(n pigeonholes are kept side by side in a row. You want to put pigeons in some of the holes in a way that
for every k consecutive holes there will be exactly m holes with a pigeon. There shouldnt be more than
one pigeon in a hole.
For example:
For n = 4, k = 3, m = 2, a solution can be PP.P(Here P means a pigeon and . means a hole). But
.PPP, PPP., P.P. or PP.. arent solutions.
i) Write a general formula to find the number of solutions for n, m and k. [12]
ii) n = 5, k = 3, m = 2 [3]
iii) n = 1000000000, k = 30, m = 25 [5]

(Appendix)
(Recurrence Relation)
,

(In mathematics, a recurrence relation is an equation which defines a sequence where one or more initial
terms are given and each further term of the sequence is defined as a function of the preceding terms.)
,

(For example, consider the following recurrence relation)

T(n) = 2T(n-1) + 1, T(0) = 0


(Building a table of values yields the following)
n

T(n)

15

31

63

127

T(n)

2 -1

(We might conjecture that that the

value of T(n) is 2 -1 which is true. You can prove it using mathematical induction. One well known
recurrence relation is the Fibonacci sequence.)
(Binary Numbers)

8
(Its possible to uniquely express any number as a sum of one or more power(s) of two. We
can express the number as a sum of each used powers of two multiplied by 1 and each unused powers
multiplied by 0. Youll get a better idea from the following example)
11 = 8 + 2 + 1 =1 * 2^3 + 0 * 2^2 + 1 * 2^1 + 1 * 2^0 = 1011 in Binary

10

10

11

100

101

110

111

1000

1001

1010

(Binary)

(Stack)

Pop
Pop

[1, 2]

Push

[2] Push(3)

1
[3,2]

(Stack can be compared with a pile of books. If we want

to put a new book in the pile we put the book on the top and if we remove one we remove from the top
too. Here putting something is called Push and removing is called pop. For example, if we have a stack
[1,2] where 1 is the topmost item. If you pop we will get 1 and the stack becomes [2]. After Push(3) the
stack becomes [3,2]. Thats why stacks operation is called Last in first out)
(Queue)

Push

Pop

[1, 2]

1
[2,3]

Pop

[2] Push(3)
(Queue can be compared

with a line in front of a bus counter where a new person stand in the back of the line and the ticket is
given to the person in the front of the line. Here standing in the back is called Push and giving ticket to the
front person is called Pop. For Example, we have a queue [1,2] where 1 is the front item. If we Pop we
will get 1 and the queue becomes [2]. If we Push(3) then the queue becomes [2,3]. This nature of queue
is called First in first out)

(Node):

(A point or object. In the figure, there


are ten nodes.)

(Edge):

(The

relationship between two nodes. It is represented


as a line between two nodes. These node are
considered to be adjacent to each other. For
example, in the figure. 4 and 9 are adjacent to 3. 4
and 7 are adjacent to 6.)

(Root):

(A

special node. Here 3 is the root.)


(Predecessor):

(The idea

of predecessor is best explained from the figure.


Here node 4 is the predecessor to 10, 5 and 6.
Root does not have any predecessor.)
(Tree):

n-1

(Collection of nodes and edges such that every


node other than the root has exactly one
predecessor. A tree with n node has exactly n-1
edges.)

Você também pode gostar