Question

In: Computer Science

Does the order of arrival of data play a role in the pattern of data stored in a Heap?


Does the order of arrival of data play a role in the pattern of data stored in a Heap?

Solutions

Expert Solution

Yes of course because Heap can either be min heap or max heap. In min heap child of a parent node should be greater than their parents and in max heap the child of parent node will less than its parent node.

But as we know that Heap is a binary tree so it can have maximum two children i.e. the left child and the right child. So, both the children can be at any position and that will be decided by their order of arrival.

For example if we have 1,2,3 to insert in min heap then

1 will be parent because it is minimum.

2 will be left child of the node containing 1.

And 3 will be it's right child.

But if we insert in the sequence 1,3,2 then

1 will be at root node.

But now 3 will be at left child of it's parent i.e. node containing 1

And 2 will be it's right child.

Yes of course because Heap can either be min heap or max heap. In min heap child of a parent node should be greater than their parents and in max heap the child of parent node will less than its parent node.

But as we know that Heap is a binary tree so it can have maximum two children i.e. the left child and the right child. So, both the children can be at any position and that will be decided by their order of arrival.

For example if we have 1,2,3 to insert in min heap then

1 will be parent because it is minimum.

2 will be left child of the node containing 1.

And 3 will be it's right child.

But if we insert in the sequence 1,3,2 then

1 will be at root node.

But now 3 will be at left child of it's parent i.e. node containing 1

And 2 will be it's right child.

And we know Generally that the elements are stored in a memory in a level order manner i.e. level by level and from left to right so the location of elements in both above sequences will be different.

And we know Generally that the elements are stored in a memory in a level order manner i.e. level by level and from left to right so the location of elements in both above sequences will be different.


Related Solutions

What role does calcium play in this regulation, and where is it stored in a muscle fiber?
What role does calcium play in this regulation, and where is it stored in a muscle fiber?
What role does intuition play in decision making? What role does quantitative data play in decision...
What role does intuition play in decision making? What role does quantitative data play in decision making? Identify a decision situation in which you used both intuition and data for your analysis of the situation
What role does statistical data play in public health?
What role does statistical data play in public health?
Does social media play a role in advertising? If so, what role does it play?
Does social media play a role in advertising? If so, what role does it play?
What role does big data and cloud computing play in marketintelligence?
What role does big data and cloud computing play in market intelligence?
Does nature play a more significant role, or does nurture play a more significant role in...
Does nature play a more significant role, or does nurture play a more significant role in shaping human behavior? Or is it a combination of both?
what role does consumption play in shaping your sense of self? what role does it play...
what role does consumption play in shaping your sense of self? what role does it play in our society?
What role does personal conflict or politics play in the success of data governance?
What role does personal conflict or politics play in the success of data governance?
What role does phosphorus play?
What role does phosphorus play?
Q1. What role does the accounting department play (or what role should it play) in the...
Q1. What role does the accounting department play (or what role should it play) in the budgeting process? In the end, who is ultimately responsible for the budget, anyway? Instead of the president of the company, would it be more effective if the budgeting committee as a whole was responsible for the budget? Q2. Who should represent the various departments in the budget committee? What are the roles of these individuals?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT