1. Algorithms Flashcards

1
Q

What is an algorithm?

A

A finite sequence of step-by-step instructions carried out to solve a problem

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

Name 2 methods of sorting unordered lists

A
  1. Bubble Sort

2. Quick Sort

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

What are the steps to the bubble sort algorithm?

A
  1. Start at beginning of working list and move from left to right, comparing adjacent items
  2. If the two items are not in order, swap them
  3. If the two items are in order, leave them
  4. Once at the end of the working list, the last item is in its final position (no longer part of working list)
  5. If you had swaps in last pass, repeat steps 1-3
  6. If not, the list is sorted
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the steps to the quick sort algorithm to sort a list in ascending order?

A
  1. Choose item at midpoint of list (even-numbered list has a midpoint of item to the right of middle) to be the pivot point
  2. Write all items less than pivot point, keeping their order, as a sub-list
  3. Write down the pivot point
  4. Write remaining items after pivot point as sub-list
  5. Apply steps 1-4 to each sub-list
  6. Once all items have been chosen, the list is ordered
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the 3 bin-packing algorithms?

A
  1. First-fit
  2. First-fit decreasing
  3. Full-bin
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the state of the order of a list for the first-fit algorithm?

A

Items are in the order they are given

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

What is the state of the order of a list for the first-fit decreasing algorithm?

A

Requires the items to be in descending order before applying algorithm

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

What is the state of the order of a list for the full-bin algorithm?

A

Order does not matter

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

What are the steps to the first-fit algorithm?

A
  1. Take items in order they are given

2. Place each item in first available bin that can take it, starting from Bin 1 each time.

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

What are the steps to the first-fit decreasing algorithm?

A
  1. Sort items in descending items

2. Apply first-fit algorithm to this list

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

What are the steps to the full-bin algorithm?

A
  1. Use observation to find combinations of items that will fill a bin, packing these items first
  2. Any remaining items should be packed using first-fit algorithm
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the advantage and disadvantage of using first-fit algorithm?

A

Advantage: Quick to implement
Disadvantage: Unlikely to lead to good solution

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

What are the advantages and the disadvantage of using the first-fit decreasing algorithm?

A

Advantages: Easy to implement and usually get a fairly good solution
Disadvantage: May not get optimal solution

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

What is the advantage and disadvantage of using the full-bin algorithm?

A

Advantage: Usually get a good solution
Disadvantage: Difficult to do, esp. with many awkward numbers

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

What is the order of an algorithm?

A

A function of its size

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

If an algorithm has an order of f(n), what factor will the algorithm’s run time increase by if the size of the problem n to m?

A

f(m) / f(n)

17
Q

When the size of a problem is increased by a factor of k, how long does it take a linear order algorithm to complete?

A

k times as long

18
Q

When the size of a problem is increased by a factor of k, how long does it take a quadratic order algorithm to complete?

A

k squared times as long

19
Q

When the size of a problem is increased by a factor of k, how long does it take a cubic order algorithm to complete?

A

k cubed times as long