I am very confused about this concept.. now it's all cleared my doubts .. thank you
@programmingforbeginners73925 ай бұрын
Glad to hear that
@MahaDev-cx1ij5 ай бұрын
Very impressive and wow presentation
@programmingforbeginners73925 ай бұрын
Thank you 😊
@paarthiban8452 Жыл бұрын
At last I understood the algorithm behind the priority queue...really nice work buddy.👌
@programmingforbeginners7392 Жыл бұрын
Thank you so much.. please share with your friends and subscribe to the channel 🙂👍
@jeyanthan360 Жыл бұрын
For a capacity-constrained queue, the difference between add() and offer() methods are, add() always returns true and throws an exception if it can't add the element, whereas offer() is allowed to return false if it can't add the element.
@thesquarefish Жыл бұрын
Don't know if you'll see this message but why would anyone use add() over offer() if add() might error and offer() won't?
@jeyanthan360 Жыл бұрын
@@thesquarefish if you know that the queue has enough capacity to hold the element you want to add, it is generally better to use the add() method. On the other hand, if you are not sure whether the queue has enough capacity or not, or if you want to handle queue overflow gracefully, you can use the offer() method. And actually add() method was created first . After sometimes, from the problem faced by the add() ,offer() has been created. So most text books are using the old methods as an example for adding elements in a priority queue, these youtube videos are also teaching in traditional bookish way. But offer() is good compared to add() we can use that too, totally our choice.
@thesquarefish Жыл бұрын
@@jeyanthan360 But from a purely functional standpoint, offer() is always equal to or better than add()?
@jeyanthan360 Жыл бұрын
@@thesquarefish Yessss u r Right
@thesquarefish Жыл бұрын
@@jeyanthan360 Ok thank u for answering
@ACUCSPRADEEPB-up9ne2 жыл бұрын
Wow 👍
@programmingforbeginners73922 жыл бұрын
Thanks 👍
@nishikantmandaokar9353 Жыл бұрын
You r good.. but lil bit more knowledge is there then it will be good
@programmingforbeginners7392 Жыл бұрын
Ok
@2412Anand2 ай бұрын
why it is 1 3 2 4 why not 1 2 3 4
@ankitkulhade94102 ай бұрын
When you print the PriorityQueue directly using System.out.println(pq);, it does not sort the elements for display. The order you see is simply how the elements are organized in the heap. Therefore, the output may look like [1, 3, 2, 11, 21, 14, 4, 31], which does not represent a sorted order. Continuously poll elements from the PriorityQueue until it's empty. This will give you the elements in sorted order: