Unit 4 Flashcards
Determine the median of the values in this list:
[23, 42, 1, 17, 24, 38, 15, 19]
21
What is quick select, and how does it differ from quick sort (in terms of approach and complexity)?
Quick select is a divide-and-conquer algorithm.
It uses the same overall approach as quick sort (choosing one item in a list as a pivot and partitioning the list into two based on that pivot, so that one partition has values that are less than the pivot and the other partition has values that are greater than or equal to the pivot).
However, instead of recursing into both partitions, as in quick sort, quick select only recurses into one partition – the one with the item that is being searched for. This reduces the average complexity from O(n log n) (in quick sort) to O(n) (in quick select).
Given an alphabet {A, C, G, T} and a target string {GACCTGCT}, calculate a shift table.
A = 7
C = 2
G = 3
T = 1
Given a string of {ABCCAB}, calculate its prefix table.
[0, 0, 0, 0, 1, 2]
How is data in a hash table stored?
Data in a hash table is stored in a number of slots.
What is mid-square an example of?
Mid-square is an example of a hash function.
Draw a tree showing the correct outcome when the numbers [22, 13, 10, 34, 12, 50] are inserted into an empty binary search tree in the given order.
Draw the updated AVL tree after the node with a key of 1 is deleted.
Complete the following table, regarding the attached trees:
Assuming a hash table with 23 slots, using the folding method, with 2 as the size of each part, what would be the hash value of the item 1459862903?
7
- Split the item 1459862903 into groups of two (14 59 86 29 03)
- Add these groups together, to give 191
- Divide this number by the number of slots - 191 / 23 = 8, with a remainder of 7
- The remainder is the hash value