+ 1

Priority Queue Vs Vector

Hi I don't know how many values will be there and hence, I need to use vector. Also, All data required is sorted. With vector, time complexity of sorting is O(N*log N). What if I use priority queue and will get everything sorted. I just need to then pop all elements to traverse, but that looks fine to me. Given a choice, what should be best option among these two?

27th Dec 2022, 5:26 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
3 ответов
+ 3
Both have the same complexity of NlogN both will work
27th Dec 2022, 6:46 AM
YUGRAJ
+ 2
Input is from user 2*N values N is vector of int Another N is stored in vector of int Need to display user difference betwen two vector at respective index in sorted order Option 1 : Declare vector of N value Push values of each index as diff between corrosponding index of two input vectors Sort 3 vector and display to user in index 0 to N-1 Option 2: Instead of vector, store difference in priority queue. Print top element and pop. Continue till queue is not empty Which is best among 1 and 2 option ?
27th Dec 2022, 6:43 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 1
Can you explain what operations you are trying to do
27th Dec 2022, 5:38 AM
YUGRAJ