Test 3 Flashcards
A __________ ___________ is a restricted form of a list. Items have priorities (or _____)
priority queuekeys
A priority queue removes items based on _________
priority
Unsorted list implementation store the items of the priority queue in a ____-_____, in arbitrary order
list-based
Unsorted list implementation example
4 - 5 - 2 - 3 - 1
Unsorted list implementation Performance: ____________ takes _____ time since we can insert the item at the beginning of the sequence
insertItemO(1)
Unsorted list implementation Performance: ___________, __________, and ___________ take ______ time since we have to traverse the entire sequence to find the smallest key
removeItem, min/maxKey, min/maxElementO(n)
Sorted list implementation store the items of the priority queue in a sequence, sorted by _____
key
Sorted list implementation example
1 - 2 - 3 - 4 - 5
Sorted list implementation Performance: __________ takes ______ time since we have to find the place where to insert the item
insertItemO(n)
Sorted list implementation Performance: ___________, __________, and ___________ take ______ time since the smallest key is at the beginning of the sequence
removeItem, min/maxKey, min/maxElementO(1)
Sorting Using a Priority Queue -given a ___________ of N items: a PQ can be used to sort the ___________:
sequencesequence
Sorting Using a Priority Queue -given a sequence of N items: a PQ can be used to sort the sequence: -Step 1: ___________…
Insert N items into the PQ via insertItem(key, data)
Sorting Using a Priority Queue -given a sequence of N items: a PQ can be used to sort the sequence: -Step 1: Insert N items into the PQ via insertItem(key, data) -Step 2: ___________…
Remove the items by calling removeItem() N times-the first remove removes the largest item, the second call the second largest, … the last removes the smallest item
Binary Search -uses a _________ and ___________ methodology
divideconquer
Binary Search -requires data to be ________
sorted
Binary Search -Runs in _______ time
O(lg n)
Binary Search -example of divide and conquer
looking up a word in a dictionary
Bubble Sort 1st run (5), (7), 2, 6, 9, 3 can’t switch 5 and 7 because 7 is larger 5, (7), (2), 6, 9, 3 then 7 and 2 5, 2, (7), (6), 9, 3 switch 7 and 2 because 7 is larger 5, 2, 6, (7), (9), 3 switch 7 and 6 5, 2, 6, 7, (3), (9) switch 9 and 3
the largest value has now bubbled to the end
Bubble Sort 2nd run (5), (2), 6, 7, 3, 9 2, (5), (6), 7, 3, 9 2, 5, (6), (7), 3, 9 2, 5, 6, (7), (3), 9 2, 5, 6, 3, (7), 9
the second largest value has now bubbled to the end
Complexity of bubble sort
n^2
Quicksort Algorithm 1. While data[___________] <= data[______] {++BiggerIndex; }
BiggerIndexpivot
Quicksort Algorithm 2. While data[___________] > data[_____] {–SmallerIndex; }
SmallerIndexpivot
Quicksort Algorithm 3. If ___________ < ____________ { swap data[BiggerIndex] and data[SmallerIndex] }
BiggerIndexSmallerIndex
Quicksort Algorithm 4. While SmallerIndex > BiggerIndex, go to 1
SmallerIndexBiggerIndex