For a priority queue implemented using an ordered linked list, what is the…

2021

For a priority queue implemented using an ordered linked list, what is the worst-case time complexity of inserting a node at the position determined by its key?

Answer: D. O(n)ConceptA priority queue may use different representations. In an ordered linked list, insertion must first locate the key-based position; the link change…

  1. A.

    O(n log n)

  2. B.

    O(log n)

  3. C.

    O(n2)

  4. D.

    O(n)

  5. E.

    Question not attempted

Attempted by 509 students.

Show answer & explanation

Correct answer: D

Concept

A priority queue may use different representations. In an ordered linked list, insertion must first locate the key-based position; the link change itself is constant-time, but the search can span the list.

Application

  1. Start at the head and compare the new key with successive nodes while preserving priority order.

  2. In the worst case, the insertion point is at the end, so all n existing nodes are inspected.

  3. After the position is found, updating the neighboring links takes O(1) time.

Cross-check

  • Ordered linked list: a linear search dominates the constant-time link update.

  • Binary heap: insertion instead follows one root-to-leaf path and takes O(log n).

  • Unordered list: insertion can be O(1), with the search cost deferred to removal.

Result

Therefore, insertion into the stated ordered linked-list priority queue has worst-case time complexity O(n).

Explore the full course: Dsssb Tgt Computer Science Paper 2

Loading lesson…