Data Structure Questions and Answers-Stack using Array

DOWNLOAD FREE PDF <<CLICK HERE>>

Data Structure Questions and Answers-Stack using Array

Congratulations - you have completed Data Structure Questions and Answers-Stack using Array.

You scored %%SCORE%% out of %%TOTAL%%.

Your performance has been rated as %%RATING%%


Your answers are highlighted below.
Question 1 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER]
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
all of the mentioned
Question 1 Explanation: 
Stack follows Last In First Out(LIFO) policy. Piling up of chairs one above the other is based on LIFO, people standing in a line is a queue and if the service is based on priority, then it can be associated with a priority queue.

Question 2 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER]
What does the following function check for? (all necessary headers to be included and function is called from main)

 #define MAX 10 typedef struct stack { int top; 	int item[MAX]; }stack; int function(stack *s) { if(s->top == -1) 	 return 1; 	 else return 0; }
A
full stack
B
invalid index
C
empty stack
D
infinite stack
Question 2 Explanation: 
An empty stack is represented with the top-of-the-stack('top' in this case) to be equal to -1.

Question 3 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER]
What does 'stack underflow' refer to?
A
accessing item from an undefined stack
B
adding items to a full stack
C
removing items from an empty stack
D
index out of bounds exception
Question 3 Explanation: 
Removing items from an empty stack is termed as stack underflow.

Question 4 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER]
What is the output of the following program?

public class Stack { 	protected static final int CAPACITY = 100; 	protected int size, top = -1; 	protected Object stk[]; 	public Stack() 	{ 		stk = new Object[CAPACITY]; 	} 	public void push(Object item) 	{ 		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; 		} 	} } public class StackDemo { 	public static void main(String args[]) 	{ 		Stack myStack = new Stack(); 		myStack.push(10); 		Object element1 = myStack.pop(); 		Object element2 = myStack.pop(); 		System.out.println(element2); 	} }
A
stack is full
B
20
C
0
D
none of the mentioned
Question 4 Explanation: 
The first call to pop() returns 10, whereas the second call to pop() would result in stack underflow and the program returns -999.

Question 5 [CLICK ON ANY CHOICE TO KNOW MCQ multiple objective type questions RIGHT ANSWER]
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)
Question 5 Explanation: 
pop() accesses only one end of the structure, and hence constant time.

Once you are finished, click the button below. Any items you have not completed will be marked incorrect. Get Results
There are 5 questions to complete.