Algorithms 2. Packing and Sorting Flashcards
What is a bin-packing problem?
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.
What is the first-fit algorithm?
You pack each box, in turn, into the first available bin into which it will fit.
What is the first-fit decreasing algorithm?
You Reorder the boxes from the largest to the smallest
Apply the first-fit algorithm to the reordered list of boxes
What is the full bin method?
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
Why is the full bin method not an algorithm?
it is ambiguous; there may be different ways of packing full bins.
What are the two algorithms not guaranteed to produce?
The two algorithms are not guaranteed to produce an optimal solution (which in this case means using the least number of bins).
What is a heuristic algorithm?
An algorithm which is usually efficient but may not produce an optimal solution is called a heuristic, or heuristic algorithm.
What complexity do first fit and first fit decreasing algorithm have?
First-fit and first-fit decreasing have quadratic complexity, O(n2), where n is the number of boxes.
How do you carry out the quick sort algorithm?
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.
What is worst case complexity for quick sort?
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.