SP Contest 3
Question 1 |
What will be the equivalent postfix expression of the given infix expression:
Infix Expression: a+b*(c/d-e/f)/(g^h)-i
abcd / ef / - * gh ^ / + i - | |
abcd / ef / - * gh ^ / + - i | |
abcd / ef / - * gh / ^ + i - | |
abcd / ef / - * gh ^ / - + i |
Discuss it
Question 1 Explanation:
Question 2 |
What is the minimum number of queues needed to implement a stack? We are not allowed to use any other data structure and also not allowed to use recursion. We may assume that given queue has basic functions like enqueue(), dequeue(), size(), isEmpty()
1 | |
2 | |
3 | |
4 |
Discuss it
Question 2 Explanation:
https://www.geeksforgeeks.org/implement-a-stack-using-single-queue/
Question 3 |
Which of the following permutation can be obtained in the same order using a stack assuming that input is the sequence 3, 4, 2, 1, 5 in that order?
Note: Any element can be pushed only once in the stack.
2, 1, 3, 4, 5 | |
5, 3, 4, 2, 1 | |
1, 5, 3, 4, 2 | |
2, 1, 5, 4, 3 |
Discuss it
Question 3 Explanation:
https://www.geeksforgeeks.org/stack-permutations-check-if-an-array-is-stack-permutation-of-other/
Question 4 |
What does the below function do in general?
void fun(Queue *Q)
{
Stack S; // Say it creates an empty stack S
// Run while Q is not empty
while (!isEmpty(Q))
{
// deQueue an item from Q and
// push the dequeued item to S
push(&S, deQueue(Q));
}
// Run while Stack S is not empty
while (!isEmpty(&S))
{
// Pop an item from S and enqueue
// the poppped item to Q
enQueue(Q, pop(&S));
}
}
Removes the last element from the queue, Q | |
Keeps the queue, Q same as it was before the call | |
Makes queue Q empty | |
Reverses the queue Q |
Discuss it
Question 4 Explanation:
The function takes a queue Q as an argument. It dequeues all items of Q and pushes them to a stack S. Then pops all items of S and enqueues the items back to Q. Since stack is LIFO order, all items of the queue are reversed.
Question 5 |
Five full-time employees and 6 interns work 12 hours a day and finish a task in 20 days. 8 full-time employees and 18 interns work 10 hours a day and finish the same task in 12 days. How many are working hours per day required if 5 full-time employees and 6 interns work for 30 days to finish the same amount of work? We may assume that changing number of people in a group does not change productivity.
8 hours a day | |
7 hours a day | |
6 hours a day | |
5 hours a day |
Discuss it
Question 5 Explanation:
(5 full time + 6 interns) * 12 * 20 = (8 full time + 18 interns) * 10 * 12
(5 full time + 6 interns) * 2 = (8 full time + 18 interns)
2 full time = 6 interns
1 full time = 3 interns.
Now (8 full time + 18 interns) * 10 * 12 = (5 full time + 6 interns) * x * 30
42 interns * 12 * 10 = 21 interns * x * 30
X = 8 hours a day.
Question 6 |
Find the missing numbers in the series:
4, 6, 8, 9, _, 12, 14, 15, _, 18. . . .
11 and 17 respectively. | |
10 and 16 respectively. | |
11 and 16 respectively. | |
10 and 17 respectively. |
Discuss it
Question 6 Explanation:
Given series is the list of composite numbers.
Question 7 |
Consider the below C program:
int main()
{
fork();
fork();
fork();
printf("Hello World");
}
How many child processes will be created when the above program executes?4 | |
5 | |
6 | |
7 |
Discuss it
Question 7 Explanation:
For n fork calls in a program, (2n-1) child processes are created.
Here n = 3.
Therefore, no of child process = 23 - 1 = 8 - 1 = 7.
Question 8 |
Which of the below statements are false about static member functions?
- Static member functions can have this pointer.
- Static member functions cannot be virtual.
- Static member functions cannot be const.
- Static member functions can be volatile.
1, 2 | |
3, 4 | |
1, 4 | |
1, 3 |
Discuss it
Question 8 Explanation:
https://www.geeksforgeeks.org/some-interesting-facts-about-static-member-functions-in-c/
Question 9 |
What will be the output of below C++ Program?
class Gfg
{
public:
int main(int s)
{
cout << s << ", ";
return 0;
}
int main(char *s)
{
cout << s << โ, โ;
return 0;
}
int main(int s ,int m)
{
cout << s << " " << m;
return 0;
}
};
int main()
{
Gfg obj;
obj.main(3);
obj.main("Hello World!");
obj.main(9, 6);
return 0;
}
3 | |
Error | |
3, Hello World!, 9 6 | |
3, Garbage Value, 9 6 |
Discuss it
Question 9 Explanation:
Question 10 |
Given below is a C++ function to evaluate a postfix expression represented as a string. The below code contains proper comments and some statements are marked specially. Find the statements which will lead to incorrect output.
// C++ function to evaluate a given postfix expression
int evaluatePostfix(char* exp)
{
// Create a stack of capacity equal to expression size
stack<int> st;
int i;
// Scan all characters one by one
for (i = 0; exp[i]; ++i)
{
// If the scanned character is an operand (number here),
// push it to the stack.
// The isdigit() function is used to check if a particular
// character in the given input string is a digit or not.
if (isdigit(exp[i]))
st.push(exp[i]); // Statement 1
// If the scanned character is an operator, pop two
// elements from stack apply the operator
else
{
int val1 = st.top(); // Statement 2
st.pop();
int val2 = st.top();
st.pop();
switch (exp[i]) // Statement 3
{
case '+': st.push(val2 + val1); break;
case '-': st.push(val2 - val1); break;
case '*': st.push(val2 * val1); break;
case '/': st.push(val2/val1); break;
}
}
}
return st.top();
}
Statement 2 | |
Statement 1 | |
Statement 3 & Statement 1 | |
None of the above |
Discuss it
Question 10 Explanation:
https://www.geeksforgeeks.org/stack-set-4-evaluation-postfix-expression/
There are 10 questions to complete.


