I need a data structure that holds unique values (like a set), but also sorts them (like a priority queue) and allows random access for binary searching (like an array). Which type of data structure would fit these needs? I could live without the sorting (I can always sort it myself at the end)
Share
That sounds like a balanced binary tree, with a restriction of uniqueness in its insert operation, and implementing the
OS-SELECToperation (see: Introduction to Algorithms, chapter 14 in the 3rd edition) for retrieving an element given its rank (“index”) in O(lg n).The proposed data structure and augmented operations will allow you to: