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

How do you complete a bubble sort?

A

Compare adjacent items in a list:
- if they are in order, leave them
- if they are not in order, swap them
- the list is in order when a pass is completed without any swaps

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

How do you complete a quick sort?

A

Select a pivot then split the items into two sub-lists:
- one sub-list contains items less than the pivot
-the other sub-list contains items greater than the pivot
- select further pivots from within each sub list and repeat the process until all items have been chosen as pivots
- write “sort complete”

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

How do you determine the lower bound for the number of bins needed?

A

Sum the heights of the boxes then divide by the bin size. Round up to the next integer.

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

How do you execute the first-fit bin packing algorithm?

A
  1. Take the items in the order given
  2. Place each item into the first available bin that can take it. Start from bin 1 each time.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the advantages and disadvantages of the first-fit bin packing algorithm?

A

Advantage: quick to implement
Disadvantage: not likely to lead to a good solution

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

How do you execute the first-fit decreasing bin packing algorithm?

A
  1. Sort the items so that they are in descending order
  2. Apply the first-fit algorithm to the reordered list
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the advantages and disadvantages of the first-fit decreasing bin packing algorithm?

A

Advantages: usually get a good solution, easy to implement
Disadvantage: may not get an optimal solution

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

How do you execute the full-bin packing algorithm?

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

What are the advantages and disadvantages of the full-bin packing algorithm?

A

Advantage: usually get a good solution
Disadvantage: difficult to do, especially when the numbers are plentiful and awkward

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

What does the order of an algorithm tell you?

A

How changes in the size of a problem affect the approximate time taken for its completion.
If an algorithm has order f(n), then increasing the size of the problem from n to m will increase the run time of the algorithm by a factor of f(m)/f(n).

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