C++20 sections · 1024 units
Open in Course

Performance Tips

Choosing wisely

I'll explain when to prefer sets over sorted vectors. If you do many insertions and searches, set is better. For static data with many searches, sort once and use binary_search. You'll use partial_sort when you only need the top kk elements.

It's faster than full sort: O(nlogk)O(n \log k) versus O(nlogn)O(n \log n). For counting, maps give O(1)O(1) average time. Use algorithms when you need to operate on ranges.