0

I have recently learned about small to large merging. https://usaco.guide/plat/merging?lang=cpp

So as an example problem, consider a rooted tree, where each vertex has color. For every vertex v, we are interested in determining the number of unique colors in its subtree.

I'm a java programmer, but many articles that implement small to large merging say that the complexity of it is n(logn)^2, this is because it takes time logn to insert in a c++ map. And each node requires to be transferred logn times from one map to another.

But, why don't folks use c++ unorded_map , since the complexity insert in it i O(1), there by reduce to total complexity to just nlogn, is it because unordered_map consumes more memory and we need to create a map for each of the n-nodes?

I tried using java hashmaps for https://www.hackerrank.com/challenges/coloring-tree/problem amd ot went through

0 Answers0