I know about the basics of priority queue, and I wonder can we add an element in the prority queue but after a certain value, as eg:- My array is 2, 5, 7, 11. I want to add 4 but after but after 5, the final array being: 2,5,4,7,11. Is there any other way to do it in O(logn) time?
Is there any other way to do it in O(logn) time?
It is not possible to insert into an arbitrary position of an array in logarithmic complexity.
It is possible to insert a value into a an array, and move elements around such that heap property is maintained in logarithmic complexity, but that doesn't necessarily result in the final array that you expect here.