Week 1 CP
Week 1 CP
0
0(1)
0
O(n)
0
O(n log n)
0
O(n 2 )
0 Minimum = 8, Maximum = 44
0 Minimum = 8, Maximum = 45
0 Minimum = 9, Maximum = 45
0 Minimum = 9, Maximum = 44
l 1 point
4) Consider the problem Reversort discussed 1 point
in the lecture. For which of the following input array of
size N = 8, Cost C is 20?
9 [2, 8, 3, 5, 1, 6, 4, 7]
D [1, 3, 5, 7, 8, 6, 4, 2]
9 [1, 7, 2, 5, 3, 8, 6, 4]
9 [5, 3, 7, 1, 2, 6, 4, 8]
D [2, 4, 6, 8, 7, 5, 3, 1]
5) Consider the problem Number Game 1 point
discussed in the lecture. Suppose now it's Arya's turn.
Which of the following is/are the winning position for
Arya?
9 A= 1, B = 26
9 A= 4, B = 16
DA= 5, B = 5
DA= 21, B = 13
■ A= 14, B = 8
Common Statement for Question 6 and 7
1 whi l e ( n > 1)
2 {
3 if (n ~ 2 =-- 0)
4 {
s n == n/ 2;
6 }
7 else
8 {
9 n a 3 • n + 1;
10 }
11 }
]
1 point
0
If n is odd, then the code will never stop.
0
If n is even, then the code will never stop.
0
It wi II stop for all values of n .
0
It will never stop for all values of n .
8) The game Race of 50 proceeds as follows. 1 point
0
l 2 3 4 n
Symbols : 0 and X
01X [o
n• l
Iobol odoI
• Q Q Q Q ~
..
Minimum 3 X
m == 4
[..___
a _ _ _]
1 point