Heaps Flashcards

1
Q

A special queue where the key with the highest priority is found at one end

Used to schedule jobs on a computer shared among multiple users

A

Priority queues

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

1) the higher the key,

A

the greater the priority

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

2) the key indicates

A

the execution time (lower is faster)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Implementation of priority queues using a linked list

A

insert – O(1)
delete min – O(n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Implementation of priority queues using a sorted linked list

A

insert – O(n)
delete min – O(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

An array that we can view as a nearly complete binary tree

A

(Binary) Heap

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

The tree is full on all levels except possibly

A

the bottom level (which is filled from left to right)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Each node of the tree is

A

an element of the array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

The number of elements in the heap stored in an attribute

A

Heap-size

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

If heap-size = 0,

A

heap is empty

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Given a heap represented by an array 𝐴, the root of the tree is at

A

𝐴[1]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

For any node at index 𝑖,
a. its parent is at

A

index i / 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

b. its left child is at

A

index 2𝑖

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

c. its right child is at

A

index 2𝑖 + 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

𝐴[𝑝𝑎𝑟𝑒𝑛𝑡(𝑖)] ≥ 𝐴[𝑖]

A

Max-heap

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

For every node other than the root, the value of a node is

A

at most, the value of its parent

17
Q

The largest value in a max-heap is at

A

the root

18
Q

𝐴[𝑝𝑎𝑟𝑒𝑛𝑡(𝑖)] ≤ 𝐴[𝑖]

A

Min-heap

19
Q

For every node other than the root, the value of a node is

A

at least, the value of its parent

20
Q

The smallest value in a min-heap is at

A

the root

21
Q

We insert at the next available location

A

Heap insertion

22
Q

Fixup: percolate up aka

A

Sift-up, float up, *min-heapify

23
Q

To delete the min/max,

A

1) swap it with the last key
2) subtract heap-size by 1
3) do a fixup from the root (percolate down)

24
Q

Converts an array into a min- / max-heap

Starting from index i / 2 down to 1, percolate down

A

Build min- / max-heap

25
Q

Using a heap for a priority queue,

A

insert – O(log n)
delete min/max – O(log n)
build-heap – O(n)

26
Q

A sorting algorithm that calls build-max-heap, then performs N-1 delete-max operations

A

Heapsort