Question

In: Computer Science

Data Structures and Algorithm Analysis in Java by Weiss: Exercise 6.8 Show the following regarding the...

Data Structures and Algorithm Analysis in Java by Weiss: Exercise 6.8

Show the following regarding the maximum item in the heap:

A) It must be at least one of the leaves.

B) There are exactly [N/2] leaves.

C) Every leaf must be examined to find it.

Solutions

Expert Solution

As per the heap order property ,min heap the value of each node is greater than or equal to value of its oarentwith minim value at the root.with this ,it can be proven that max element in heap should be at its leaf

B)

A complete tree of depth k has exactly (2^k+1) -1 nodes.

Now assume at depth k,up to level k-1 ,the tree is complete and has( 2^k) -1 nodes.

Each leaf on kth level will have a parent and parent will be at n-(2^k+1)+1/2 .I.e

Thus out of (2^k-1) nodes at k-1 level,[n-2^k+1/2]. Are aprenrs and the rest 2^(k-1) -[n-2^k+1/2] are leaves.

So the total no of leaves is n-2^k+1+2(k-1)- [n-2^k+1/2] which will be equal to N/2 leaves

Example:take a perfect tree of depth 2,it will have total of (2^k+1)-1=7nodes =N

Now calculate the leave nodes using above formula 7-2+1+2^0-[7-2^1+1/2] []-upper bound of value.=7-3=4 nodes which is upper bound of 7/2 i.e N/2

C)

If we want to add anode which is greater than the max element of the heap ,then the value which we want to insert will definitely end up at one of the leaves of heap or if we may need to insert any other number also we have to traveser the entire heap and then we can insert the element .thus every leaf must be examined to find out the max item.


Related Solutions

DATA STRUCTURES: For each algorithm, always explain how and why they work. If not by a...
DATA STRUCTURES: For each algorithm, always explain how and why they work. If not by a proof, at least by a clear explanation. ALWAYS, analyze the running time complexity of your algorithms. Do not write a program. Write pseudo codes or explain in words Q1: We want to maintain both a Queue and a Priority Queue. When you do Enqueue you also add the item to the Priority Queue and when you do Dequeue you also remove the item from...
In Java, Using ArrayList and HashSet data structures, as well as their methods, obtain following from...
In Java, Using ArrayList and HashSet data structures, as well as their methods, obtain following from some input text file: Total number of characters used,without counting spaces and punctuation, total number of words used; Number of words, counting each word only once; Total number of punctuation characters;Number of words that are of size six or more;Number of words that are used only once
The assignment: C++ program or Java You need to use the following programming constructs/data structures on...
The assignment: C++ program or Java You need to use the following programming constructs/data structures on this assignment. 1. A structure named student which contains:   a. int ID; student id; b. last name; // as either array of char or a string c. double GPA;    2. An input file containing the information of at least 10 students. 3. An array of struct: read the student information from the input file into the array. 4. A stack: you can use the...
Discuss the following processes/issues regarding qualitative data analysis: Preliminary processes to analysis and the manner in...
Discuss the following processes/issues regarding qualitative data analysis: Preliminary processes to analysis and the manner in which they best enhance qualitative data analysis.
The following data was collected from a global warming exercise regarding the time elapsed in months...
The following data was collected from a global warming exercise regarding the time elapsed in months between major floods attributed to global warming. Time Elapsed: 1,2,2,1,1,1,2,2,3,4,3,4,3,5,3,4,3,4,6,7,8,6,7,6,8,7,6,7,6,7,6,8,9,9,10,10,11,11,11,9,9,10,12,13,14,14,14,13, 13,12,12,15,15,16,16,17,17,16,18,19,20,20,21,23,23,19,19,11,13,12,24 Using the Method of Moments (MM) for a data fit investigation to a distribution i. Find an estimate for the Exponential distribution parameter. ii. Find estimators for Gamma distribution parameters. iii. Find estimators for Normal distribution parameters iv. Write down the log-likelihood function for the normal distribution (only in terms of the summation...
Please write a Java algorithm solving the following problem: Implement a Java method to check if...
Please write a Java algorithm solving the following problem: Implement a Java method to check if a binary tree is balanced. For this assignment, a balanced tree is defined to be a tree such that the heights of the two subtrees of any node never differ by more than one. 1. First, please create the following two classes supporting the Binary Tree Node and the Binary Tree: public class BinTreeNode<T> { private T key; private Object satelliteData; private BinTreeNode<T> parent;...
Using Java implement a searching algorithm to solve the following problem (please specify the searching algorithm...
Using Java implement a searching algorithm to solve the following problem (please specify the searching algorithm being used) Requirements Choose one problem with an algorithm and implement it. You should show and explain the result whatever you got. I recommend using N-Queen problem (at least N=8 or more) or any simple perfect games. For example, - N-Queen problem with hill climbing - N-Queen problem with simulated annealing - N-Queen problem with genetic algorithm - Tic-Tac-Toe with Minimax
Using Java implement a searching algorithm to solve the following problem (please specify the searching algorithm...
Using Java implement a searching algorithm to solve the following problem (please specify the searching algorithm being used) N-Queen problem with genetic algorithm Please use the N-Queen problem (at least N=8 or more) or any simple perfect games. Please provide a screenshot of output and please heavily comment the code. Thanks!
Which of the following statements are correct regarding the structures of myoglobin and haemoglobin and their...
Which of the following statements are correct regarding the structures of myoglobin and haemoglobin and their abilities to bind oxygen? Select one or more: a. When haemoglobin has two oxygen molecules bound, it effectively has a lower affinity for oxygen than when it has no oxygen molecules bound. b. Myoglobin and haemoglobin have very similar tertiary structures. c. Myoglobin and hemoglobin have very similar quaternary structures. d. Haemoglobin is a tighter oxygen binder than myoglobin because it has a different...
Please show solution and comments for this data structure using java.​ Implement a program in Java...
Please show solution and comments for this data structure using java.​ Implement a program in Java to convert an infix expression that includes (, ), +, -, *,     and / to postfix expression. For simplicity, your program will read from standard input (until the user enters the symbol “=”) an infix expression of single lower case and the operators +, -, /, *, and ( ), and output a postfix expression.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT