We present an approach to implement binary search trees in the rule-based graph programming language GP 2. Our implementation uses GP 2's rooted graph transformation rules to be fast and supports insertion, deletion and query operations. We argue that the worst-case runtime for each of the operations is O(n) for a tree with n nodes. In addition, we expect that, on average, the operations run in time O(log(n)). Hence the implementation would match the time complexity of binary search trees implementations in imperative languages.
翻译:我们提出了一种在基于规则的图编程语言GP 2中实现二叉搜索树的方法。我们的实现利用GP 2的有根图变换规则以达到快速执行,并支持插入、删除和查询操作。我们论证了对于包含n个节点的树,每个操作在最坏情况下的运行时间为O(n)。此外,我们预期在平均情况下,这些操作的运行时间为O(log(n))。因此,该实现的时间复杂度可与命令式语言中的二叉搜索树实现相匹配。