For example,

set < set<int> , less<set<int>> > K; 

How is K stored in memory? set is stored in memory in sorted form as a binary tree, and set <set <int>> in which?

  • 3
    And what do these numbers mean ?! set is saved in accordance with the implementation of set, that is, what algorithm is chosen to build the tree. - Vlad from Moscow
  • Well, for example, so set <set <int>, less <set <int >>> K; How is "K" stored in memory? - Taras
  • As an object of a class that has certain fields. To store items allocated dynamically. - Vlad from Moscow
  • @VladfromMoscow can issue as an answer (if you can add details)? - PashaPash
  • Please explain which aspect of keeping an object in memory interests you? - Cerbo

1 answer 1

Usually set<T> is implemented using binary search trees ( binary search tree, BST ). Searches, deletes, and inserts have an average complexity of O (log n) , and iteration is also supported.

In the case of nested sets set<set<T>> second-level sets are stored in the elements of the tree. Second level sets are sorted using the comparison operator < , which for sets is set as a lexicographical order .