Data Structures Questions and Answers Part-2

1. Assuming int is of 4 bytes, what is the size of int arr[15];?
a) 15
b) 19
c) 11
d) 60

Answer: d
Explanation: Since there are 15 int elements and each int is of 4 bytes, we get 15*4 = 60 bytes.

2. In general, the index of the first element in an array is __________
a) 0
b) -1
c) 2
d) 1

Answer: a
Explanation: In general, Array Indexing starts from 0. Thus, the index of the first element in an array is 0.

3. Elements in an array are accessed _____________
a) randomly
b) sequentially
c) exponentially
d) logarithmically

Answer: a
Explanation: Elements in an array are accessed randomly. In Linked lists, elements are accessed sequentially.

4. Process of inserting an element in stack is called ____________
a) Create
b) Push
c) Evaluation
d) Pop

Answer: b
Explanation: Push operation allows users to insert elements in the stack. If the stack is filled completely and trying to perform push operation stack – overflow can happen.

5. Process of removing an element from stack is called __________
a) Create
b) Push
c) Evaluation
d) Pop

Answer: d
Explanation: Elements in the stack are removed using pop operation. Pop operation removes the top most element in the stack i.e. last entered element.

6. In a stack, if a user tries to remove an element from an empty stack it is called _________
a) Underflow
b) Empty collection
c) Overflow
d) Garbage Collection

Answer: a
Explanation: Underflow occurs when the user performs a pop operation on an empty stack. Overflow occurs when the stack is full and the user performs a push operation. Garbage Collection is used to recover the memory occupied by objects that are no longer used.

7. Pushing an element into stack already having five elements and stack size of 5, then stack becomes ___________
a) Overflow
b) Crash
c) Underflow
d) User flow

Answer: a
Explanation: The stack is filled with 5 elements and pushing one more element causes a stack overflow. This results in overwriting memory, code and loss of unsaved work on the computer.

8. Entries in a stack are “ordered”. What is the meaning of this statement?
a) A collection of stacks is sortable
b) Stack entries may be compared with the ‘<‘ operation
c) The entries are stored in a linked list
d) There is a Sequential entry that is one by one

Answer: d
Explanation: In stack data structure, elements are added one by one using push operation. Stack follows LIFO Principle i.e. Last In First Out(LIFO).

9. Which of the following is not the application of stack?
a) A parentheses balancing program
b) Tracking of local variables at run time
c) Compiler Syntax Analyzer
d) Data Transfer between two asynchronous process

Answer: d
Explanation: Data transfer between the two asynchronous process uses the queue data structure for synchronisation. The rest are all stack applications.

10. Consider the usual algorithm for determining whether a sequence of parentheses is balanced. The maximum number of parentheses that appear on the stack AT ANY ONE TIME when the algorithm analyzes: (()(())(()))?
a) 1
b) 2
c) 3
d) 4 or more

Answer: c
Explanation: In the entire parenthesis balancing method when the incoming token is a left parenthesis it is pushed into stack. A right parenthesis makes pop operation to delete the elements in stack till we get left parenthesis as top most element. 3 elements are there in stack before right parentheses comes. Therefore, maximum number of elements in stack at run time is 3.