What is the time complexity of searching for an arbitrary element in an unsorted stack?

Options

  • A. O(1)
  • B. O(log n)
  • C. O(n)
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

C. O(n)

Detailed Explanation

Correct Answer: C. O(n)

Explanation: In the worst case, every element must be examined to find a particular element in an unsorted stack.

  • Searching may require checking all N elements.
  • Therefore, worst-case time complexity is O(n).
  • Push and pop operations at the top generally take O(1).