complexity of set::insert

后端 未结 1 1075
情歌与酒
情歌与酒 2020-12-29 06:16

I have read that insert operation in a set takes only log(n) time. How is that possible?

To insert, first we have find the location in the sorted array where the new

相关标签:
1条回答
  • 2020-12-29 07:00

    std::set is commonly implemented as a red-black binary search tree. Insertion on this data structure has a worst-case of O(log(n)) complexity, as the tree is kept balanced.

    0 讨论(0)
提交回复
热议问题