What is time complexity for offer, poll and peek methods in priority queue Java ?

(Last Updated On: February 2, 2018)

Answer: Time complexity for the methods offer & poll is O(log(n)) and for the peek() it is Constant time O(1) of java priority queue.



  • In Java programming, Java Priority Queue is implemented using Heap Data Structures and Heap has O(log(n)) time complexity to insert and delete element.
  • Offer() and add() methods are used to insert the element in the in the priority queue java program.
  • Poll() and remove() is used to delete the element from the queue.
  • Element retrieval methods i.e. peek() and element(), that are used to retrieve elements from the head of the queue is constant time i.e. O(1).
  • contains(Object)method that is used to check if a particular element is present in the queue, have leaner time complexity i.e. O(n).