堆VS二叉搜索树(BST)VS、BST

2023-09-11 01:49:00 作者:初遇

堆和BST之间的区别是什么?

What is the difference between a heap and BST?

在使用堆以及何时使用BST?

When to use a heap and when to use a BST?

如果你想在一个列表中的元素,是BST好了堆?

If you want to get the elements in a sorted fashion, is BST better over heap?

推荐答案

堆只是保证在较高的水平元素更高(最大堆)或小(最小堆),比上下级元素,而BST保障顺序(从左到右)。如果要排序的元素,去与BST。

Heap just guarantees that elements on higher levels are greater (for max-heap) or smaller (for min-heap) than elements on lower levels, whereas BST guarantees order (from "left" to "right"). If you want sorted elements, go with BST.