Presentation is loading. Please wait.

Presentation is loading. Please wait.

By the end of this session you should be able to...

Similar presentations


Presentation on theme: "By the end of this session you should be able to..."— Presentation transcript:

1 By the end of this session you should be able to...
Understand what is meant by ‘the use of algorithms to describe a problem’ including: Analysis and design of algorithms for a given situation. Compare the suitability of different algorithms for a given task and data set.

2 Good Practice Write the date at the top of a new page at the start of every lesson When you see the pen symbol, copy down what is on the board (you can put it into your own words). Your book will be checked regularly, it must be presentable. When you see the book symbol with a page number, you should turn to that page in your text book. Page: 00

3 Programming Languages
Starter How many programming languages are there?.. Programming Languages

4 Transferable skills So if there are so many programming languages, how do we ensure all programmers follow the correct method to meet a projects needs? We use algorithms to represent the program before we make the program. An algorithm is transferable as it represents the flow of data/ concepts. All programming languages have common features such as IF statements. By writing an algorithm we are ensuring any programmer can develop the final solution. Why do you think this is important?

5 Watch this…

6 So what is an algorithm? Algorithms are a set of instructions that can be followed to perform a certain task. Two common methods of writing algorithms are flowcharts and pseudo code. You need to be familiar with both, by which you should read, write and interpret these methods of displaying solutions. It is through algorithms we are able to develop programming code that computers can use. Page: 049

7 Writing algorithms Algorithms can be notoriously hard to do all but for the most simple task. Non-trivial problems can have a range of out comes. It is the job of the person writing the algorithm to find the most effective outcome. The power of algorithms comes from the short cuts that have been designed into them. Algorithms must work with any instance of the same problem. The whole point of presenting algorithms to a computer is that they can be applied to different sets of similar data.

8 What does this algorithm do?
Task What does this algorithm do? Start Is temp <19 Yes Turn heating on No Is temp >21 Yes Turn heating off No

9 What does this algorithm do?
Task What does this algorithm do? Start Program If temp <19 turn heating on Else If temp >21 turn heating off

10 Task Create a simple program in Python that replicates the algorithm on the previous slide. You should ask the user to specify the temperature and have an output that reads something similar to “heating is on”, etc.

11 Understanding pseudo code
Flowcharts are relatively straight forward to follow, but pseudo code can be tricky to get your head round at first. Follow this Link: Now have a go at replicated the task completed in the video but this time do it in Python.

12 Sequence, Selection and Iteration
An algorithm follows a sequence of instructions. However simple sequences do not allow for complex instructions to take place. We can use selection and Iteration to build a complex algorithm.

13 Selection IF Check the condition
IF – THEN Action to take based on condition IF – THEN – ELSE If condition is not valid perform another action CASE Select response from an array ENDIF Ends the construct

14 Iteration FOR Continues a loop for a set number of times
WHILE Continues a loop while a condition holds true REPEAT Continues a loop until the condition is met

15 How to correctly write Pseudocode
Get temperature IF temperature <19 THEN Switch heating ON ELSE IF temperature >20 THEN Switch heating OFF ENDIF ENDIF Indent Selection in capitals IF statements ended correctly

16 Further help Useful links: http://www.wikihow.com/Write-Pseudocode
Task: Review the links above to familiarise yourself with pseudo code.

17 Algorithm selection The selection of whether to use a flowchart or pseudo code to represent a computer program often depends on the audience and complexity of the computer solution. For example, if you know you are going to program the solution straight away then as we have seen pseudo code straight into your programming language might be the best choice. However, representing the heating system might never be programmed but used to explain to customers how the heating system works. So a flowchart is more appropriate.

18 Task For each of the following tasks identify a possible algorithm method and write a solution to the problem using your chosen method. Drawing a snowman inside a snow globe Representing how traffic light on a bridge work Representing a system that checks the username and password of a user Representing a system that generates 10 questions about Game of Thrones and then assigns a character to the player depending on their answers.

19 Task Choosing at least two of your algorithms, represent the solutions within a programming language of your own choice. Remember to comment your code to ensure you understand what you have done when you come to revise.

20 Identifying what an algorithm does
It is not enough to just be able to write an algorithm; you need to be able to identify what one does. Within an exam you might be presented with pseudo code, a flowchart or a section of code from Java or Python. Your task will be to explain what it does! Remember computational methods are: abstraction, problem decomposition and the development of algorithms.

21 Example Code: def find_max (L): max = 0 for x in L: if x > max:
max = x return max Algorithm: Set max to 0. For each number x in the list L, compare it to max. If x is larger, set max to x. 3.max is now set to the largest number in the list.

22 Task Describe what the following code does: int x, count, even; x = 0;
cin>>count; while(x < count) { cout<<even; even = even+2; x = x+1; }

23 Answer Read count Set x to 0; While(x < count) Set even to even + 2
x = x + 1 write even

24 Task Describe what the following pseudo code does:
Read num1, num2, num3 If (num1 < num2) If(num2 < num3) Write num1 , num2, num3 Else If(num3 < num1) Write num3, num1, num2 Write num1, num3, num2 else If(num1 < num3) Write num2 , num1, num3 If(num3 < num2) Write num3, num2, num1 Write num2, num3, num1

25 Task Program a solution to the pseudo code below:
1. Declare an integer variable called n 2. Declare an integer variable sum 3. Declare an integer variable f1 4. Declare an integer variable f2 5. set sum to 0 6. set f1 and f2 to 1 7. set n to 50 8. repeat n times a. sum = f1 + f2 b. f2 = f1 c. f1 = sum d. print sum 9. end loop int main( ) { int n, k, f1, f2, f; if ( n < 2 ) return n; else { f1 = f2 = 1; for(k=2;k<n;k++) f = f1 + f2; f2 = f1; f1 = f; } return f;

26 Task Program a solution to the pseudo code below:
1. Declare an integer variable called n 2. Declare an integer variable sum 3. Declare an integer variable f1 4. Declare an integer variable f2 5. set sum to 0 6. set f1 and f2 to 1 7. set n to 50 8. repeat n times a. sum = f1 + f2 b. f2 = f1 c. f1 = sum d. print sum 9. end loop int main( ) { int n, k, f1, f2, f; if ( n < 2 ) return n; else { f1 = f2 = 1; for(k=2;k<n;k++) f = f1 + f2; f2 = f1; f1 = f; } return f;

27 Project tasks Your final project will be a computer based solution to the day care problem. Using both flowcharts and pseudo code write algorithms showing possible solutions to the problem. As demonstrated over the previous lessons you might want to write pseudo code into notepad so that it can be copied into the program you choose to write your final solution in. It is a good idea to spend some time thinking about how you are going to represent the different parts of the problem.


Download ppt "By the end of this session you should be able to..."

Similar presentations


Ads by Google