midterm Flashcards
rehashing: when and how?
when the table exceeds a certain load, double the table size and round up to the nearest prime number and refill via the hashing function
cost: O(N)
in-place sorting algorithms
sorting algorithms that require no auxiliary arrays
main advantages open address hashing has over separate chaining (3)
no extra space for pointers, no extra time allocating nodes that make up each separate bucket, and easier spacial locating when rehashing
insertion sort over merge sort
insertion is good for small scale, mostly sorted
merge sort over insertion sort
merge sort is good for big and mostly sorted
selection sort over insertion sort
selection sort is good for not very sorted (swaps are gonna happen anyway better be good for something)
quick sort over merge sort
large elements, evenly distributed
merge sort over quick sort
mostly sorted already (the less swaps the better)
different ways to select a pivot (4)
median, first, last, or random
height of a recursion tree during divide and conquer
lg(n)
runtime of an algorithm depends on (4)
input size, processor speed, language, RAM
order of big oh notations from best to worst
O(1), O(lg(n)), O(n), O(nlg(n)), O(n^2), O(n^3), O(2^n), O(n!)
how many operations to find the max element in an unordered stack
the height of the stack
big O of finding the minimum value in a hash table of size n, containing n elements where separate chaining is used and each bucket is unsorted
search all buckets -> O(n)
search all values in each bucket -> O(n)
O(n) + O(n) = O(n)
big O to make a stack empty that currently contains n/2 element. implemented as an array of size n
O(1) (make the top point to 0)