SP Contest 1
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"; } }
O(n) | |
Infinite times | |
O(n2) | |
O(nlogn) |
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?
50, 40, 30, 35, 45, 80, 70, 90, 85 | |
50, 40, 45, 30, 35 ,80 , 90, 85, 70 | |
50, 80, 90, 85, 70, 40, 45, 30, 35 | |
30, 35, 40, 45, 50, 70, 80, 85, 90 |
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?
It initializes the data member variables to default values in C++ but not in JAVA. | |
It initializes the data member variables to default values neither in C++ nor in JAVA. | |
It initializes the data member variables to default values in C++ and JAVA both. | |
It initializes the data member variables to default values in JAVA but not in C++. |
Discuss it
Question 3 Explanation:
Question 4 |
Below are some operators separated by comma in C++. Which of these operators cannot be overloaded?
!, ::, ->*, ~, .*, sizeof, new
->*, .*, sizeof | |
.*, ~, new | |
::, sizeof, ! | |
sizeof, .*, :: |
Discuss it
Question 4 Explanation:
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; }
5 4 3 2 1 0 0 0 1 2 3 4 | |
5 4 3 2 1 0 0 1 2 3 4 5 | |
1 2 3 4 5 0 0 5 4 3 2 1 | |
5 4 3 2 1 1 0 1 2 3 4 5 |
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.
2 days | |
4 days | |
6 days | |
7 days |
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?
96 | |
104 | |
120 | |
126 |
Discuss it
Question 7 Explanation:
There are 6 digits and their sum is 5. So,
a + b + c + d + e + f = 5where,
1 ≤ a ≤ 9, and 0 ≤ b, c, d, e, f ≤ 9Therefore,
(a'+1) + b + c + d + e + f = 5 a' + b + c + d + e + f = 4Hence,
(4+5)C5 = 9C5 = 126So, 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
1561 | |
1764 | |
1600 | |
None of these |
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.
M = P(Y), N = V(X), O = P(X), P = V(Y); X = 0, Y = 1; | |
M = P(Y), N = V(X), O = P(X), P = P(Y); X = Y = 1; | |
M = P(Y), N = V(Y), O = P(X), P = V(X); X = 1, Y = 0; | |
M = P(Y), N = V(Y), O = P(X), P = V(X); X = Y = 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.