Heap (Priority Queue) Patterns — DSA Pattern

The Heap (Priority Queue) Patterns pattern applies when you need top K elements, K-way merge, two heaps for median, and scheduling. Its time complexity is O(n log k) and space complexity O(k). It is used in 22 problems on Thita, including Finding MK Average, Find K Pairs with Smallest Sums and Find Median from Data Stream. Common variations are Two Heaps for Median Finding and Top K Elements (Selection/Frequency).

Master heap-based algorithms including top K elements, two heaps for median, K-way merge, and scheduling problems with priority queues.

Heap (Priority Queue) Patterns is pattern 9 of 16 in the Thita.ai DSA course. It covers top K elements, K-way merge, two heaps for median, and scheduling, split into 4 subpatterns and about 2 hours of study. It is one of the interview-critical patterns, so it is worth covering before your first onsite.

Subpatterns of Heap (Priority Queue) Patterns

Each subpattern below has its own theory page and problem set. They are listed in the order the course teaches them.

How to practise Heap (Priority Queue) Patterns on Thita.ai

Read the theory for a subpattern, then solve its problems in the browser editor. Your solution runs against the problem's test cases, and the AI coach gives a hint on the technique you are missing rather than the finished answer. Progress is tracked per subpattern, so the tracker shows which of the 4 Heap (Priority Queue) Patterns subpatterns you have covered. Topics covered here include heap, priority queue, top k elements, kth largest, k-way merge, two heaps median, min heap, max heap.

Related DSA patterns

Preparing this lesson and its course outline.