D1 Algorithms Sorting algorithms. Bubble sort- repeated passes through a list of numbers by...
-
Upload
bobby-fletcher -
Category
Documents
-
view
217 -
download
0
Transcript of D1 Algorithms Sorting algorithms. Bubble sort- repeated passes through a list of numbers by...
![Page 1: D1 Algorithms Sorting algorithms. Bubble sort- repeated passes through a list of numbers by comparing and switching adjacent numbers Try for 16, 9, 4,](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c775503460f9492c491/html5/thumbnails/1.jpg)
D1 Algorithms
Sorting algorithms
![Page 2: D1 Algorithms Sorting algorithms. Bubble sort- repeated passes through a list of numbers by comparing and switching adjacent numbers Try for 16, 9, 4,](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c775503460f9492c491/html5/thumbnails/2.jpg)
Bubble sort- repeated passes through a list of numbers by comparing and switching adjacent numbers
Try for 16, 9, 4, 6,
![Page 3: D1 Algorithms Sorting algorithms. Bubble sort- repeated passes through a list of numbers by comparing and switching adjacent numbers Try for 16, 9, 4,](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c775503460f9492c491/html5/thumbnails/3.jpg)
Quick sort Try with 19, 9, 4, 6,
![Page 4: D1 Algorithms Sorting algorithms. Bubble sort- repeated passes through a list of numbers by comparing and switching adjacent numbers Try for 16, 9, 4,](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c775503460f9492c491/html5/thumbnails/4.jpg)
Exercise 1B
![Page 5: D1 Algorithms Sorting algorithms. Bubble sort- repeated passes through a list of numbers by comparing and switching adjacent numbers Try for 16, 9, 4,](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c775503460f9492c491/html5/thumbnails/5.jpg)
Exam questions
![Page 6: D1 Algorithms Sorting algorithms. Bubble sort- repeated passes through a list of numbers by comparing and switching adjacent numbers Try for 16, 9, 4,](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c775503460f9492c491/html5/thumbnails/6.jpg)
![Page 7: D1 Algorithms Sorting algorithms. Bubble sort- repeated passes through a list of numbers by comparing and switching adjacent numbers Try for 16, 9, 4,](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c775503460f9492c491/html5/thumbnails/7.jpg)
![Page 8: D1 Algorithms Sorting algorithms. Bubble sort- repeated passes through a list of numbers by comparing and switching adjacent numbers Try for 16, 9, 4,](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c775503460f9492c491/html5/thumbnails/8.jpg)
![Page 9: D1 Algorithms Sorting algorithms. Bubble sort- repeated passes through a list of numbers by comparing and switching adjacent numbers Try for 16, 9, 4,](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c775503460f9492c491/html5/thumbnails/9.jpg)
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
![Page 10: D1 Algorithms Sorting algorithms. Bubble sort- repeated passes through a list of numbers by comparing and switching adjacent numbers Try for 16, 9, 4,](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c775503460f9492c491/html5/thumbnails/10.jpg)
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
![Page 11: D1 Algorithms Sorting algorithms. Bubble sort- repeated passes through a list of numbers by comparing and switching adjacent numbers Try for 16, 9, 4,](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c775503460f9492c491/html5/thumbnails/11.jpg)
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
![Page 12: D1 Algorithms Sorting algorithms. Bubble sort- repeated passes through a list of numbers by comparing and switching adjacent numbers Try for 16, 9, 4,](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c775503460f9492c491/html5/thumbnails/12.jpg)
EXERCISE 1C
![Page 13: D1 Algorithms Sorting algorithms. Bubble sort- repeated passes through a list of numbers by comparing and switching adjacent numbers Try for 16, 9, 4,](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c775503460f9492c491/html5/thumbnails/13.jpg)
Exam questions
June 08 q1June 10 q 3Jan 11 q 2Jan 12 q 5