1. Engineering
  2. Computer Science
  3. problem 2suppose we implement a dary heap in an array...

Question: problem 2suppose we implement a dary heap in an array...

Question details

Problem 2.Suppose we implement a d-ary heap in an array (see the book, d is a small integer, d 〉 2). Suppose we store the root item at index 0 of the array, its leftmost child at 1, its next child at 2, and so on. (The book likes to put the root at index 1, but we will put it at 0.) Suppose the heap stores n 2 1 items. 2(a). Suppose an item is at array index k. What is the index of its leftmost child? 2(b). Supposing k > 0, what is the index of its parent? 2(c). Suppose we want to start the first phase of heapsort (putting the given array into max-heap order). What is the largest index k, so that k has at least one child? 2(d). Give an exact formula for the tree height h, in terms of the size n. (Check your base cases: when n = 1 you should have h 0, and when 2 〈 n-d+ 1 you should have Remark: Each answer is just an integer-valued formula, you may need to round up or round down (like Lk/2] or 「h/2). You do not need to prove anything

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution