What are a heap and a priority queue?

2 stars Asked often.

In one or two sentences
A heap is a complete binary tree in which every parent is larger (max heap) or smaller (min heap) than its children. It implements a priority queue that quickly returns the largest or smallest item.

Think of your own answer first

Say it out loud, or type it below. What you type never leaves this device.

Follow-up questions

These are likely next questions from an interviewer. Think of your answer first, then press the button.

  1. 1 / 3

    How long does it take to build a heap from an array?

Sources checked

This is a textbook level concept, so no outside source is listed.