Question

Given an array representation of a heap, with indexes starting at 0. If a child node...

Given an array representation of a heap, with indexes starting at 0. If a child node is stored at index 50,
what index will contain its parent?

0 0
Add a comment Improve this question Transcribed image text
Answer #1
formula for index of parent is (child-1)/2
index of the parent is (50-1)/2 = 49/2 = 24

Answer: 24
index of the parent is 24
Add a comment
Know the answer?
Add Answer to:
Given an array representation of a heap, with indexes starting at 0. If a child node...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. Which of the following is a proper array representation a binary min heap?

    1. Which of the following is a proper array representation a binary min heap?2. A heap is implemented using an array. At what index will the right child of node at index i be found? Note, the Oth position of the array is not used.Select one:a. i/2b. 2 i+1c. i-1d. 2 i3. Consider the following array of length 6. Elements from the array are added, in the given order, to a max heap. The heap is initially empty and stored as an array.A={18,5,37,44,27,53}What...

  • 3. We begin by considering a 3-heap (a heap where each node has at most 3...

    3. We begin by considering a 3-heap (a heap where each node has at most 3 children) stored as an array. What are the indices of the parent and nth child of index k? That is, fill in the following mathematical functions. 20 pt parent(k)= child-o(k) = child-1(k)= child-2(k)= 4. Update the implementation for a minHeap delete Min given a 3-heap, include your Java code. 20 pts

  • Using a zero origin array representation for a heap, the heap element at index 100 would...

    Using a zero origin array representation for a heap, the heap element at index 100 would have a right child located at index: Answer Next page

  • Assume that a heap is implemented using an array called items where the root of the...

    Assume that a heap is implemented using an array called items where the root of the heap is stored in items[0]. Provide the mathematical proof of the following formulas that calculate the indices of the children and parent of any node items[i]. Left child of items[i] is items [2xi + 1] - Right child of items[i] is items [2xi + 2] Parent of items[i] is items[[(i-1)/2]]

  • 5. A three-heap with n elements can be stored in an array A, where A[O] contains...

    5. A three-heap with n elements can be stored in an array A, where A[O] contains the root of the tree. a) Draw the three-heap that results from inserting 5, 2, 8, 3, 6, 4, 9, 7, 1 in that order into an initially empty three-heap. You do not need to show the array representation of the heap. You are only required to show the final tree, although if you draw intermediate trees. b) Assuming that elements are placed in...

  • Min heap class implementation in Python. Implement a min-using an array. Your min-heap class will have...

    Min heap class implementation in Python. Implement a min-using an array. Your min-heap class will have one private attribute, an array of integers. Implement the following methods for the min-heap class You may not use the built-in min function. init - Constructor makes an empty heap str - Prints the heap out in any way you want for debugging only) makenull(self) - Makes the heap empty insert(self,x) - Insert element x into the heap parent(self,i) - Returns the index of...

  • A heap can be encoded either as an array, or as a full binary tree. For...

    A heap can be encoded either as an array, or as a full binary tree. For this question, write a function that takes the array representation of a heap and outputs its binary tree representation. More specifically, you should write a function with the specifications given below. Specifications for the function: # def arrayToTree(A, j): # input: array A representing a heap, an index j in [0:len(A)] # output: a Node object storing the heap with root j in the...

  • Discrete Math Max Heap After you build your heap, you then compare the values of the vertices, in the following way: If a child of a parent node is larger than the parent node, switch their posit...

    Discrete Math Max Heap After you build your heap, you then compare the values of the vertices, in the following way: If a child of a parent node is larger than the parent node, switch their positions. Using the list above, the following operations would take place: The parent of value 4 would swap with child of value 8. 1. 8 4 Now the parent value of 4 would swap places with the child value of 6. 2. 6 2...

  • Suppose that d ≥ 2 is an integer constant. In a d-ary tree, each node has...

    Suppose that d ≥ 2 is an integer constant. In a d-ary tree, each node has at most d nonempty subtrees. For example, the trees discussed along with heaps had d = 2. We can represent a nearly complete d-ary tree with n nodes using an array whose indexes range from 0 to n−1. (This is different from Cormen’s arrays, whose indexes range from 1 to n.)       Suppose that i is the index of a node in the array....

  • #ifndef HEAP_H_ #define HEAP_H_ namespace cse { template<typename dtype> class heap { public: /** TO DO::...

    #ifndef HEAP_H_ #define HEAP_H_ namespace cse { template<typename dtype> class heap { public: /** TO DO:: default constructor perform new to reserve memory of size INITIAL_CAPACITY. set num_items = 0; */ heap() { // write your code here }; /** Create a heap from a given array */ heap(dtype *other, size_t len) { // write your code here }; /** copy constructor copy another heap to this heap. */ heap(const heap<dtype> &other) { //write your code here }; /** Accessor...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT