MCQOPTIONS
Saved Bookmarks
This section includes 13 Mcqs, each offering curated multiple-choice questions to sharpen your Data Structures and Algorithms knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
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] |
| Answer» B. S[N] | |
| 2. |
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 |
| Answer» B. user unable to give the input for stack operations | |
| 3. |
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. |
| A. | print alternate elements of array |
| B. | duplicate the given array |
| C. | parentheses matching |
| D. | reverse the arrayView Answer |
| Answer» E. | |
| 4. |
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 |
| Answer» D. NoStackException is thrown | |
| 5. |
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 |
| Answer» D. index out of bounds exception | |
| 6. |
What does the following function check for? (all necessary headers to be included and function is called from main) |
| A. | full stack |
| B. | invalid index |
| C. | empty stack |
| D. | infinite stackView Answer |
| Answer» D. infinite stackView Answer | |
| 7. |
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 |
| Answer» B. Compiler displays a warning | |
| 8. |
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]. |
| Answer» E. | |
| 9. |
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) |
| Answer» D. O(nlogn) | |
| 10. |
stack is full |
| A. | 20 |
| B. | 0 |
| C. | none of the mentioned |
| Answer» C. none of the mentioned | |
| 11. |
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 |
| Answer» E. | |
| 12. |
full stack |
| A. | invalid index |
| B. | empty stack |
| C. | infinite stack |
| Answer» D. | |
| 13. |
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 |
| Answer» B. people standing in a line to be serviced at a counter | |