midterm Flashcards

1
Q

rehashing: when and how?

A

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)

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

in-place sorting algorithms

A

sorting algorithms that require no auxiliary arrays

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

main advantages open address hashing has over separate chaining (3)

A

no extra space for pointers, no extra time allocating nodes that make up each separate bucket, and easier spacial locating when rehashing

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

insertion sort over merge sort

A

insertion is good for small scale, mostly sorted

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

merge sort over insertion sort

A

merge sort is good for big and mostly sorted

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

selection sort over insertion sort

A

selection sort is good for not very sorted (swaps are gonna happen anyway better be good for something)

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

quick sort over merge sort

A

large elements, evenly distributed

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

merge sort over quick sort

A

mostly sorted already (the less swaps the better)

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

different ways to select a pivot (4)

A

median, first, last, or random

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

height of a recursion tree during divide and conquer

A

lg(n)

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

runtime of an algorithm depends on (4)

A

input size, processor speed, language, RAM

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

order of big oh notations from best to worst

A

O(1), O(lg(n)), O(n), O(nlg(n)), O(n^2), O(n^3), O(2^n), O(n!)

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

how many operations to find the max element in an unordered stack

A

the height of the stack

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

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

A

search all buckets -> O(n)
search all values in each bucket -> O(n)
O(n) + O(n) = O(n)

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

big O to make a stack empty that currently contains n/2 element. implemented as an array of size n

A

O(1) (make the top point to 0)

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

big O of selection sort (best, average, and worst case)

A

all O(n^2)

17
Q

big O of insertion sort (best, average, and worst case)

A

best: O(n), average & worst: O(n^2)

18
Q

big O of counting sort (best, average, and worst case)

A

all O(n)

19
Q

big O of merge sort (best, average, and worst case)

A

all O(nlgn)

20
Q

big O of quick sort (best, average, and worst case)

A

best: O(nlgn), average & worst: O(n^2)

21
Q

big O of binary search (best, average, and worst case)

A

best: O(1), average & worst: O(lgn) (recursion)

22
Q

binary search

A

(only in sorted arrays) find middle, check which side to go to, check middle of chosen side, continue until found

23
Q

big O of linear search (best, average, and worst case)

A

best: O(1), average & worst: O(n)

24
Q

load factor for linear probing hash table unsuccessful search

A

0.5(1 + 1/(1 + load_factor)^2)

25
Q

load factor for linear probing hash table successful search

A

0.5(1 + 1/(1 + load_factor))

26
Q

load factor for separate chaining hash table unsuccessful search

A

load_factor

27
Q

load factor for separate chaining hash table successful search

A

1 + load_factor/2