Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More useful solution assuming ascending sort #338

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions C06-Heapsort/6.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ It must be in the leaf node.
Is an array that is in sorted order a min-heap?

### `Answer`
没有说明是递增数组还是递减数组,所以不一定.
如果假设按排序排序,则排序顺序是递增的,那么是的,因为对于被视为父节点的任何索引i,左子级子由(2 * i)给出,右子级子由(2 * i)给出+1。在排序数组中,这两个索引都将在父节点的右侧,因此更大或相等。因此,这满足了Heap属性,可以认为是最小堆.

We don't know whether it's an increasing order or descending order.
If you assume by sorted, that it is in increasing sorted order, then yes, because for any index i considered as a parent node, the left subchild is given by (2*i) and right subchild is given by (2*i)+1. In a sorted array, both these indices will be to the right of the parent node and therefore larger or equal. Therefore this satisfies the Heap property and it can be considered a min-heap.

### Exercises 6.1-6
***
Expand Down