What is Heap?
What is Heap?
A heap is a specialized tree-based data structure that satisfies the heap property. The heap property states that for a max-heap, the value of each node must be greater than or equal to the values of its children, while for a min-heap, the value of each node must be less than or equal to the values of its children.
There are two main types of heaps:
In a max-heap, the value of each node is greater than or equal to the values of its children. The root node, therefore, contains the maximum value in the heap.
In a min-heap, the value of each node is less than or equal to the values of its children. The root node, therefore, contains the minimum value in the heap.
Heaps are commonly implemented using an array, where the elements are stored level by level, from left to right. This allows for efficient insertion, deletion, and access of the ma...
entry
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào