From ebe21f46ee0d6455886086e8c3f81b22f38400a0 Mon Sep 17 00:00:00 2001 From: remy Date: Mon, 8 Sep 2025 13:50:48 -0400 Subject: [PATCH] docs: add comprehensive content for two heaps algorithm pattern * Update two-heaps@MGb8ufztTK75aXAyEAuaf.md * Update two-heaps@MGb8ufztTK75aXAyEAuaf.md * Update two-heaps@MGb8ufztTK75aXAyEAuaf.md --- .../content/two-heaps@MGb8ufztTK75aXAyEAuaf.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/data/roadmaps/datastructures-and-algorithms/content/two-heaps@MGb8ufztTK75aXAyEAuaf.md b/src/data/roadmaps/datastructures-and-algorithms/content/two-heaps@MGb8ufztTK75aXAyEAuaf.md index ad376f711..616226267 100644 --- a/src/data/roadmaps/datastructures-and-algorithms/content/two-heaps@MGb8ufztTK75aXAyEAuaf.md +++ b/src/data/roadmaps/datastructures-and-algorithms/content/two-heaps@MGb8ufztTK75aXAyEAuaf.md @@ -1 +1,7 @@ -# Two Heaps \ No newline at end of file +# Two Heaps +The two heaps method uses a max-heap to store the lower half of the numbers and a min-heap to store the upper half. This setup allows you to quickly access the largest value of the lower half and the smallest value of the upper half in constant time. Insertions and deletions take logarithmic time, and the heaps are balanced so that the median can be found in O(1) time. This approach is especially useful for dynamically maintaining the median of a long or streaming data sequence, where repeatedly sorting the data would be inefficient (O(n log n) per sort). + +Learn more from the following resources: +- [@article@Two Heaps — A Coding Pattern for Median-finding (Emre Bolat)](https://emre.me/coding-patterns/two-heaps/) +- [@video@Coding Pattern - Two Heaps (Imran Sarwar)](https://www.youtube.com/watch?v=9P7W5aEaatQ) +