Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An overview of various algorithms, including Prim's, Simplex, Bin packing, Dijkstra's, Kruskal's, Floyd's, and sorting algorithms like Bubble Sort and Quick Sort. Learn about their significance, how they work, and their applications.
Typology: Lecture notes
1 / 56
This page cannot be seen from the preview
Don't miss anything!
Last modified: 11th^ July 2020
1 :: Algorithms Sorting and bin packing. 4 :: Route inspection Find the shortest route which travels along all roads 2 :: Graphs and networks What is a graph and how they represent things. 5 :: The Travelling Salesman Find the shortest route which visits all places. 3 :: Algorithms on graphs What algorithms do I need to be able to apply? 6 :: Linear Programming How to find an optimal solution graphically 7 :: The simplex algorithm How to find an optimal solution algebraically. 8 :: Critical path analysis How to plan a project.
Algorithms can be written in code, flowcharts, or just a list of instructions. Python code now = datetime.now() mm = str(now.month) dd = str(now.day) yyyy = str(now.year) hour = str(now.hour) mi = str(now.minute) ss = str(now.second) print mm + "/" + dd + "/" + yyyy + " " + hour + ":" + mi + ":" + ss What is this programme doing? How to eat cake
The ‘peasant’ algorithm on two numbers is as follows: Make a table with two columns, A and B.
Step n A B C Write down 1 - 2 1 1 1 1, 1 3 - 4 2 2 5 - 6 2 1 2 3 - 4 3 3 5 - 6 3 2 3 3 - 4 5 5 5 - 6 4 3 5 3 - 4 8 11 5 5 5 8 7 - stop Implement this algorithm:
Step n A B C Write down
Reveal A B C D 2 3 0 0 2 3 4 6 6 Print 6
?
There are three shapes of boxes which are used in the examination: The boxes in a flowchart are linked by arrows. As with an algorithm written in words, you need to follow each step in order. Start/End Instruction Decision
Start Stop Let n = 0 Let n = n + 1 Let E = 2 n Print E Is n > 9? No Yes Implement this algorithm using a trace table. n E Decision 0 1 2 No 2 4 No 3 6 No 4 8 No 5 10 No 6 12 No 7 14 No 8 16 No 9 18 No 10 20 Yes n E Decision
Input various values for A=16 and B=12, use a trace table to show your results and work out what the Euclidian Algorithm is doing. step 𝑨 𝑩 𝑩 = 𝟎 𝑨 > 𝑩 1 - 3 16 12 no Yes 6 4 2 - 5 8 no no 2 - 5 4 no no 2 - 5 0 no no 2 yes Print 4 ? step 𝑨 𝑩 𝑩 = 𝟎 𝑨 > 𝑩 It is finding the HCF of A and B?
The diagram describes an algorithm in the form of a flow chart, where a is a positive integer. List P, which is referred to in the flow chart, comprises the prime numbers 2, 3, 5, 7, 11, 13, 17, (b) Explain the significance of the output list. (c) Write down the final value of c for any initial value of a. Reveal ?
?
Pearson Decision 1, Page 9, Q2, Q
Click to Animate We look at each pair of values in turn, and swap them if they’re in the incorrect order: This is known as ‘one pass’ of the algorithm. Clearly we’re not done, but we definitely know one value will be in the correct place. Which? The last value (112), because it’s guaranteed to be moved right on each comparison.
Click to Animate After the second pass, we know that the 67 is now in the right place. We keep doing passes, ignoring one extra item at the end each time. We can stop if there are no swaps on a pass. ? We can then do a ‘ second pass ’, and can exclude the last value, given we know it’s now in the correct position: ?
! Bubble Sort