YogeshZT's blog

By YogeshZT, history, 13 months ago, In English

Hello, I was solving the question which involves finding Kth ancestor of a node in a tree using binary lifting. I was wondering if instead of binary lifting, is there something like n-ary lifting (n>2 ofc). Is it something which can be thought of and will it be more efficient?

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
13 months ago, # |
  Vote: I like it +3 Vote: I do not like it

N-ary lifting is somewhat useful only if you're trying to squeeze your solution into the tight memory limit

For example, if you take N = 4, you have to store two time less data relatively to the classic binary lifting (4th, 16th, 64th, ..., 4^kth ancestors): answering the query is basically the same except of some casework with small queries, which is doable in O(1)

Moreover, the same trick is applicable to the sparse table — same as in the binary lifting, it allows to trade some constant factor in time for some constant factor in memory