d1 algorithms sorting algorithms. bubble sort- repeated passes through a list of numbers by...

13
D1 Algorithms Sorting algorithms

Upload: bobby-fletcher

Post on 14-Dec-2015

221 views

Category:

Documents


0 download

TRANSCRIPT

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,

D1 Algorithms

Sorting algorithms

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,

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,

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,

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,
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,
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,
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,

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,

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,

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,

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,

Exam questions

June 08 q1June 10 q 3Jan 11 q 2Jan 12 q 5