Does Heavy Light Decomposition have any advantage over Binary Lifting Technique or using a sparse table? Can we solve some type of problem using HLD which can't be solved using the other mentioned techniques?

# | User | Rating |
---|---|---|

1 | tourist | 3434 |

2 | fateice | 3337 |

3 | Um_nik | 3292 |

4 | OO0OOO00O0OOO0O0…O | 3280 |

5 | Syloviaely | 3274 |

6 | Petr | 3223 |

7 | Swistakk | 3105 |

8 | mnbvmar | 3096 |

9 | yosupo | 3091 |

10 | dotorya | 3081 |

# | User | Contrib. |
---|---|---|

1 | rng_58 | 164 |

2 | tourist | 161 |

3 | csacademy | 153 |

4 | Petr | 150 |

5 | Swistakk | 148 |

6 | Um_nik | 144 |

7 | Nickolas | 142 |

7 | Vovuh | 142 |

9 | BledDest | 138 |

9 | PikMike | 138 |

9 | matthew99 | 138 |

9 | Errichto | 138 |

Does Heavy Light Decomposition have any advantage over Binary Lifting Technique or using a sparse table? Can we solve some type of problem using HLD which can't be solved using the other mentioned techniques?

↑

↓

Codeforces (c) Copyright 2010-2018 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Jul/20/2018 07:46:24 (d3).

Desktop version, switch to mobile version.

User lists

Name |
---|

Hld is useful when u are given some kind of non-invertible operation queries with updates. For example, consider the problem witht the following 2 queries:

Update the value of node X to Y

Say the GCD of the path u...v

Can this be done in some other way ?

Ah ok, so it should be used when we need to support update queries. That didn't strike me for some reason. Thanks!

Apart from update queries, ofc:

HLD:

O(N) preprocessing,O(logN) LCA query,O(N) memory.Binary lifting:

O(NlogN) preprocessing,O(logN) LCA query,O(NlogN) memory.Sparse table on DFS order:

O(NlogN) preprocessing,O(1) LCA query,O(NlogN) memory.Segment tree on DFS order:

O(N) preprocessing,O(logN) LCA query,O(N) memory.It's easy to see that HLD beats binary lifting by any means (except for simplicity which is actually quite important in CP), sparse table has a better query time but worse preprocessing time and memory complexity while segment tree gives you the same complexities. Not sure if the constant factor for querying segment tree is bigger than the one for LCA query in HLD but I guess so.

`HLD: O(N) preprocessing, O(logN) LCA query, O(N) memory.`

What do you mean by LCA query? LCA can be calculated in O(logN) irrespective of HLD/sparse tables, right?

Maybe I have misunderstood what you meant but if you mean query a given path using HLD, that can take

O(logN*logN)time, because you may encounter at mostlogNlight edges and for each light edge you will perform a query on the segment tree representing the heavy path above it.What I mean by LCA query is find the LCA of two nodes. You can do it with HLD, simply bringing one of the nodes to the next chain, depending on which one is deeper until they happen to be in the same chain.