# SP Contest 3

• Last Updated : 25 Jul, 2018

 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
```
 A abcd / ef / - * gh ^ / + i - B abcd / ef / - * gh ^ / + - i C abcd / ef / - * gh / ^ + i - D abcd / ef / - * gh ^ / - + i
SP Contest 3
Discuss it

 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()
 A 1 B 2 C 3 D 4
SP Contest 3
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.
 A 2, 1, 3, 4, 5 B 5, 3, 4, 2, 1 C 1, 5, 3, 4, 2 D 2, 1, 5, 4, 3
SP Contest 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?

## C

```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 popped item to Q
enQueue(Q, pop(&S));
}
}
```
 A Removes the last element from the queue, Q B Keeps the queue, Q same as it was before the call C Makes queue Q empty D Reverses the queue Q
SP Contest 3
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.
 A 8 hours a day B 7 hours a day C 6 hours a day D 5 hours a day
SP Contest 3
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. . . .
```
 A 11 and 17 respectively. B 10 and 16 respectively. C 11 and 16 respectively. D 10 and 17 respectively.
SP Contest 3
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?
 A 4 B 5 C 6 D 7
SP Contest 3
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?
1. Static member functions can have this pointer.
2. Static member functions cannot be virtual.
3. Static member functions cannot be const.
4. Static member functions can be volatile.
 A 1, 2 B 3, 4 C 1, 4 D 1, 3
SP Contest 3
Discuss it

Question 8 Explanation:
 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(&quot;Hello World!&quot;);
obj.main(9, 6);
return 0;
}
```
 A 3 B Error C 3, Hello World!, 9 6 D 3, Garbage Value, 9 6
SP Contest 3
Discuss it

 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();
}
```
 A Statement 2 B Statement 1 C Statement 3 & Statement 1 D None of the above
SP Contest 3
Discuss it

Question 10 Explanation:
https://www.geeksforgeeks.org/stack-set-4-evaluation-postfix-expression/
There are 10 questions to complete.
My Personal Notes arrow_drop_up