Tag: binary tree

二进制搜索树遍历,比较两个指针的相等性

我正在阅读Cormen算法手册(二叉搜索树章节),它说有两种方法可以在没有递归的情况下遍历树: 使用堆栈和一个更复杂但更优雅的解决方案,它不使用堆栈,但假设可以测试两个指针的相等性 我已经实现了第一个选项(使用堆栈),但不知道如何实现后者。 这不是一个家庭作业,只是阅读教育自己。 有关如何在C#中实现第二个的任何线索?

在二叉搜索树中找到最低共同祖先

我有以下代码来找到最低的共同祖先(同时具有a和b作为后代的最低节点): public static Node LCA(Node root, Node a, Node b) { if (root == null) return null; if (root.IData == a.IData || root.IData == b.IData) return root; if (root.RightChild != null && (root.RightChild.IData == a.IData || root.RightChild.IData == b.IData)) return root; if (root.LeftChild != null && (root.LeftChild.IData == a.IData || root.LeftChild.IData == b.IData)) return root; […]

如何迭代地找到BST的高度?

public void HeightIterative() { int counter = 0; int counter2 = 0; TreeNode current=root; if(current != null) { while(current.LeftNode!=null) { counter++; current = current.LeftNode; } while(current.RightNode!=null) { counter2++; current = current.RightNode; } } int res = 1+Math.Max(counter, counter2); Console.WriteLine(“The Height Of Tree Is: “+res); } 我写了迭代方法,来计算树的高度。 但在某些情况下它不能正常工作。 如案例:10 1 2 3 4 5 18 17 […]

SortedDictionary是红黑树吗?

我在互联网上看到了几个关于此的引用,但没有官方文档? 谁能告诉我在哪里可以获得有关此信息?

代表树木的物体

C#(或.net)中是否有任何对象表示二叉树(或好奇心)和n-ary树? 我不是在谈论表示树控件,而是作为模型对象。 如果没有,是否有任何良好的外部实现?