Algorithms Flashcards
What is an algorithm?
A finite sequence of step-by-step instructions carried out to solve a problem.
How do you complete a bubble sort?
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 do you complete a quick sort?
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 do you determine the lower bound for the number of bins needed?
Sum the heights of the boxes then divide by the bin size. Round up to the next integer.
How do you execute the first-fit bin packing algorithm?
- Take the items in the order given
- Place each item into the first available bin that can take it. Start from bin 1 each time.
What are the advantages and disadvantages of the first-fit bin packing algorithm?
Advantage: quick to implement
Disadvantage: not likely to lead to a good solution
How do you execute the first-fit decreasing bin packing algorithm?
- Sort the items so that they are in descending order
- Apply the first-fit algorithm to the reordered list
What are the advantages and disadvantages of the first-fit decreasing bin packing algorithm?
Advantages: usually get a good solution, easy to implement
Disadvantage: may not get an optimal solution
How do you execute the full-bin packing algorithm?
- Use observation to find combinations of items that will fill a bin. Pack these items first.
- Any remaining items are packed using the first-fit algorithm.
What are the advantages and disadvantages of the full-bin packing algorithm?
Advantage: usually get a good solution
Disadvantage: difficult to do, especially when the numbers are plentiful and awkward
What does the order of an algorithm tell you?
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).