Skip to content

Commit

Permalink
add content for heap
Browse files Browse the repository at this point in the history
  • Loading branch information
jackyhuynh committed Nov 19, 2024
1 parent 2f920e5 commit 6e58c0e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions DataStructure/17_Heap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

The `heapify` function is used to maintain the heap property in a binary tree. It plays a crucial role in building max-heaps and min-heaps, which are fundamental structures for algorithms like heap sort.

- [Heap Sort Algorithm](https://algostructure.com/sorting/heapsort.php)

### `heapify` Function
`heapify` ensures that a subtree with a given node as the root satisfies the heap property. If the subtree violates the heap property, the function rearranges the nodes so that the subtree becomes a valid max-heap or min-heap.

Expand Down Expand Up @@ -57,6 +59,8 @@ For a min-heap, `heapify` ensures that each node is less than or equal to its ch
3. If the heap property is violated, swap the node with the largest (max-heap) or smallest (min-heap) of its children.
4. Recursively apply `heapify` to the affected subtree.

![heapify](./images/heapify.png)

### Visualizing the Max-Heap
Initial tree before heapifying:
```
Expand Down
Binary file added DataStructure/17_Heap/images/heapify.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6e58c0e

Please sign in to comment.