Question

    Which data structure is most suitable for implementing a priority queue?

    A Stack Correct Answer Incorrect Answer
    B Queue Correct Answer Incorrect Answer
    C Binary heap Correct Answer Incorrect Answer
    D Linked list Correct Answer Incorrect Answer
    E Array Correct Answer Incorrect Answer

    Solution

    A binary heap is the most suitable data structure for implementing a priority queue because it allows for efficient extraction of the highest or lowest priority element. The time complexity for inserting and extracting elements is O(log n), making it highly efficient. Why Other Options are Wrong: a) Stack follows LIFO (Last In First Out) and cannot manage priority efficiently. b) Queue follows FIFO (First In First Out) and doesn’t handle priority. d) Linked list has linear time complexity for extracting elements based on priority. e) Array requires scanning the entire list for priority, leading to inefficient operations.

    Practice Next