![EBK STARTING OUT W/JAVA:...DATA...](https://www.bartleby.com/isbn_cover_images/9780134757179/9780134757179_largeCoverImage.gif)
EBK STARTING OUT W/JAVA:...DATA...
4th Edition
ISBN: 9780134757179
Author: GADDIS
Publisher: PEARSON CO
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 21, Problem 9MC
Program Description Answer
The number of comparisons made by this heapsort method is “O (n log n)” when it sorts the array with “n” values.
Hence, the correct answer is option “B”.
Expert Solution & Answer
![Check Mark](/static/check-mark.png)
Want to see the full answer?
Check out a sample textbook solution![Blurred answer](/static/blurred-answer.jpg)
Students have asked these similar questions
int[] 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 queue
Java program to return the third smallest element in the Binary Search Tree in O(n) time.
VERY IMPORTANT: The value of the third smallest element is ”3”. You may choose either a recursive or an iterative solution, but you are NOT allowed to maintain an extra array to store values of the tree elements for a linear scan later to return the required value. Also, you can’t just return 3 :)
int[] 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 heap
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
Similar questions
- JAVA Write a Java method named FillTree that can fill a Binary Search Tree using 10 words that areread from the user via the keyboard. The first two words should be your first name and last name.The other 8 words can be anything of your choice. The Binary Search Tree should come from themain method. The main method calls FillTree and pass it a Tree to be filled;arrow_forwardPython: Written without libraries method find_ansestors , that takes in an index i and returns all ancestors of node located at index i. What is the time complexity of your function? class ArrayBinaryTree: def __init__(self): self._heap = [] def find_ancestors(self, i: int): if(i==0): return;arrow_forwardThe implementation of a queue in an array, as given in this chapter, uses the variable count to determine whether the queue is empty or full. You can also use the variable count to return the number of elements in the queue. On the other hand, class linkedQueueType does not use such a variable to keep track of the number of elements in the queue. Redefine the class linkedQueueType by adding the variable count to keep track of the number of elements in the queue. Modify the definitions of the functions addQueue and deleteQueue as necessary. Add the function queueCount to return the number of elements in the queue. Also, write a program to test various operations of the class you defined.arrow_forward
- 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#.arrow_forwardCode: Number of Balanced BTsSend FeedbackGiven an integer h, find the possible number of balanced binary trees of height h. You just need to return the count of possible binary trees which are balanced.This number can be huge, so, return output modulus 10^9 + 7.Write a simple recursive solution.Input Format :The first and only line of input contains an integer, that denotes the value of h. Here, h is the height of the tree.Output Format :The first and only line of output contains the count of balanced binary trees modulus 10^9 + 7.Constraints :1 <= h <= 24Time Limit: 1 secSample Input 1:3Sample Output 1:15Sample Input 2:4Sample Output 2:315Solution:===========================================================================public class Solution {.arrow_forwardThe Java heapSort() method's first loop heapifies the list. One loop iteration occurs for each node with only 1 child node leaf node internal nodearrow_forward
- heap sort the list L ={D, B, G, E, A, H, C, F}.Writa all the steps with pseudecode.arrow_forwardHeap sort is considered: Select one: a. in place and stable b. in place and most efficient c. in place d. stable and most efficient e. stablearrow_forwardPython binary search tree: a function that takes in a root, p, and checks whether the tree rooted in p is a binary search tree or not. What is the time complexity of your function? def is_bst(self, p: Node):arrow_forward
- C++ DATA STRCUTURES AND ALGORITHMS Build a heap tree from the given information or values. 50 45 65 60 75 90 15 35 70 45 55arrow_forwardIN JAVA LANGUAGE FILL OUT THE FIND MAX FUNCTION public int findMax();/* Returns the largest element in the tree.* This method should call upon the recursive findMax_r() you write.** @return the largest element in the tree (an int value)* Example: findMax() will return 29 for the tree below** (28)* / \* (14) (29)* /* (1)*/ DO THIS BY CALLING A RECURSIVE FUNCTION SHOULD RETURN LARGEST ELEMENT IN A BST THANK YOU!!!!!arrow_forwardCreate a Binary Search Tree Class with the following four Operations using a single C++ program: Operations: 1. Insert(int n) : Add a node the tree with value n. Its O(lgn) 2. Find(int n) : Find a node the tree with value n. Its O(lgn) 3. Delete (int n) : Delete a node the tree with value n. Its O(lgn) 4. Display(): Prints the entire tree in increasing order. O(n).arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
![Text book image](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning