Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
4th Edition
ISBN: 9780134787961
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
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
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
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_forwardAssume the following list: 30, 45, 1, 26, 90, 5, 85, 35, 20, 41, 38, 72, 11, 33, 49 Using the function buildHeap as given in this chapter, convert the list into a heap. Show the resulting list after three passes of heapsort. (Use the heapify procedure as given in this chapter.) One pass:________________________________________________ Two passes:_______________________________________________ Three passes:______________________________________________ //---------buildHeap function-------------------- template <class elemType> void arrayListType<elemType>::buildHeap() { for (int index = length / 2 - 1; index >= 0; index--) heapify(index, length - 1); }//end buildheap //-----------heapify function------------------ template<class elemType> void arrayListType<elemType>::heapify(int low, int high) { int largeIndex; elemType temp = list[low]; //copy the root node of the subtree largeIndex = 2 * low + 1; //index of the left child while (largeIndex <= high)…arrow_forward4. 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_forward
- not handwrittenarrow_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_forwardPlease don't copy the solution from other websites. Assignment: For this week’s assignment, you’re going to be creating a Heap Sorter. It should be able to take input (using CIN), place it into proper Max Heap form in an array, and once it’s done accepting input, put the array in order using a Heap Sort. For the sake of simplicity, our heap trees will be made of an array that’s only seven elements long. Make sure to define your arrays ahead of time with garbage filler data before you start putting in your CIN data. Remember to use the binary heap traversal trick when dealing with your array-based tree. Please sort the following lists of inputs: 1.) 12, 40, 2, 6, 88, 90, 5 2.) 1, 2, 3, 4, 5, 6, 7 3.) 7, 6, 5, 4, 3, 2, 1 4.) 42, 64, 355, 113, 101, 13, 35 5.) 12, -5, 24, -4, 48, -3, 96arrow_forward
- Computer Science JAVA Write a program that maintains the names of your friends and relatives and thus serves as a friends list. You should be able to enter, delete, modify, or search this data. You should assume that the names are unique. use a class to represent the names in the friends list and another class to represent the friends list itself. This class should contain a Binary Search Tree of names as a data field. (TreeNode Class BinarySearchTree Class FriendsList Class)arrow_forwardDesign 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_forwardchar ** doubleIt (char **arr, int *maxsize); The doubleIt function will increase the heap size by doubling the original space. The functions takes 2 arguments: 1. A double pointer of type char called arr. This is a 2D dynamic array that contains words (strings) from the respective category (noun, verb, adjective, preposition). This is the original heap. 2. A pointer of type int called maxsize. This pointer holds the address of an integer that keeps track of the maximum amount of strings the 2D dynamic array can store. When this function is invoked, the current size of the dynamic array is at capacity so the values should match. This value will need to be multiplied by 2. The function allocates a new heap that is twice the size of the original heap and copy the values from the original heap into the new heap. One important note about this is that you have to properly copy the values over in order to avoid segmentation fault. Think about how this can be avoided. That is part of the…arrow_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_forwardList-Based Heap Implementations: The book starts out by discussing the concept of a priority queue and how to implement it conceptually. Then, the first implementation is presented: using an array or Python sequence to represent the heap. Data Storage: The book stores elements of a priority queue within a custom object (an _Item) which wraps and provides almost no support for the stored data. For this section, you will be storing your key and value as an ordered pair (or tuple) of two values where the first element is the key and the second element is the value. 1. What are the inherent benefits and drawbacks of this (array-based) backing representation? Discuss with respect to implementation, efficiency, and memory usage. (PI 1.2/ABET[1], PI 6.1/ABET[6])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