# SP Contest 1

• Last Updated : 11 Jul, 2018

 Question 1
How many times is the below loop executed?
``` for(int i=0; i < n; i++)
{
for(int j=0; j < (2*i); j+=(i/2))
{
cout<<"Hello Geeks";
}
}
```
 A O(n) B Infinite times C O(n2) D O(nlogn)
SP Contest 1
Discuss it

Question 1 Explanation:
At the second iteration of the outer loop, i.e. when i = 1, the inner loop will become an infinite loop as the increment condition is j = j+(i/2) and for i = 1, i/2 = 0.
 Question 2
The Postorder traversal of a Binary Search Tree is {35, 30, 45, 40, 70, 85, 90, 80, 50}. What is its Preorder traversal?
 A 50, 40, 30, 35, 45, 80, 70, 90, 85 B 50, 40, 45, 30, 35 ,80 , 90, 85, 70 C 50, 80, 90, 85, 70, 40, 45, 30, 35 D 30, 35, 40, 45, 50, 70, 80, 85, 90
SP Contest 1
Discuss it

Question 2 Explanation:
You may create a BST from it's given post order traversal and then find it's preorder traversal. Please refer to the post on Construct a Binary Search Tree from given postorder.
 Question 3
Which statement is true about initializing a variable to a default value (i.e. integer to 0, boolean to false) using the default constructor?
 A It initializes the data member variables to default values in C++ but not in JAVA. B It initializes the data member variables to default values neither in C++ nor in JAVA. C It initializes the data member variables to default values in C++ and JAVA both. D It initializes the data member variables to default values in JAVA but not in C++.
SP Contest 1
Discuss it

 Question 4
Below are some operators separated by comma in C++. Which of these operators cannot be overloaded?
```!, ::, ->*, ~, .*, sizeof, new
```
 A ->*, .*, sizeof B .*, ~, new C ::, sizeof, ! D sizeof, .*, ::
SP Contest 1
Discuss it

 Question 5
What is the output of below C program?
```#include <stdio.h>

void print(int c){

if (c < 0) {
return;
}

printf("%d ", c);
c--;
print(c);

c++;

printf("%d ", c);

}

int main() {
int c = 5;
print(c);
return 0;
}
```
 A 5 4 3 2 1 0 0 0 1 2 3 4 B 5 4 3 2 1 0 0 1 2 3 4 5 C 1 2 3 4 5 0 0 5 4 3 2 1 D 5 4 3 2 1 1 0 1 2 3 4 5
SP Contest 1
Discuss it

 Question 6
A can finish an IT project in 15 days, B can finish the same project in 12 days. In how many days, both of them can finish 60% of the project? It may be assumed that working together does not impact their productivity.
 A 2 days B 4 days C 6 days D 7 days
SP Contest 1
Discuss it

Question 6 Explanation:
A finish the work in one day = 1 / 15 B finish the work in one day = 1 / 12 If A and B work together to finish the project, then one day's work = 1 /15 + 1 / 12. Then 60% of work can be finished: (1 /15 + 1 / 12 ) * x = 6 / 10. X = 4 days.
 Question 7
How many numbers of 6 digits are possible with the property that the sum of their digits is 5?
 A 96 B 104 C 120 D 126
SP Contest 1
Discuss it

Question 7 Explanation:
There are 6 digits and their sum is 5. So,
`a + b + c + d + e + f = 5 `
where,
`1 ≤ a ≤ 9, and 0 ≤ b, c, d, e, f ≤ 9 `
Therefore,
```(a'+1) + b + c + d + e + f = 5
a' + b + c + d + e + f = 4 ```
Hence,
`(4+5)C5 = 9C5 = 126 `
So, option (D) is correct. Refer method-2: Indistinguishable balls and Distinguishable boxes .
 Question 8
Find the missing term in the below sequence:
```1, 1, 4, 25, 196, __ , 17424
```
 A 1561 B 1764 C 1600 D None of these
SP Contest 1
Discuss it

Question 8 Explanation:
Each term is the square of numbers of Catalan Series
 Question 9
Here are the two concurrent process A, B with respective codes: Code A:
```while (true) // infinite condition
{
M :____;
printf("%c", b);
printf("%c", b);
N:____;
}
```
Code B:
```while (true) // infinite condition
{
O:____;
printf("%c", a);
printf("%c", a);
P:____;
}
```
What should be the binary semaphore operation on M, N, O, P respectively and what must be the initial values of semaphore X, Y in order to get the output bbaabbaabbaa . . . ? Where P is down and V is up operation respectively.
 A M = P(Y), N = V(X), O = P(X), P = V(Y); X = 0, Y = 1; B M = P(Y), N = V(X), O = P(X), P = P(Y); X = Y = 1; C M = P(Y), N = V(Y), O = P(X), P = V(X); X = 1, Y = 0; D M = P(Y), N = V(Y), O = P(X), P = V(X); X = Y = 1;
SP Contest 1
Discuss it

Question 9 Explanation:
In semaphore up is always a successful operation but down is not always successful. In following concurrent process Operations are: A: code
```while (true) // infinite condition
{
M :P(Y); // Y become 0 successful down operation.
printf("%c", b);
printf("%c", b);
N:V(X); // X become 1 successful up operation.
}
```
B code:
```while (true) // infinite condition
{
O:P(X); // X  become 0 successful down operation.
printf("%c", a);
printf("%c", a);
P:V(Y); // Ybecome 1 successful up operation.
}```
Here all operation are successful with intial values of X and Y are 0 and 1 respectively. So, option (A) is correct.
There are 9 questions to complete.
My Personal Notes arrow_drop_up