Algorithms 2. Packing and Sorting Flashcards

1
Q

What is a bin-packing problem?

A

A problem that packs ‘boxes’ of given sizes into a number of (equal sized) ‘bins’ of a fixed size. The boxes are in a given order and so are the bins.

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

What is the first-fit algorithm?

A

You pack each box, in turn, into the first available bin into which it will fit.

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

What is the first-fit decreasing algorithm?

A

You Reorder the boxes from the largest to the smallest

 Apply the first-fit algorithm to the reordered list of boxes

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

What is the full bin method?

A

You look for combinations of boxes which fill a bin and pack these boxes

 Put the rest of the boxes in combinations which come as close as possible to filling bins

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

Why is the full bin method not an algorithm?

A

it is ambiguous; there may be different ways of packing full bins.

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

What are the two algorithms not guaranteed to produce?

A

The two algorithms are not guaranteed to produce an optimal solution (which in this case means using the least number of bins).

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

What is a heuristic algorithm?

A

An algorithm which is usually efficient but may not produce an optimal solution is called a heuristic, or heuristic algorithm.

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

What complexity do first fit and first fit decreasing algorithm have?

A

First-fit and first-fit decreasing have quadratic complexity, O(n2), where n is the number of boxes.

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

How do you carry out the quick sort algorithm?

A

First pass
 The first value in the list is the pivot
 Rearrange the list as follows
o Go along the list, writing down each value which is less than or equal to the pivot
o Write down the pivot
o Go along the list writing down the values which are greater than the pivot.
o Underline the pivot to show it is in the correct place in the final sorted list.

Subsequent passes
 The previous pivot divides the new list into two sub-lists.

 Repeat the instructions for the first pass on these sub-lists.

Continue in this way until every value in the list is underlined to show it is in
the correct place.

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

What is worst case complexity for quick sort?

A

The worst-case complexity for quick sort is O(n2) where n is the number of numbers in the list to be sorted and you are counting the number of comparisons to be made. ‘Worst-case’ complexity means that you imagine that the maximum possible number of comparisons has to be made e.g. if the list is actually in reverse order.

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