Question

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 the array starting at location Al0], give expressions to calculate the left, middle, and right children of the element stored in Ai]: Left child: Middle child: Right child: Draw the array representation of your heap from part b. d) Removing Arbitrary Items From Heaps One way to remove an object from a binary min heap is to decrease its priority value by 1 and then call deleteMin. An alternative is to remove it from the heap, thus creating a hole, and then repair the heap. Write pseudocode for an algorithm that performs the remove operation using the alternative approach described above. Your pseudocode should implement the method call remove (int index), where index is the index into the heap array for the object to be removed. Your pseudocode can call the following methods described in lecture: insert, deleteMin, percolateUp, and percolateDown. Like in lecture, you may assume that objects are just priority integers (no other data). e) What is the worst case complexity of the algorithm you wrote in part (a)?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

s,a,e,3,6,4, 9, 9, 1 5 2- 3 주 규 Repre fentahon c) Fosmula- aj middle child. 81.t Riglit e

Add a comment
Know the answer?
Add Answer to:
5. A three-heap with n elements can be stored in an array A, where A[O] contains...
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
  • In the lectures, we studied binary heaps. A min-Heap can be visualized as a binary tree...

    In the lectures, we studied binary heaps. A min-Heap can be visualized as a binary tree of height with each node having at most two children with the property that value of a node is at most the value of its children. Such heap containing n elements can be represented (stored) as an array with the property Suppose that you would like to construct a & min Heap: each node has at most& children and the value of a node...

  • 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...

  • 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...

  • Consider the following max-heap stored as an array: <7, 6, 4, 2, 5, 1, 3>. Draw...

    Consider the following max-heap stored as an array: <7, 6, 4, 2, 5, 1, 3>. Draw this max-heap as an (undirected) binary tree and give both adjacency-list representation and adjacency-matrix representation of the binary tree

  • Consider the following complete binary tree is stored in an array the way we learned during...

    Consider the following complete binary tree is stored in an array the way we learned during heap lecture. The root node is stored at index 1. The last node (47) is stored at index heapsize. If you want to build a heap from the array using the heapify(), what position of the array you start doing percolate Down in heapify()? Answer: What is the run-time to build a heap from an array of size n using heapify() process ? OC...

  • 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...

  • 10 L 1 22 Given the function below, that divides the original array in two arrays...

    10 L 1 22 Given the function below, that divides the original array in two arrays of half size, develop the Java code that combines two sorted arrays or clearly explain how to implement the merge function. (3 points) nt middle values.Length/2; // divide array into two arrays of half size nt left- new int[middle]; or Cint i-e; imiddle; i+) t Leftri] - values[iJ: ntD right- new int[values. length-middle]: or Cint i-a; i<values.length-middle; i++) t rightli] -values [middle+i]; ort(left); //recursively...

  • SECTION B (4 QUESTIONS, 90 MARKS) Question 4. [32 marks in total] For this question, assume the definition of Java clas...

    SECTION B (4 QUESTIONS, 90 MARKS) Question 4. [32 marks in total] For this question, assume the definition of Java class Heap given in the Appendix. The heaps referred to in this question are all maxHeaps. a. (5 marks) Insert into an empty (binary) heap the values 35, 4, 72, 36, 49, 50. Draw all intermediate steps b. (3 marks) Carry out one deletion operation on the final heap in (a.) above. c. (2 marks) Give the worst-case time complexity...

  • I need help In the lecture you got acquainted with the median algorithm, which calculates the median of an unsorted array with n∈N elements in O (n). But the algorithm can actually do much more: it is...

    I need help In the lecture you got acquainted with the median algorithm, which calculates the median of an unsorted array with n∈N elements in O (n). But the algorithm can actually do much more: it is not limited to finding only the median, but can generally find the ith element with 0≤i <n. Implement this generic version of the median algorithm by creating a class selector in the ads.set2.select package and implementing the following method: /** * Returns the...

  • Write a second constructor that could be added to the HeapPriorityQueue class. This constructor accepts an...

    Write a second constructor that could be added to the HeapPriorityQueue class. This constructor accepts an array of elements as a parameter and uses that array as the heap rather than creating a new array. Of course, the array passed in is probably not in proper heap ordering, so you must rearrange it until it is. There's a neat trick for achieving this: If you just "bubble down" all of the non-leaf nodes of the heap, starting from the last...

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