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.
SIDE NOTE:
- 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).
- The method contains(Object) is used to check if a particular element is present in the queue, have leaner time complexity i.e. O(n).