MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

DATA STRUCTURES

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
Consider the following operation performed on a stack of size 5.Push(1);Pop();Push(2);Push(3);Pop();Push(4);Pop();Pop();Push(5);After the completion of all operation, the number of elements present in stack are
A
1
B
2
C
3
D
4
Explanation: 

Detailed explanation-1: -Answer: Option A is correct. Hence, only one element is present in the stack which is 5. Thus finally only one element is is in stack i.e., 5.

Detailed explanation-2: -Push is a function in stack definition which is used to insert data at the stack’s top. Given below is the syntax of the push function in the stack. Pop is a function in the stack definition which is used to remove data from the stack’s top. Given below is the syntax of the pop function in the stack.

Detailed explanation-3: -What is the time complexity of pop() operation when the stack is implemented using an array? Explanation: pop() accesses only one end of the structure, and hence constant time.

Detailed explanation-4: -Basic Operations on Stack top() Returns the top element of the stack. isEmpty() returns true if stack is empty else false. size() returns the size of stack.

There is 1 question to complete.