Given the following array A 0 1 A 2 39 11 3 4 5 6 7 8 9 10 11 12 5 13 14 16 9 4 19 78 32 29 A) Build a Max heap for the given array. Show your work by drawing visual representations of the various binary trees, starting from the initial tree to the final one. Additionally, display the resulting array that represents the heap in the empty array down. 1 2 3 4 5 6 7 8 9 10 11 12 B) What is the array content after inserting the number (99) into the resulting array from part (A). 1 2 3 4 5 6 7 8 9 10 11 12 C) What is the array content after applying the Delete/Extract Max method to the array resulting from part (B)? 1 2 3 4 5 6 7 8 9 10 11 12 D) What is the time complexity of part (C)?
Added by Olga T.
Close
Step 1
Step 1: Building a Max heap for the given array A - Start with the given array A: [0, 1, 2, 11, 4, 13, 5, 14, 6, 7, 16, 9, 8, 4, 9, 19, 10, 78, 11, 32, 12, 29, 5] - Represent the array as a binary tree: ``` 0 / \ Show more…
Show all steps
Your feedback will help us improve your experience
Bibi Naikbakht and 83 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Consider a B+ tree for the following set of key values: (2, 3, 5, 7, 11, 17, 19, 23, 29, 31). Assume that the tree is initially empty and values are added in ascending order. The B+-trees for the cases where the number of pointers that will fit in one node is as follows: 1: Four (a) Show the form of the tree after inserting 9 (b) Show the form of the tree after (a) inserting 10 2: Six (a) Show the form of the tree after inserting 9 (b) Show the form of the tree after (a) inserting 10 Please draw the complete B+ trees for both question 1 and 2.
Bibi N.
2.4.2 Criticize the following idea: To implement finding the maximum in constant time, why not use a stack or a queue, but keep track of the maximum value inserted so far, then return that value for finding the maximum? (Don't confuse finding the max and removing the max) 2.4.4 Is an array that is sorted in decreasing order a max-oriented heap? 2.4.5 Give the heap that results when the keys E A S Y Q U E S T I O N are inserted in that order into an initially empty max-oriented heap. 2.4.9* Draw all of the different heaps that can be made from the five keys A B C D E, then draw all of the different heaps that can be made from the five keys A A A B B. (Draw min heaps.) 2.4.11 Suppose that your application will have a huge number of insert operations, but only a few remove the maximum operations. Which priority-queue implementation do you think would be most effective: heap, unordered array, or ordered array? (Also say why. Don't confuse finding the max and removing the max) 2.4.12 Suppose that your application will have a huge number of find the maximum operations, but a relatively small number of insert and remove the maximum operations. Which priority-queue implementation do you think would be most effective: heap, unordered array, or ordered array? (Also say why. Don't confuse finding the max and removing the max) 2.4.15* Design a linear-time certification algorithm to check whether an array pq[] is a min-oriented heap. (The method MinPQ.isMinHeap does this recursively. What would an iterative solution be? You should make sure you understand this and can do it without looking at MinPQ.isMinHeap.) 2.4.27* Find the minimum. Add a min() method to MaxPQ. Your implementation should use constant time and constant extra space. (Argue that your solution is constant time/space.)
Akash M.
All sorting should be done in ascending order: for example, 3, 7, 13, 16, 17,... A[0..11]: 25, 13, 38, 42, 7, 30, 3, 16, 29, 17, 55, 26 1. Build and show a binary search tree (BST) using array A[0..11]. You read the array left to right and fill the key in the tree starting from the root; in this case, 25 is the root. 2,3,4. Show pre-order, in-order, and post-order traversals of the BST built above 5. From the BST above, add nodes 11, 35, 45, and then remove 26, 16, 25 applying the BST insertion/deletion algorithms discussed in the class. Then show the final tree. 6. Show the immediate successor of the new root node in the BST applying the BST successor algorithms discussed in the class 7. We want to save the keys of a BST into an array. Then later we want to rebuild exactly the same BST by reading in the keys sequentially from the saved array. Describe a way to save the keys systematically. [Hint: think of a tree traversal and homework 5] 8. Why is the BST not considered the best solution for all cases? Give an example where BST can be as bad as a sorted array or linked list base tree? What's an alternative to it? 9. Can the BST tree in Q5 be a Red-Black BST tree? Verify your answer using four R-B tree properties. If it is an R-B tree, you only need to show a properly colored tree satisfying the R-B tree properties. If not an R-B tree, prove why it can't be an R-B tree. 10. Into the resulting tree of Q5, add 57 and 48. Then to balance the BST tree, perform RB-balancing operations as needed using recoloring and/or rotations as they get added. Draw a separate tree picture for each operation step.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD