Question

[12] 3. a) Draw the binary min-heap after inserting the following values, one after another. 21, 13, 12, 25, 4, 20, 16, 1, 11

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

(a)2 13 3 D 21 12 21 13 Heapify 13 12 21 113 2) 21 12 2) 13 4 25 5 4 12 4 12 Heapify 219 iz 13 13 2) 13 25 21 25 25 4 6 20 7 16

(b)MAXHEAPIFY(A , i)
{
    child1 = 4*i + 1;
    child2 = 4*i + 2;
    child3 = 4*i + 3;
    child4 = 4*i + 4;
    max = i;
    if (child1 < A.length && A[child1] > A[max])
        max = child1;
    if (child2 < A.length && A[child2] > A[max])
        max = child2;
    if (child3 < A.length && A[child3] > A[max])
        max = child3;
    if (child4 < A.length && A[child4] > A[max])
        max = child4;
    if (max != i)
    {
        swap(A[i], A[max]);
        MAXHEAPIFY(A , max)
    }
}

Add a comment
Know the answer?
Add Answer to:
[12] 3. a) Draw the binary min-heap after inserting the following values, one after another. 21,...
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
  • braw the binary min heap that results from inserting 8, 7, 3, 2, 4, 6, 9,...

    braw the binary min heap that results from inserting 8, 7, 3, 2, 4, 6, 9, 5, 1 in that order into an initially empty binary min hea p. Show final tree and the array representation of the heap. No need to show the intermediate work. 0 5 6 8 10 12 9. Consi der the binary heap shown below. What would the heap look like after deleteMin operation is performed? Show your work. 13 28 44 61 60 68...

  • 1.(10 pts) Contrast a heap with a binary search tree by inserting the numbers 60, 30,...

    1.(10 pts) Contrast a heap with a binary search tree by inserting the numbers 60, 30, 40, 50, 20, 10 first in a BST and then in a min-heap. Draw the resulting BST on the left and the heap on the right. You may draw any valid BST or Heap that contain the provided values 2. (5 pts) In section 11.1, the book mentions that heaps are **complete** binary trees, what does that mean? Demonstrate by drawing an example of...

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

  • 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

  • Trees and Heaps 1. Show that the maximum number of nodes in a binary tree of...

    Trees and Heaps 1. Show that the maximum number of nodes in a binary tree of height h is 2h+1 − 1. 2. A full node is a node with two children. Prove that the number of full nodes plus one is equal to the number of leaves in a nonempty binary tree. 3. What is the minimum number of nodes in an AVL tree of height 15? 4. Show the result of inserting 14, 12, 18, 20, 27, 16,...

  • 2) (5 pts) Consider inserting the following values into a min heap, in this order: 12,...

    2) (5 pts) Consider inserting the following values into a min heap, in this order: 12, 3, 19, 2, 1. Show the final locations for each value in the array storing the heap. (Recall that we store heaps in arrays using 1-based indexing and typically leave the 0 index blank.) Note: Only the answer will be graded for this question. 2 3 4 5 index value

  • 3. (8 points) Using the implementation of binary search tree operations we discussed in class, draw...

    3. (8 points) Using the implementation of binary search tree operations we discussed in class, draw the trees that result from the following operations: (a) Inserting 142, 400, 205, 127, 100, 320, 160, 141, and 110 into an initially-empty tree (in that order). (b) Deleting 142 from the tree you drew for part (a). 4. (8 points) Draw the unique binary tree that has a preorder traversal of 4, 1, 6, 3, 7, 5, 9, 2, 8 and an inorder...

  • Question 3. a. Draw the binary min heap represented by the following array: (5 points) 1...

    Question 3. a. Draw the binary min heap represented by the following array: (5 points) 1 2 4 6 7 Value 4 9 12 29 17 14 16 b. Show the result of calling deleteMin twice on the heap you drew in part (a). Show the heap after each deleteMin, and circle the final heap. (5 points) c. Starting with the heap you ended up with in part (b), insert values 11 & 2 in that order. Draw the heap...

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

  • Tree & Hash Table & Heap Use the following integer keys 73, 58, 91, 42, 60, 130, 64, 87 to perform the followings: a) Binary Search Tree - Draw a binary search tree - Retrieve the integers ke...

    Tree & Hash Table & Heap Use the following integer keys 73, 58, 91, 42, 60, 130, 64, 87 to perform the followings: a) Binary Search Tree - Draw a binary search tree - Retrieve the integers keys in post-order - Retrieve the integers keys in pre-order - Draw a binary search tree after node 58 is deleted b) Create a Hash Table using the methods described below. Show the final array after all integer keys are inserted. Assumes that...

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