Check if 2 tree nodes are related (ancestor/descendant) in O(1) with pre-processing

前端 未结 3 1134
北恋
北恋 2020-12-28 09:48

Check if 2 tree nodes are related (i.e. ancestor-descendant)

  • solve it in O(1) time, with O(N) space (N = # of nodes)
  • pre-processing is allowed
3条回答
  •  失恋的感觉
    2020-12-28 10:22

    if you consider a tree where a node in the tree has n/2 children (say), the running time of setting the labels will be as high as O(n*n). So this labeling scheme wont work ....

提交回复
热议问题