Presentation is loading. Please wait.

Presentation is loading. Please wait.

IGCSE 6 Cambridge Effectiveness of algorithms Computer Science

Similar presentations


Presentation on theme: "IGCSE 6 Cambridge Effectiveness of algorithms Computer Science"— Presentation transcript:

1 IGCSE 6 Cambridge Effectiveness of algorithms Computer Science
Section 2 Effectiveness of algorithms Unit 7 Algorithm design and problem-solving 6

2 Objectives Produce an algorithm for a given problem
Explain standard methods of solution Comment on the effectiveness of a given solution Use a trace table to find the value of variables at each step in an algorithm

3 Designing an algorithm
Designing an algorithm involves developing a set of instructions to solve a problem The instructions need to work for any instance of the problem Sometimes it helps to figure out a solution to one particular instance, and from that, understand how to solve the general problem

4 Multiplying by ten How do you multiply an integer by 10? Why is this easier than multiplying by 9 or by 11? What is special about the number 10? 4623 x 10 = 46230

5 Multiplying by the number base
Decimal numbers use 10 digits 0..9 They are base 10 numbers Binary digits use two digits 0 and 1. They are base 2 numbers What do you get when you multiply the binary number by 2? (Remember that 2 converts to 10 in binary) From this instance you can work out a general solution to the problem of multiplying a number by its “base”!

6 Evaluating an algorithm
When designing an algorithm, you need to consider whether it is the best solution, or even a good solution Does it always give the correct answer? Is it fast enough? Is it economical in terms of resources (e.g. memory, disk space or computational power)? Is it easy for someone to use?

7 Efficiency of an algorithm
When designing an algorithm, you need to consider whether it is the best solution, or even a good solution An algorithm which works well for a few items may not be suitable for a large number of items! Could you use this algorithm to add the numbers 1 to 1000? total = Output total

8 A better algorithm What goes in the blank decision box? total = 0
Output total total = 0 count = 0 count = count + 1 total = total + count No Yes

9 An even better solution
……1000 = …… = 1000 * 1001 Total = n * (n + 1) / 2 Output Total n = 1000 Output Total

10 A search algorithm Ask a friend to think of an integer between 1 and 20 Each time they guess, tell them whether the guess was too high, too low or spot on How many guesses did it take to get the right number? What algorithm were they using to solve the problem?

11 See Binary video

12 The binary search algorithm
This is a very efficient algorithm for finding a particular item in a sorted array or file Think of how you might search for a name in a telephone directory If you’re searching for Richards, you might open the page and find Smith Then you try a few pages back and find Patel What next?

13 The binary search algorithm
Can be applied to guessing a number x between 1 and n Compare x with the middle element m of the set of numbers If x = guess, then the item is found Otherwise, if x < m, repeat the search on the subset to the left of the middle element Or, if x > m, repeat the search on the subset to the right of the middle element For example, suppose your partner thought of the number 6 2 3 Guess 1 too high Guess 4 – found it!

14 Worksheet 6 Try Tasks 1 and 2 on the worksheet

15 Extension - Sorting Sorting is a very common operation in data processing applications Why would you need to sort data? There are many sorting algorithms and they vary wildly in their efficiency The merge sort is 200 times faster than a bubble sort for sorting 10,000 items

16 The bubble sort The bubble sort is not efficient for a large number of items, but it is a simple algorithm to follow Each item in a list is compared to the one next to it, and if it is greater, they swap places At the end of one pass through the list, the largest item is at the end of the list This is repeated until the items are sorted

17 Worksheet 6 Try Task 3 on the worksheet

18 Plenary You’ve had lots of practice at constructing and testing algorithms You’ve learned how to use a trace table to find out what’s going on in an algorithm You’ve learned something about the effectiveness of different solutions to problems You’re ready for the final assessment test!

19


Download ppt "IGCSE 6 Cambridge Effectiveness of algorithms Computer Science"

Similar presentations


Ads by Google