Or

# Question

Problem 8. (Heap Top-k) Prof Dubious has made the following claim, and has provided a proof Claim. Let n and k be positive integers such that 2*-1n. In amax-heap H of n elements, the top 21 elements are in the first k layers of the heap. Proof. Since is a max-heap, each node in H must satisfy the heap property, i.e., if H, is an element of H with at least one child then Hmaxchldren(H)). We know that every subtree of the heap H is a heap, as subtrees of complete binary tro complete binary trees, and the heap property holds. Therefore since each subtree is a heap, the maximum element in each subtree must be at the root of that subtree Clearly, the largest element in H is at the root. Since the left and right subtrees are also heaps the next two largest elements must be at the root of each of these subtrees, i.e., the left and right child of the root Hence, the largest 22 - 1 3 elements of the heap lie in the first 2 layers. We repeatedly apply this argument to each subtree until we have considered the first k layers. Thus the largest 2k -1 elements in the heap must be in the first k layers. Briefly describe what is wrong with Professor Dubious's argument and provide a counter-example to their claim.
Problem 8. (Heap Top-k) Prof Dubious has made the following claim, and has provided a proof Claim. Let n and k be positive integers such that 2*-1n. In amax-heap H of n elements, the top 21 elements are in the first k layers of the heap. Proof. Since is a max-heap, each node in H must satisfy the heap property, i.e., if H, is an element of H with at least one child then Hmaxchldren(H)). We know that every subtree of the heap H is a heap, as subtrees of complete binary tro complete binary trees, and the heap property holds. Therefore since each subtree is a heap, the maximum element in each subtree must be at the root of that subtree Clearly, the largest element in H is at the root. Since the left and right subtrees are also heaps the next two largest elements must be at the root of each of these subtrees, i.e., the left and right child of the root Hence, the largest 22 - 1 3 elements of the heap lie in the first 2 layers. We repeatedly apply this argument to each subtree until we have considered the first k layers. Thus the largest 2k -1 elements in the heap must be in the first k layers. Briefly describe what is wrong with Professor Dubious's argument and provide a counter-example to their claim. Seen 1 years ago by 