What is the complexity of st.erase(st.begin())?
# | User | Rating |
---|---|---|
1 | tourist | 3757 |
2 | jiangly | 3647 |
3 | Benq | 3581 |
4 | orzdevinwang | 3570 |
5 | Geothermal | 3569 |
5 | cnnfls_csy | 3569 |
7 | Radewoosh | 3509 |
8 | ecnerwala | 3486 |
9 | jqdai0815 | 3474 |
10 | gyh20 | 3447 |
# | User | Contrib. |
---|---|---|
1 | maomao90 | 171 |
2 | awoo | 165 |
3 | adamant | 163 |
4 | TheScrasse | 159 |
5 | maroonrk | 155 |
6 | nor | 154 |
7 | -is-this-fft- | 152 |
8 | Petr | 147 |
9 | orz | 146 |
10 | pajenegod | 145 |
What is the complexity of st.erase(st.begin())?
Name |
---|
It should be O(logn)
so this code will has O(NlogN), right? :>
If I understand correctly, inside the while cycle you are comparing a set to another set, which has roughly O(n^2) complexity
I used string
What
st
is? What cppreference tell about it?st is string
erase it's $$$O(|st|)$$$ then
For a set, the complexity would be O(logn)
Is
st
a set? If so, then it'sO(log n)
, but it seems like yourst
is a string, in which case it'sO(n)
.