Stack Using Array Questions and Answers
Stack Using Array Questions and Answers
25%
1. Which of the following real world scenarios would you associate with a stack data structure?
a) piling up of chairs one above the other
b) people standing in a line to be serviced at a counter
c) offer services based on the priority of the customer
d) tatkal Ticket Booking in IRCTC
View Answer
2. What does the following function check for? (all necessary headers to be included and function is
called from main)
#define MAX 10
a) full stack
b) invalid index
https://www.sanfoundry.com/data-structure-questions-answers-stack-array/ 1/8
28/11/2023, 09:26 Stack using Array Questions and Answers - Sanfoundry
c) empty stack
d) infinite stack
View Answer
advertisement
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
public Stack()
{
stk = new Object[CAPACITY];
}
https://www.sanfoundry.com/data-structure-questions-answers-stack-array/ 2/8
28/11/2023, 09:26 Stack using Array Questions and Answers - Sanfoundry
{
if(size_of_stack==size)
{
System.out.println("Stack overflow");
return;
}
else
{
top++;
stk[top]=item;
}
}
public Object pop()
{
if(top<0)
{
return -999;
}
else
{
Object ele=stk[top];
top--;
size_of_stack--;
return ele;
}
}
}
a) stack is full
b) 20
c) 0
d) -999
View Answer
advertisement
https://www.sanfoundry.com/data-structure-questions-answers-stack-array/ 3/8
28/11/2023, 09:26 Stack using Array Questions and Answers - Sanfoundry
5. What is the time complexity of pop() operation when the stack is implemented using an array?
a) O(1)
b) O(n)
c) O(logn)
d) O(nlogn)
View Answer
advertisement
6. Which of the following array position will be occupied by a new element being pushed for a stack
of size N elements(capacity of stack > N)?
a) S[N-1]
b) S[N]
c) S[1]
d) S[0]
View Answer
7. What happens when you pop from an empty stack while implementing using the Stack ADT in
Java?
https://www.sanfoundry.com/data-structure-questions-answers-stack-array/ 4/8
28/11/2023, 09:26 Stack using Array Questions and Answers - Sanfoundry
a) Undefined error
b) Compiler displays a warning
c) EmptyStackException is thrown
d) NoStackException is thrown
View Answer
9. Array implementation of Stack is not dynamic, which of the following statements supports this
argument?
a) space allocation for array is fixed and cannot be changed during run-time
b) user unable to give the input for stack operations
c) a runtime exception halts execution
d) improper program compilation
View Answer
10. Which of the following array element will return the top-of-the-stack-element for a stack of size
N elements(capacity of stack > N)?
a) S[N-1]
https://www.sanfoundry.com/data-structure-questions-answers-stack-array/ 5/8
28/11/2023, 09:26 Stack using Array Questions and Answers - Sanfoundry
b) S[N]
c) S[N-2]
d) S[N+1]
View Answer
To practice all areas of Data Structure, here is complete set of 1000+ Multiple Choice Questions and
Answers.
« Prev - Data Structure Questions and Answers » Next - Data Structure Questions and Answers –
– Circular Linked List Stack using Linked List
Related Posts:
advertisement
Recommended Articles:
https://www.sanfoundry.com/data-structure-questions-answers-stack-array/ 6/8
28/11/2023, 09:26 Stack using Array Questions and Answers - Sanfoundry
advertisement
Additional Resources:
Data Structure MCQ Questions
Data Structures in C
Data Structures in Java
Data Structures in C++
C# Array Programs
Popular Pages:
Java Array Programs
https://www.sanfoundry.com/data-structure-questions-answers-stack-array/ 7/8
28/11/2023, 09:26 Stack using Array Questions and Answers - Sanfoundry
C# Programs on Threads
Data Science MCQ Questions
C++ STL
C Programs on Recursion
Name
Subscribe
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is
Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on
development of Linux Kernel, SAN Technologies, Advanced C, Data
Structures & Alogrithms. Stay connected with him at LinkedIn.
https://www.sanfoundry.com/data-structure-questions-answers-stack-array/ 8/8