Question

Let T be a complete binary tree such that node v stores the entry (p(v), 0),...

Let T be a complete binary tree such that node v stores the entry (p(v), 0), where p(v) is the level number of v. Is tree T a heap? Why or why not?

I know that a complete binary tree is a heap, but shouldn't we also take into consideration the values that it is storing into the tree: (p(v), 0)? The heap tree could be either a min-heap or max-heap. If we order the the value based of p(v) which is the level number of v, then it would result in a min-heap since the higher numbers are at the bottom. However, if we order the value based of the 0, then this could be a max-heap, where the highest value is at the top. I guess in both cases it would result in a heap tree, but I'm wonder if we can store 2 numbers into the heap tree because most of the examples I see in the book have a variable and a number (A,5) to make it clear that the order of the tree is based of the number.

Homework Answers

Answer #1

Your query seems to be about what the nodes of the heap may contain. To know that you have to first know what a heap is used for. Usually there are two main puposes of a heap:

  1. In heap sort. Since in a heap, we have a specific order of the values in the node (children have either lower values or higher values than their parent depending on if we have max heap or min heap). This information can be used to keep extracting the root of the heap and fixing the heap (to replace the extracted root). The result is that we get the elements in a sorted order.
  2. As a priority queue. In this case, we order the nodes of the heap by priority. For example if every name that begins with M has higher priority than A which in turn has higher priority than T, then the root should have M, the child should have A and the subsequent child has T.

Obviously if only numbers are given and nothing is mentioned about priority order, then we assume that the max heap will have the highest number at the top.

Now think about the use of a priority queue. We have each node containing some amount of information and priority assigned to it. The highest priority is at the top. Children node have lower priority than parent node. Is there any real use of a "priority number/order" if there is no other information associated with the node? No. Rather we associate "priority number" to other information.

In fact, the following are also valid nodes for construction of a heap:

Names of the students in your class prioritized by their roll numbers.

Notice that the nodes above have a lot more information than just two fields.

The priority order doesn't need to be a number. It can be any entity as long as we can establish a order for it. As long as we know that entityX is lower than entityY, we can estasblish a priority order and create the heap.

In the example you gave in the question, we can assume that the priority order of the nodes of the tree can be established by "level number" and it will become a heap. You can also prioritize the nodes by the second field "0" and call it a heap.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Consider a binary search tree where each tree node v has a field v.sum which stores...
Consider a binary search tree where each tree node v has a field v.sum which stores the sum of all the keys in the subtree rooted at v. We wish to add an operation SumLE(K) to this binary search tree which returns the sum of all the keys in the tree whose values are less than or equal to K. (a) Describe an algorithm, SumLE(K), which returns the sum of all the keys in the tree whose values are less...
In this lab, you will write a program that creates a binary search tree based on...
In this lab, you will write a program that creates a binary search tree based on user input. Then, the user will indicate what order to print the values in. **Please write in C code** Start with the bst.h and bst.c base code provided to you. You will need to modify the source and header file to complete this lab. bst.h: #ifndef BST_H #define BST_H typedef struct BSTNode { int value; struct BSTNode* left; struct BSTNode* right; } BSTNode; BSTNode*...
The Binary Search Tree implementation for bst.zip. The code in the destructor of the BST class...
The Binary Search Tree implementation for bst.zip. The code in the destructor of the BST class is empty. Complete the destructor so the memory allocated for each node in the BST is freed. Make a couple of different trees in your main method or in a function to test the destructor (the program should not crash upon exiting). bst.zip (includes the following files below in c++): bst.h: #pragma once #include #include "node.cpp" using namespace std; template class BST { public:...
Create an add method for the BST (Binary Search Tree) class. add(self, new_value: object) -> None:...
Create an add method for the BST (Binary Search Tree) class. add(self, new_value: object) -> None: """This method adds new value to the tree, maintaining BST property. Duplicates must be allowed and placed in the right subtree.""" Example #1: tree = BST() print(tree) tree.add(10) tree.add(15) tree.add(5) print(tree) tree.add(15) tree.add(15) print(tree) tree.add(5) print(tree) Output: TREE in order { } TREE in order { 5, 10, 15 } TREE in order { 5, 10, 15, 15, 15 } TREE in order {...
1. Complete the PDF. x P(X = x) x · P(X = x) 0 0.1 1...
1. Complete the PDF. x P(X = x) x · P(X = x) 0 0.1 1 0.4 2 3 0.2 Part (a) Find the probability that X = 2. Part (b) Find the expected value. 2. A school newspaper reporter decides to randomly survey 16 students to see if they will attend Tet (Vietnamese New Year) festivities this year. Based on past years, she knows that 21% of students attend Tet festivities. We are interested in the number of students...
Complete the following activities and then post your responses in the Activity #5 discussion forum (link...
Complete the following activities and then post your responses in the Activity #5 discussion forum (link below). Consider a short multiple choice quiz with three items, and each item has four choices (only one of the choices is correct). Suppose that you are taking this quiz but you are completely and utterly unprepared for it. That means that you only option for the quiz is to guess the answers. Suppose you are thinking about the first item: what's the probability...
Relations and Functions Usual symbols for the above are; Relations: R1, R2, S, T, etc Functions:...
Relations and Functions Usual symbols for the above are; Relations: R1, R2, S, T, etc Functions: f, g, h, etc. But remember a function is a special kind of relation so it might turn out that a Relation, R, is a function, too. Relations To understand the symbolism better, let’s say the domain of a relation, R, is A = { a, b , c} and the Codomain is B = { 1,2,3,4}. Here is the relation: a R 1,    ...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code to initialize the CustomerAccountsDB database table and add a set of customer accounts is provided. Finish the code in these 3 methods in CustomerAccountDB.java to update or query the database: -purchase(double amountOfPurchase) -payment(double amountOfPayment) -getCustomerName() Hint: For getCustomerName(), look at the getAccountBalance() method to see an example of querying data from the database. For the purchase() and payment() methods, look at the addCustomerAccount() method...
Use python language please #One of the early common methods for encrypting text was the #Playfair...
Use python language please #One of the early common methods for encrypting text was the #Playfair cipher. You can read more about the Playfair cipher #here: https://en.wikipedia.org/wiki/Playfair_cipher # #The Playfair cipher starts with a 5x5 matrix of letters, #such as this one: # # D A V I O # Y N E R B # C F G H K # L M P Q S # T U W X Z # #To fit the 26-letter alphabet into...
I. Solve the following problem: For the following data: 1, 1, 2, 2, 3, 3, 3,...
I. Solve the following problem: For the following data: 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 5, 6 n = 12 b) Calculate 1) the average or average 2) quartile-1 3) quartile-2 or medium 4) quartile-3 5) Draw box diagram (Box & Wisker) II. PROBABILITY 1. Answer the questions using the following contingency table, which collects the results of a study to 400 customers of a store where you want to analyze the payment method. _______B__________BC_____ A...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT