Dannypa's blog

By Dannypa, history, 6 weeks ago, translation,

Hi! I am in search for problems that can be solved using the following technique: if we need to merge two sets in dfs, we put elements of the larger one into the smaller one, and in total asymptotics is $O(nlogn)$. If anyone knows of this kind of problems, i would be very grateful if you post some in the comments.

• +4

 » 6 weeks ago, # |   0 Auto comment: topic has been translated by Dannypa (original revision, translated revision, compare)
 » 6 weeks ago, # |   -8 You can see the "dsu"-taged problems.
•  » » 6 weeks ago, # ^ |   +14 Thanks for narrowing the search space down to a couple hundreds
 » 6 weeks ago, # |   -20 If your "set" means std::set or any self balancing tree, the total time complexity is $\mathcal{O}(n\log^2n)$, not $\mathcal{O}(n\log n)$.
•  » » 6 weeks ago, # ^ |   +1 Why the downvotes smh
 » 6 weeks ago, # |   +19 The technique is called "small to large" you will find some problems here
•  » » 6 weeks ago, # ^ |   +1 I thnk OP also meant small to large but just to be clear, the complexity is actually $\mathcal{O}(nlog^2n)$
•  » » » 5 weeks ago, # ^ |   +1 There are many ways to store a set. One of them is std::unordered_set, which has $O(1)$ insertion and $O(size)$ traversal, which yields $O(n\log n)$ total time for some problems. So, the "small to large" idea is not tied to a certain complexity.Also, sometimes we are allowed to store duplicates (or we can prove that there are no duplicates). Then, we can store sets in linked lists and merge two of them in just $O(1)$. This wouldn't require "small to large" then, but I've seen at least one problem in this comment section, which can be solved this way.
•  » » 6 weeks ago, # ^ |   0 Thanks!
•  » » 6 weeks ago, # ^ |   +1 Great! This list is helpful.Can you share more lists of other topics? would be more helpful :)
•  » » » 5 weeks ago, # ^ |   0 linkcredits: Abdelrhman_Akram
 » 6 weeks ago, # |   +22
 » 6 weeks ago, # |   +3