Decision 1 Chapter 1 - Algorithms Flashcards
Flow chart syntax - Start / End
Box with rounded edges
Flow chart syntax - Instruction
Rectangle
Flow chart syntax - Decision
Diamond
Two arrows coming from it with “yes” and “no”
Bubble sort algorithm
1 - Starting at he beginning of the list pass through and compare adjacent values. For each pair:
- If in order leave
- If not in order swap
2 - When at the end of the list repeat step 1
3 - When a pass is completed without any swaps the list is in order
Quick sort algorithm
1 - Choose the item at the middle of the list to be the pivot (if the list has an even length the item to the right of the middle)
2 - Write down all the numbers less than the pivot, keeping their order, in a sub list
3- Write down the pivot
4- Write down the remaining items in a sub list
5 - Apply steps 1-4 to each sub list recursively
6 - When all items are pivots, stop
Binary search algorithm
1 - Select the middle item in the list
2 - If it is the target the search is complete
3 - If the item is larger than the target delete the second half of the list including the selected item
4 - If the item is smaller than the target delete the first half of the list including the selected item
5 - Repeat steps 1-4 until either the target is found or not
What bubble sort and quicksort do
Order a list
What binary search does
Checks whether a value is in an ORDERED list
First fit algorithm
1 - Take the items in the order given
2 - Place each item in the first available bin that will take it
Advantage of first fit algorithm
It is quick and easy to do
Disadvantage of first fit algorithm
It is not likely to give a good solution
First fit decreasing algorithm
1 - Reorder the list so that it is in descending order
2 - Place each item at the first available bin that will take it
Advantage of first fit decreasing algorithm
You usually get a fairly good solution and it is easy to do
Disadvantage of first fit decreasing algorithm
You may not get an optimal solution
Full bin packing algorithm
1 - Use observation to find combinations of items that will fill a bin and pack these first
2- Pack any remaining items with first fit