WEEK 8 2200

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/41

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 7:02 AM on 4/25/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

42 Terms

1
New cards

What is a priority queue?

A data structure that stores a collection of items, each represented as a pair (key, value).

2
New cards

What does the add(k, x) method do in a priority queue?

Inserts an item with key k and value x.

3
New cards

What is the purpose of the remove_min() method?

Removes and returns the item with the smallest key.

4
New cards

What does the min() method do?

Returns but does not remove the item with the smallest key.

5
New cards

What is the time complexity of add in an unsorted list implementation of a priority queue?

O(1)

6
New cards

What is the time complexity of remove_min in an unsorted list implementation?

O(n)

7
New cards

What is the time complexity of add in a sorted list implementation of a priority queue?

O(n)

8
New cards

What is the time complexity of remove_min in a sorted list implementation?

O(1)

9
New cards

What is a total order relation?

A mathematical concept that defines an order among arbitrary objects, satisfying reflective, antisymmetric, and transitive properties.

10
New cards

What is the reflective property of total order relations?

For any element x, x <= x.

11
New cards

What is the antisymmetric property of total order relations?

If x <= y and y <= x, then x = y.

12
New cards

What is the transitive property of total order relations?

If x <= y and y <= z, then x <= z.

13
New cards

How can a priority queue be used for sorting?

By inserting elements with add operations and then removing them in sorted order with remove_min operations.

14
New cards

What is the running time of selection sort using a priority queue?

O(n^2)

15
New cards

What is the running time of insertion sort using a priority queue?

O(n^2)

16
New cards

What is the difference between selection sort and insertion sort in terms of priority queue implementation?

Selection sort uses an unsorted sequence, while insertion sort uses a sorted sequence.

17
New cards

What are some applications of priority queues?

Standby flyers, auctions, stock market.

18
New cards

What does the is_empty() method do in a priority queue?

Checks if the priority queue is empty.

19
New cards

What does the len(P) method return?

The number of items in the priority queue P.

20
New cards

What is a heap?

A binary tree storing keys at its nodes that satisfies the heap order and complete binary tree properties.

21
New cards

What is the heap order property?

For every internal node v other than the root, key(v) >= key(parent(v)).

22
New cards

What is the height of a heap storing n keys?

O(log n).

23
New cards

How is the height of a heap proven?

By applying the complete binary tree property and showing that n >= 2^h.

24
New cards

How can heaps be used in data structures?

Heaps can be used to implement priority queues.

25
New cards

What are the steps for inserting a key into a heap?

Find the insertion node, store the key, and restore the heap order property.

26
New cards

What is the purpose of the upheap algorithm?

To restore the heap order property after inserting a new key.

27
New cards

When does upheap terminate?

When the key reaches the root or a node whose parent has a key smaller than or equal to it.

28
New cards

What are the steps for removing the root key from a heap?

Replace the root key with the last node's key, remove the last node, and restore the heap order property.

29
New cards

What is the purpose of the downheap algorithm?

To restore the heap order property after removing the root key.

30
New cards

When does downheap terminate?

When the key reaches a leaf or a node whose children have keys greater than or equal to it.

31
New cards

How can the last node in a heap be updated?

By traversing a path of O(log n) nodes to find the insertion node.

32
New cards

What is heap sort?

An algorithm that sorts a sequence of n elements in O(n log n) time using a heap-based priority queue.

33
New cards

What is the space complexity of a heap-based priority queue?

O(n).

34
New cards

How is a heap represented in an array?

For a node at rank i, the left child is at rank 2i + 1 and the right child at rank 2i + 2.

35
New cards

What happens when merging two heaps?

A new heap is created with a root node storing a key and the two heaps as subtrees, followed by downheap to restore order.

36
New cards

What is bottom-up heap construction?

A method to construct a heap storing n keys in log n phases by merging pairs of heaps.

37
New cards

What is the time complexity of bottom-up heap construction?

O(n).

38
New cards

Why is bottom-up heap construction faster than successive insertions?

It reduces the number of operations needed to build the heap compared to inserting each key one at a time.

39
New cards

What is the time complexity for the add and remove_min methods in a heap?

O(log n).

40
New cards

What is the time complexity for the len, is_empty, and min methods in a heap?

O(1).

41
New cards

What is the significance of the complete binary tree property in heaps?

It ensures that the heap is balanced, allowing efficient operations.

42
New cards

How does the number of nodes in a heap relate to its height?

The number of nodes is at least 2^h, where h is the height of the heap.