ch 6 priority queues (heaps) Flashcards

1
Q

binary heap

A

a binary tree that is completely filled with exception of the bottom level (complete binary tree)

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

locating child/parent

A

left child = 2i
right child = 2i + 1
i/2 = parent

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

heap order property

A

smallest element is the root

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

insert (percolate up)

A

first, make a hole in the next avalailable spot
if x can be placed in the spot without violating heap order, place it there
otherwise, find parent, place it there, and place x in the hole that the parent created

element is percolated up until correct location

O(logn)

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

deletemin (percolate down)

A

delete root
find the smallest of the children and insert into the hole
keep repeating

O(logn)

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

buildHeap

A

all items are inserted into the tree
first exam the subtrees on the very bottom. Do necessary percolate ups if there is a leaf that is larger than the parent
keep doing this for each level of the tree

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