Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is data structure based for set

In C++, map is based on a black-red tree, thus, insert/delete function will cost O(logn), and hash_map is based on a hash.

But I'm wandering that what data structure is set based?

Set is sorted as map does, so, is set also based on a black-red tree?

How its key and value stored in that tree?

And if so, what's data structure for unorder_set? Thanks!

like image 845
DoReMi Avatar asked Oct 30 '13 19:10

DoReMi


People also ask

What is a set data structure used for?

A Set data structure allows to add data to a container. A Set is a collection of objects or primitive types (strings, numbers or booleans), and you can think of it as a Map where values are used as map keys, with the map value always being a boolean true.

Is set a data type or data structure?

In computer science, a set is an abstract data type that can store unique values, without any particular order. It is a computer implementation of the mathematical concept of a finite set.

What is set representation in data structure?

Representation of Sets Sets can be represented in two ways, one is known as the Roster form and the other is famous as the Set-Builder form, these two forms can be used to represent the same data, just the style varies in both cases.


1 Answers

There's no guarantee. The only thing that the standard mandates is the cost of the operations, so implementers are free to use whatever data structures they want. Typically std::set and std::map are balanced binary trees.

Also, std::unordered_set and std::unordered_map are hash tables. This I believe is actually guaranteed by the standard because you are allowed to specify the hashing function manually.

like image 107
bstamour Avatar answered Oct 15 '22 12:10

bstamour