From 4a1b6032c2bc7d3103443057f66b9f4a476f7ab9 Mon Sep 17 00:00:00 2001 From: Harikrishnan V Date: Wed, 5 May 2021 01:42:30 +0530 Subject: [PATCH] More useful solution assuming ascending sort I think this answer is more useful that just saying we don't know as we are able to prove that ascending sorted arrays are min heaps. Stackoverflow answer to verify correct answer - https://stackoverflow.com/questions/3113165/is-a-sorted-array-a-min-heap-whats-the-minimum-value-of-a-max-heap @gzc Please verify the chinese translation as I used google translate. --- C06-Heapsort/6.1.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/C06-Heapsort/6.1.md b/C06-Heapsort/6.1.md index d67acc45..bd7879e7 100644 --- a/C06-Heapsort/6.1.md +++ b/C06-Heapsort/6.1.md @@ -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 ***