Sign in

Libre University uses your GitHub account. Signing in is only needed to sit a final test, so the score is kept on your profile.

Heaps and priority queues

1.[2p]

What is the heap property of a binary min-heap?

Correct
The answer is: Every node's key is no larger than both of its children's keys
The answer is: Every node's key is no larger than both of its children's keys
The answer is: Every node's key is no larger than both of its children's keys

2.[2p]

In an array-based heap indexed from 0, what is the index of the parent of index 40?

CorrectNot quite: 19

3.[2p]

What is the index of the right child of index 12?

CorrectNot quite: 26

4.[2p]

A heap needs balancing machinery to keep its height at log2n.

The answer is: False
Correct

5.[3p]

During sift-down, a node must be swapped with the smaller of its two children because

Correct
The answer is: swapping with the larger one would leave it above its smaller sibling, breaking the property at once
The answer is: swapping with the larger one would leave it above its smaller sibling, breaking the property at once
The answer is: swapping with the larger one would leave it above its smaller sibling, breaking the property at once

6.[3p]

Building a heap costs at most n2h0h/2h swaps. What does that sum h0h/2h converge to?

CorrectNot quite: 2

7.[3p]

Which of these are true of heapsort?

Select all that apply

Correct
Correct
Correct
The answer is: It sorts in place and is guaranteed $\Theta(n\log n)$, It makes about twice as many comparisons as mergesort, Its access pattern strides further with every level and misses the cache

8.[3p]

Finding the 100 largest of a billion items with a size-100 min-heap costs about nlog2k operations. Give that count in billions.

CorrectNot quite: 6.6

9.[3p]

Match each priority queue implementation to the cost of extracting the minimum.

  • Unsorted array

  • Sorted array

  • Binary heap

  • Balanced search tree

  • Θ(logn)

  • Θ(logn)

  • Θ(1)

  • Θ(n)

Show the answer

Unsorted array: Θ(n) Sorted array: Θ(1) Binary heap: Θ(logn) Balanced search tree: Θ(logn)