gpt4 book ai didi

algorithm - 二叉树的第一个共同祖先

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:12:25 26 4
gpt4 key购买 nike

如果我有一个这样的二叉搜索树,那么节点 6 和 1 的最低共同祖先是什么?

Binary Search tree

最佳答案

根据 Lowest common ancestor 的维基百科定义我纠正自己:

The lowest common ancestor (LCA) is a concept in graph theory and computer science. Let T be a rooted tree with n nodes. The lowest common ancestor is defined between two nodes v and w as the lowest node in T that has both v and w as descendants (where we allow a node to be a descendant of itself).

所以是的,根据这个定义,正确答案是 6。如果这是一个面试问题,最好提前与面试官澄清。

关于algorithm - 二叉树的第一个共同祖先,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10133332/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com