Presentation is loading. Please wait.

Presentation is loading. Please wait.

Order of an algorithm The order of an algorithm tells you how efficient it is. The more efficient the quicker it is to complete it. This is important in.

Similar presentations


Presentation on theme: "Order of an algorithm The order of an algorithm tells you how efficient it is. The more efficient the quicker it is to complete it. This is important in."— Presentation transcript:

1 Order of an algorithm The order of an algorithm tells you how efficient it is. The more efficient the quicker it is to complete it. This is important in a business where a computer may be tied up working through the problem and time is money.

2 Finding the order Consider an algorithm to find the largest number in a list. Starting with the first number it is compared with each successive number in the list. If a larger number is found then this number is compared with all the successive numbers. When the end of the list is reached then the number of comparisons made will be one less than the number in the list. Number of comparisons = n - 1 So the algorithm is of order n. If a computer takes 0.01 seconds to do 1 comparison then if the algorithm is of order n then it will take 0.01  n seconds to do n comparisons. numberslargest numbercomparisons 55 251 772 473 884

3 The table on the left tells you the order of some common algorithms which will be covered in later units. AlgorithmOrder bubble sortn2n2 shuttle sortn2n2 shortest pathn2n2 minimum connectorn3n3 route inspectionn3n3 exponential2n2n So an order of n 2 means that the time to perform the algorithm depends on the square of n i.e Time  n 2 So if the value of n is doubled then the time increases by a factor of n 2 i.e 4 times as long

4 Bubble sort: a computer takes 10 seconds to solve a problem of size 60. How long does a problem of size 300 take. t = timen = problem size Method 1 t  n 2 so t = k×n 2 Subst given information10 = k×60 2 solving k = Now use information for the required problem t = ×300 2 solving t = 250secs

5 Method 2 As the order is n 2 then use the ratio so t 1 =

6 Exponential: A computer takes 2 seconds to solve a problem of size 15. How long does a problem of size 150 take if the order is 2 n. t = timen = problem size Method 1 t  2 n Subst given information2 = k×2 15 solving k = so t = k×2 n Now use information for the required problem t = ×2 150 solving t = 2×2 135 secs


Download ppt "Order of an algorithm The order of an algorithm tells you how efficient it is. The more efficient the quicker it is to complete it. This is important in."

Similar presentations


Ads by Google