Stack Multiple choice Questions
- What is the main difference between a stack and a queue? A) Stacks have a first-in-first-out (FIFO) order, while queues have a last-in-first-out (LIFO) order. B) Stacks have a last-in-first-out (LIFO) order, while queues have a first-in-first-out (FIFO) order. C) Stacks have a random order, while queues have a sequential order. D) Stacks have a sequential order, while queues have a random order.
Answer: B) Stacks have a last-in-first-out (LIFO) order, while queues have a first-in-first-out (FIFO) order.
- What is the time complexity of pushing an element onto a stack? A) O(1) B) O(n) C) O(log n) D) O(n log n)
Answer: A) O(1)
- What is the time complexity of popping an element off a stack? A) O(1) B) O(n) C) O(log n) D) O(n log n)
Answer: A) O(1)
- What is the time complexity of checking if a stack is empty? A) O(1) B) O(n) C) O(log n) D) O(n log n)
Answer: A) O(1)
- What type of data structure can be used to implement a stack? A) Array B) Linked List C) Hash Table D) Binary Tree
Answer: A) Array or B) Linked List. Both arrays and linked lists can be used to implement a stack data structure.
Comments
Post a Comment