【发布时间】:2014-02-02 06:49:21
【问题描述】:
我想找到最有效的方法来检查二叉搜索树中具有最小值的节点。我现在不打算用某种编程语言来做,我只想考虑最有效的算法。
您对此有何看法:
procedure minBST(t)
if (t = NULL) then return;
if (t -> left = NULL) then return t -> inf;
*// if the left node is null, then in a BST the smallest value will be the root*
if (t -> left != NULL) then ....
*// I need to dig more in the left side until I get the last left node*
我的问题是我应该如何深入挖掘,直到我得到最后一个左节点。 我也试图解释这些步骤。你认为这是最好的方法吗?
【问题讨论】:
-
高效是什么意思。算法上,代码的详细程度,内存效率。最简单的方法是在途中最好地访问每个节点存储。见stackoverflow.com/questions/15306452/…。
-
效率 = 最小的复杂性。我已经看到了那个例子,但对我没有多大帮助。检查第一个左节点后,我需要了解如何深入。假设我有 10 个节点,我该怎么做?
标签: c++ c algorithm tree binary-search-tree