Midterm Flashcards

1
Q

Summarize Selection Sort

A

Best Case: (1/2)N^2
Average Case: (1/2)N^2
Worst Case: (1/2)N^2
Stability: No
In-Place: Yes
Improvement: None

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

Summarize Insertion Sort

A

Best Case: N
Average Case: (1/4)N^2
Worst Case: (1/2)N^2
Stability: Yes
In-Place: Yes
Improvement: Move Large Entries to the right one space rather than doing full exchanges
Advantage: Good for small arrays

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

Summarize Shell Sort

A

Best Case: Nlog_3(N)
Average Case: N/A
Worst Case: cN^(3/2)
Stability: No
In-Place: Yes
Improvement: N/A
Advantage: Good for very large arrays

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

Summarize Merge Sort

A

Best Case: (1/2)Nlog(N)
Average Case: Nlog(N)
Worst Case: Nlog(N)
Stability: Yes
In-Place: No
Improvement: Insertion Sort for Small Subarrays

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

Summarize Quick Sort

A

Best Case: Nlog(N)
Average Case: Nlog(N)
Worst Case: N^2
Stability: Yes
In-Place: Yes
Improvement: Cutoff to Insertion

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

How do you determine the time complexity relationship between two functions f and g?

A

take the limit of (f(n)/g(n)) as n goes to infinity. Let’s say that value is L
If L = 0 then f is in O(g(n)) if L = c where c is some constant then
f is in Theta(g(n)) if L = inf then f is in Omega(g(n))

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

What is the definition of O(g(n))?

A

O(g(n)) implies that there are positive constants m and n_0 for which
0 <= f(n) <= m*g(n) for n >= n_0

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

How do you implement a stack?

A

Page 148

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

How do you implement a queue?

A

Page 150

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

How do you implement a bag?

A

Page 154

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

How do you make something iterable?

A

Page 154

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

How do you implement selection sort?

A

Page 248

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

How do you trace selection sort?

A

Page 249

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

How do you implement insertion sort?

A

Page 250

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

How do you trace insertion sort?

A

Page 251

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

How do you implement shell sort?

A

Page 258

17
Q

How do you trace shell sort?

A

Page 256

18
Q

How do you implement top down merge?

A

Page 270, 274

19
Q

How do you trace top down merge?

A

Page 273

20
Q

How do you implement a bottom up merge?

A

Page 270, 277

21
Q

How do you trace a bottom up merge?

A

Page 278

22
Q

How do you implement quick sort?

A

Page 288, 290

23
Q

How do you trace quick sort?

A

Page 291

24
Q

What is the time complexity of union-find cases for n nodes?

A

Quick Find:
Constructor: n
Union: n
Find: 1
Quick Union:
Constructor: n
Union: Tree Height
Find: Tree Height
Weighted Quick Union:
Constructor: n
Union: log(n)
Find: log(n)