From bc6e1798227d9f7f1d867e7f9032fa53e5e60287 Mon Sep 17 00:00:00 2001 From: Elston Tan Date: Sun, 2 Oct 2022 20:12:40 +0800 Subject: [PATCH] Added heap definition and example (#41) --- Data Structures/readme.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Data Structures/readme.md b/Data Structures/readme.md index a102af6d..739f5390 100644 --- a/Data Structures/readme.md +++ b/Data Structures/readme.md @@ -123,4 +123,17 @@ Let hash function H(x) = [11,12,13,14,15] // it will be stored at positions {1,2,3,4,5} // in the array or Hash table respectively. ``` -[More on Hash Table](HashTable.md) \ No newline at end of file +[More on Hash Table](HashTable.md) + +## Heap + +A heap is a specialized tree-based data structure which is an almost complete tree that satisfies the heap property. The heap property means that the element with the greatest key is always in the root node such a heap is sometimes called a max-heap. + +### Example + +``` +Let array of numbers be [100, 7, 2, 17, 3, 25, 1, 36, 19] +// It will be in a tree-like form where the largest number will point to a smaller number and the smaller number points to an even smaller number and so on +``` +![Heap example](https://upload.wikimedia.org/wikipedia/commons/thumb/c/c4/Max-Heap-new.svg/1200px-Max-Heap-new.svg.png) +[More on Heap](Heap.md)