Amazon Interview Question
Software Engineer / DevelopersTeam: SDE
Country: India
Interview Type: In-Person
Heap should have the most wanted element in the top, and once it is removed the second most wanted element should be moved to the top.
Node is added at the leave and deleted from the root. So its a queue implementation. Sorting a queue based on some priority. Parent value should be less than the child's value based on this rule we can do upheaping(adding), or downheaping(deleting)
A max/min heap is a tree( need not be a binary tree) that satisfies the following properties:
1. Every leaf node is of height h or h-1.
2. Every leaf node of height h appears to the left of every leaf node of height h-1.
3. The value in each node is greater/smaller than or equal to those in it's children( if any).
I think you can explain in general how a binary heap tree works
- hello world February 02, 2012and then the tree's properties
1. Complete binary tree
2. Heap property ( values < root node or values > root node)