EBK STARTING OUT W/JAVA:...DATA...
4th Edition
ISBN: 9780134757179
Author: GADDIS
Publisher: PEARSON CO
expand_more
expand_more
format_list_bulleted
Concept explainers
Expert Solution & Answer
Chapter 21, Problem 10MC
Program Description Answer
When an element is added to the heap, the new node is first added as a leaf node and then it shifts up if needed.
Hence, the correct answer is option “A”.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
There is an algorithm for making the heap complete:1. Remove the node at the root.2. Move the node in the last position to the root.3. Trickle the last node down until it is below.When this algorithm is applied continually, the data is removed from the heap in sorted order. Write the code for the Remove and TrickleDown methods in c#.
Heap Operation
1. pq.Enqueue(28);
2. pq.Enqueue(2);
3. pq.Enqueue(40);
4. pq.Dequeue(x);
5. pq.Dequeue(y);
6. pq.Dequeue(z);
56
27
42
26
15
3
19
Values x, y, z?
25
24
arrange the following data elements into a heap note - there will be more than one correct solution here; you simply have to show a correct arrangement. You have to draw the heap; you can not show it as an array or vector. Data Elements: 22 5 16 4 8 51 47 21 13 61 57 29 7
Chapter 21 Solutions
EBK STARTING OUT W/JAVA:...DATA...
Ch. 21.1 - Prob. 21.2CPCh. 21.1 - Prob. 21.3CPCh. 21 - Prob. 1MCCh. 21 - Prob. 2MCCh. 21 - Prob. 3MCCh. 21 - Prob. 4MCCh. 21 - Prob. 5MCCh. 21 - Prob. 6MCCh. 21 - Prob. 7MCCh. 21 - Prob. 8MC
Ch. 21 - Prob. 9MCCh. 21 - Prob. 10MCCh. 21 - Prob. 11TFCh. 21 - Prob. 12TFCh. 21 - Prob. 13TFCh. 21 - Prob. 14TFCh. 21 - Prob. 15TFCh. 21 - Prob. 16TFCh. 21 - Prob. 17TFCh. 21 - Prob. 18TFCh. 21 - Prob. 19TFCh. 21 - Prob. 20TFCh. 21 - Prob. 21TFCh. 21 - Prob. 1FTECh. 21 - Prob. 2FTECh. 21 - Prob. 3FTECh. 21 - Prob. 1SACh. 21 - Prob. 2SACh. 21 - Prob. 3SACh. 21 - Prob. 4SACh. 21 - What is a priority queue?Ch. 21 - Prob. 6SACh. 21 - Prob. 7SACh. 21 - Prob. 1AWCh. 21 - Prob. 2AWCh. 21 - Prob. 3AWCh. 21 - Prob. 4AWCh. 21 - Prob. 5AWCh. 21 - Prob. 6AWCh. 21 - Prob. 7AWCh. 21 - Prob. 4PCCh. 21 - Prob. 6PC
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Q2: Draw depending on this Binary Heap which called R. 1. Can you find where is the last and the next node? Draw IN BOTH WAYS (Explicit & Implicit). 2. Find-min(R). 3. Insert(R, 4)arrow_forwardCode The array below is used to store the values from a heap. What would be the content of the array after we remobe the minimum value. Codearrow_forwardCreate a data type that allows you to insert, delete the maximum, and delete the minimum (all in logarithmic time), as well as find the maximum and find the minimum (both in constant time). Tip: Use two heaps.arrow_forward
- 4. Draw a new heap that is created by inserting 52 into the following heap: 100 71 67 68 50 44 51 60 49 25 30arrow_forwardint[] sort();// Not quite a heap sort but almost.// This method should make a new array of elements to return, // and the elements in the new array should be the same values // that are in the heap, but in sorted order, smallest to largest.// Start the new returned array at slot 0, so in the returned array// slot 0 will have the smallest element from the heap... and// then up from there.//Min-heap example:// Suppose we have the following min-heap:// 3, 5, 4, 12, 6, 9// sort() would return an array containing 3,4,5,6,9,12. return a new array with the elements from the orignal array in asending order In java language create a method MUST USE A MIN HEAP no using priority queuearrow_forwardint[] sort();// Not quite a heap sort but almost.// This method should make a new array of elements to return, // and the elements in the new array should be the same values // that are in the heap, but in sorted order, smallest to largest.// Start the new returned array at slot 0, so in the returned array// slot 0 will have the smallest element from the heap... and// then up from there.//Min-heap example:// Suppose we have the following min-heap:// 3, 5, 4, 12, 6, 9// sort() would return an array containing 3,4,5,6,9,12. return a new array with the elements from the orignal array in asending order In java language create a method Using a min heaparrow_forward
- Design a data type that supports the following operations: insert, delete the maximum, and delete the minimum (all in logarithmic time); andfind the maximum and find the minimum (both in constant time). Hint: Use two heapsarrow_forwardIn PriorityQueue.java, write code for the following new functions:1. public boolean add( PriorityQueueNode x )This function adds a new node x to the priority queue. The node is added tothe heap by comparison of the rating attribute. It involves the “percolateup” process and returns true when finished. 2. public PriorityQueueNode remove( )This function removes the minimum element of the priority queue and returnsit. It involves a call to percolateDown( int hole ). 3. private void percolateDown( int hole )This function takes the position of the next available hole in the priority queueand uses it to bubble the elements through the heap until the heap property isrestored. 4. public void display( )This function prints out a formatted tree representation of the priority queueshowing only the rating of each node. The output should resemble that of atree. Tip: you may use the StringBuilder class and the Stringformat( ) method. Empty nodes in the tree can be replaced with “--”.Example output…arrow_forwardCreate a Student variable on the heap. Fill in the name and ID and print it out. Then, free the memory used by the variable. dynamic.cpp #include #include #include "debug_new.h" using namespace std; 1 2 3 4 5 struct Student { string name; long ID; }; 7 8 10 11 int main(int argc, char* argv[]) { Student* sp = 12 13 14 15 cout > ...; 19 cout << ... « ", ID: « endl; << ... 20 sp; ... 21arrow_forward
- Q2- Draw the following list of numbers as a heap with the first number as the root: 77, 66, 55, 44, 60, 33, 55. After that insert 40. Note: Method of Solution based on book (Object-Oriented Data Structures Using Java Dale. Daniel T. Joyce: Chip Weems)arrow_forwardQ1. Bottom-Up Min-Heapify For the following numbers, what is the resulting (1-indexed) heap after "min-heapifying" the input numbers (assume the input is an array/vector) in the bottom-up, O(n), manner. Input 5,2,6,9,3,4,7 (5 is the root at start).arrow_forwardQuestion 8 Look at the tree at the following, in what order are the numbers printed for an in-order traversal 9 17 13 root 53 14 me! 19 O The in-order traversal prints 14, 9, 17, 13, 53, 11, 19, 4, 7. O The in-order traversal prints 14, 9, 17, 13, 53, 11, 4, 19, 7. O The in-order traversal prints 9, 13, 17, 53, 14, 19, 4, 7, 11. Question 9 Tim Hannah 4 The in-order traversal prints 13, 9, 53, 17, 19, 7, 4, 11, 14. Mon 11 O The in-order traversal prints 14, 17, 9, 13, 53, 11, 4, 19, 7. 7 What statement is the most appropriate for the following tree? Granny Aunt Anne Susan Cousin Scott Harry O It is a complete tree that contains possible members of my family. The root is my mother's mother. Her children nodes contain her two daughters, and those nodes contain her children's children, and so on. O It is a tree that contains possible members of my family. The root is my mother's mother. Her children no contain her two daughters, and those nodes contain her children's children, and so on. O…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education