• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

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

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

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

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));
	}
}
  • 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

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

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.

Question 7

Consider the below C program: C
int main()
{
    fork();
    fork();
    fork();
    
    printf(\"Hello World\");
}
How many child processes will be created when the above program executes?
  • 4
  • 5
  • 6
  • 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.
  • 1, 2
  • 3, 4
  • 1, 4
  • 1, 3

Question 9

What will be the output of below C++ Program?
CPP
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;
}
  • 3
  • Error
  • 3, Hello World!, 9 6
  • 3, Garbage Value, 9 6

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
// 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

There are 10 questions to complete.

Last Updated :
Take a part in the ongoing discussion