Data Structure Questions and Answers-Stack using Array

YOU CAN DOWNLOAD 200+ SUBJECTS PDF BOOK FOR COMPETITIVE EXAMINATIONS

CLICK HERE TO DOWNLOAD

Data Structure Questions and Answers-Stack using Array

Question 6 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
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].
Question 6 Explanation: 
Elements are pushed at the end, hence N.

Question 7 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
What happens when you pop from an empty stack while implementing using the Stack ADT in Java?
A
Undefined error
B
Compiler displays a warning
C
EmptyStackException is thrown
D
NoStackException is thrown
Question 7 Explanation: 
The Stack ADT throws an EmptyStackException if the stack is empty and a pop() operation is tried on it.

Question 8 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
What is the functionality of the following piece of Java code?

Assume: 'a' is a non empty array of integers, the Stack class creates an array of specified size and provides a top pointer indicating TOS(top of stack), push and pop have normal meaning.

public void some....function(int[] a) { 	Stack S=new Stack(a.length); 	int[] b=new int[a.length]; 	for(int i=0;i<a.length;i++) 	{ 		S.push(a[i]); 	} 	for(int i=0;i<a.length;i++) 	{ 		b[i]=(int)(S.pop()); 	} 	System.out.println("output :"); 	for(int i=0;i<b.length;i++) 	{ 		System.out.println(b[i]); 	} }
A
print alternate elements of array
B
duplicate the given array
C
parentheses matching
D
reverse the array
Question 8 Explanation: 
Every element from the given array 'a' is pushed into the stack, and then the elements are popped out into the array 'b'. Stack is a LIFO structure, this results in reversing the given array.

Question 9 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
'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
all of the mentioned
Question 9 Explanation: 
You cannot modify the size of an array once the memory has been allocated, adding fewer elements than the array size would cause wastage of space, and adding more elements than the array size at run time would cause Stack Overflow.

Question 10 [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
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].
B
S[N].
C
S[N-2].
D
S[N+1].
Question 10 Explanation: 
Array indexing start from 0, hence N-1 is the last index.

There are 10 questions to complete.