d1 algorithms sorting algorithms. bubble sort- repeated passes through a list of numbers by...
TRANSCRIPT
D1 Algorithms
Sorting algorithms
Bubble sort- repeated passes through a list of numbers by comparing and switching adjacent numbers
Try for 16, 9, 4, 6,
Quick sort Try with 19, 9, 4, 6,
Exercise 1B
Exam questions
Bin packing algorithmspacking with as few bins/boxes as possible
Example
Bins of 1.5m tall with 10 boxes to pack into them
Multiply numbers by 10 to make them easier to work with and find the total.T=59
Therefore 4 bins are neededHowever this may not be possible depending upon the size of the boxes
Box A B C D E F G H I J
HEIGHT (M)
0.8 0.6 0.7 0.5 0.9 0.4 0.3 0.6 0.5 0.6
Full bin combinationsonly suitable for small problems
Box A B C D E F G H I JHEIGHT (M)
0.8 0.6 0.7 0.5 0.9 0.4 0.3 0.6 0.5 0.6
Example
A + C 8+7=15 FULL BINB + E 6+9=15 FULL BINH + J + G 6+6+3=15 FULL BIND + I + F 5+5+ 4=14 REMAINING BIN
First fit algorithmtaking the boxes in the order listed and place in the next box available
A (8) BIN 1 LEAVING 7B(6) BIN 1 LEAVING 1C(7) BIN 2 LEAVING 8D(5) BIN 2 LEAVING 3E(9) BIN 3 LEAVING 6F(4) BIN 3 LEAVING 2G(3) BIN 2 LEAVING 0H(6) BIN 4 LEAVING 9I (5) BIN 4 LEAVING 4J(6) BIN 5 LEAVING 9
Although this has led to a further bin being used it is an attempt for a good solution known as a HEURISTIC ALGORITHM
FIRST FIT DECREASING ALGORITHM- REORDER BOXES USING A SORTING ALGORITHM FIRST THEN FOLLOW THE FIRST FIT ALGORITHM
EXERCISE 1C
Exam questions
June 08 q1June 10 q 3Jan 11 q 2Jan 12 q 5