Heap is the best data structure to arrange your data in such a way that you can get the min/max in constant time. In sort this is all heap is used for.
Further there are many variations of Heap:
1) Min Heap
2) Max Heap
1) Min Heap:
With Min Heap at any point of time when you query the data structure you get the minimum item present in the list.
2) Max Heap:
With Max Heap at any point of time when you query the data structure you get the maximum item present in the list.
Off-course there are some work need to be done to have such a data structure which keep the record of max/min values even after having multiple insert and delete operations.
Then there are further variations of the Heap which could be:
1) Fixed length Heap
2) Dynamic length Heap
I would suggest you to go through https://github.com/sayrajat/java-ds and get the code of dynamic length Heap to have a better understanding of the concept.
To understand the basics of Heap this wiki link is best
https://en.wikipedia.org/wiki/Min-max_heap
Further there are many variations of Heap:
1) Min Heap
2) Max Heap
1) Min Heap:
With Min Heap at any point of time when you query the data structure you get the minimum item present in the list.
2) Max Heap:
With Max Heap at any point of time when you query the data structure you get the maximum item present in the list.
Off-course there are some work need to be done to have such a data structure which keep the record of max/min values even after having multiple insert and delete operations.
Then there are further variations of the Heap which could be:
1) Fixed length Heap
2) Dynamic length Heap
I would suggest you to go through https://github.com/sayrajat/java-ds and get the code of dynamic length Heap to have a better understanding of the concept.
To understand the basics of Heap this wiki link is best
https://en.wikipedia.org/wiki/Min-max_heap
No comments:
Post a Comment