πŸ“’ Too many exams? Don’t know which one suits you best? Book Your Free Expert πŸ‘‰ call Now!

  • google app store apple app store
  • βœ–

      Question

      You are asked to implement a feature that requires

      storing unique items and quickly checking for the existence of an item. Which data structure would be the most efficient for this?
      A Array Correct Answer Incorrect Answer
      B Linked List Correct Answer Incorrect Answer
      C Stack Correct Answer Incorrect Answer
      D Set (e.g., HashSet in Java, set in Python) Correct Answer Incorrect Answer
      E Queue Correct Answer Incorrect Answer

      Solution

      A Set data structure is specifically designed to store unique elements and provides very efficient (average O(1)) operations for adding elements and checking for membership (existence). Arrays and linked lists would require O(N) for checking uniqueness, and stacks/queues are not suitable for this purpose.

      Practice Next
      ask-question