Presentation is loading. Please wait.

Presentation is loading. Please wait.

Component 1.6.

Similar presentations


Presentation on theme: "Component 1.6."— Presentation transcript:

1 Component 1.6

2 Starter: Entry Ticket Complete the Entry Ticket on Algorithms and Programming Constructs Extension: Draw a Flow Chart that plays the number guessing game: Write a program that asks if they would like to play a number guessing game: The user will get 5 guesses. Whilst the number the user enters is not 10 the game will repeat and tell them that they are wrong. The game should then tell them if their guess was above or below the computers number and should ask them to have another go. If the user guesses correctly, within the 5 guesses, they will receive a congratulations message. If the user does not guess correctly within the 5 guesses they will be told they have ran out of lives.

3 Learning Intentions and Outcomes
To develop an understanding of how computer programs are constructed including the errors that may occur during construction. Grade 4 Explain the industry standard flow chart shapes for Start/Stop, Decision, Input/Output, Process/Operation, Connectors, and Subroutines Explain how Sequencing, Selection, and Iteration are used in Flow Charts and Pseudocode Create algorithms using Flow Charts and Pseudocode Explain the purpose of sorting algorithms Explain the purpose of searching algorithms Grade 5-6 Analyse algorithms to explain inputs and outputs Write algorithms to solve mathematical problems Grade 7 Analyse algorithms to identify data types, inputs, and outputs Write algorithms to solve real world programming problems using pseudocode

4 Assessment Outcomes Use common methods of defining algorithms, including pseudo-code and flowcharts Follow and make alterations to algorithms and programs that solve problems using: Sequence, selection and iteration Input, processing and output. Write algorithms and programs that solve problems using: Input, processing and output

5 Starter Discussion Start / Stop Input / Output Subroutine

6 Starter Discussion Pseudocode is when we write an algorithm in programming‐style constructs but not in an actual programming language. You do not need to worry about the detailed syntax or be precise about how the code will do something, just capture the steps you will need in your program

7 Starter Discussion In programming an algorithm is a set of instructions that can be used to solve a given problem. The instructions must be clear and in the correct order to produce the solution. These instructions will be the starting point for writing a computer program to solve the given problem.

8 Flow charts You are very likely to see flow charts in your exam.
You will be asked to either…. Build one from scratch Understand the outcome based on one Complete or modify a flow chart All flowcharts are build up from the same basic components Terminators Input/Output Decision box Process Storage

9 Terminators These will show where the algorithm starts or ends.
Every algorithm must have a start but may have more than one end Start Stop

10 Output “Hello” + UserName
Input / Output Shows any data/information that is going into the computer or out of the computer. Think is information going in or out of the computer Input UserName Output “Hello” + UserName

11 Flow These are the arrows that show the flow of the algorithm
Some of these flows will require text to describe what is going on.

12 Is UserName in List of Users?
Decision Is UserName in List of Users? These components will ask questions and will have different routes depending on the answer. A decision will have one flow entering and two leaving. A decision box should ALWAYS BE A QUESTION Yes No

13 Process A process is something that happens.
It should always contain a verb or calculation Be careful not to mix input/output with a process X = 10 X = X + 5

14 What do flow charts look like?

15 Requirements to Flow chart
In your exam you may be asked to build a flow chart based on a set of requirements. An example is shown below…

16 Grade 4: Flow Charts Draw the table below in your book and fill in the following shapes and descriptions: Start / Stop Decision Box Input / Output Process / Operation Connector Subroutine Using a diagram explain how Sequencing is used in Flow Charts Using a diagram explain how Selection is used in Flow Charts Using a diagram explain how Iteration is used in Flow Charts Draw a flowchart for a program that: Prompts the user to enter their address Runs a validation check to see if the entered has an symbol in it. If it doesn’t an error message is displayed, the text box is cleared, and the system asks the user to enter their address again. This continues until an address containing an symbol is entered. The system then checks that the address has been typed in lowercase, if not it converts it to lowercase automatically. Once the address is ok it is stored in the customer database Put the subtitle “Flow Charts” in your book and answer the Grade 4 Exercises Extension Draw a flowchart for the following program: Write a program that asks if they would like to play a number guessing game: The user will get 5 guesses. Whilst the number the user enters is not 10 the game will repeat and tell them that they are wrong. The game should then tell them if their guess was above or below the computers number and should ask them to have another go. If the user guesses correctly, within the 5 guesses, they will receive a congratulations message. If the user does not guess correctly within the 5 guesses they will be told they have ran out of lives.

17 Pseudo code Pseudocode is when we write an algorithm in programming‐style constructs but not in an actual programming language. You do not need to worry about the detailed syntax or be precise about how the code will do something, just capture the steps you will need in your program. There are three pseudo code constructs used to write algorithms (an in actual code): Sequence Selection Iteration

18 Sequence Sequence is just a matter of writing the steps down in the order they need to happen i.e. from top to bottom Sequences run line by line For example: Get the product price Get the quantity Total = quantity x price Output “Total price is ” + total

19 Selection Selection is where a program can run different sets of code depending upon certain conditions. For example: User Input Age IF Age > 18 Set AgeValidation to True Else Set AgeValidation to False END IF IF AgerValidation is True Continue to payment Output “Sorry you are not old enough”

20 Iteration Iteration is where a section of code repeats either a set number of times or until a condition is met. For example: Set number of times Repeat 5 times User Input Top Score Add Top Score to ArrayTopScore End Repeat Sort ArrayTopScore Largest to Smallest Output ArrayTopScore Until a condition is true A = 5 WHILE A > 0 END WHILE

21 Grade 4: Pseudocode Explain how Selection is shown using pseudocode
Explain how Sequencing is shown using pseudocode Explain how Iteration is shown using pseudocode Write Pseudocode for a program that: Prompts the user to enter their address Runs a validation check to see if the entered has an symbol in it. If it doesn’t an error message is displayed, the text box is cleared, and the system asks the user to enter their address again. This continues until an address containing an symbol is entered. The system then checks that the address has been typed in lowercase, if not it converts it to lowercase automatically. Once the address is ok it is stored in the customer database Put the heading “Pseudocode” into your book and answer the grade 4 exercises. Extension Write an algorithm (pseudocode) for the following program: Write a program that asks if they would like to play a number guessing game: The user will get 5 guesses. Whilst the number the user enters is not 10 the game will repeat and tell them that they are wrong. The game should then tell them if their guess was above or below the computers number and should ask them to have another go. If the user guesses correctly, within the 5 guesses, they will receive a congratulations message. If the user does not guess correctly within the 5 guesses they will be told they have ran out of lives.

22 Sorting Algorithms A sorting algorithm will put items in a list into a particular order, which may be alphabetic or numeric. As sorting a large list of items can be timely computer algorithms have been developed to do the work for us.

23 Merge Sort The merge sort is a sorting technique based on the idea of ‘divide and conquer’. A merge sort first divides a list into two equal halves and then combines them in a sorted list. We need to divide the list into two equal halves. We then split the halves in half again We keep dividing until each list is a single item We then combine them in the same way they were divided, but in order

24 Merge Sort In the next move (iteration) we combine the lists to make lists of 4 sorted items This whole process is repeated until the list is fully sorted

25 Bubble Sort The bubble sort is a simple sorting algorithm. The algorithm is based on the comparison of adjacent data items, swapping them if they are not in the correct order. The bubble sort is not suitable for large sets of data. How the bubble sort works The bubble sort starts with comparing the first two items, in this case 37 and They are out of order so they need to be swapped over. Next we compare the 37 with 21. These two items need to be swapped. Now we compare 37 with 27. Again these two items need to be swapped. Comparing 37 with 19 means that the two items need to be swapped again.

26 Bubble Sort After the first set of comparisons, know as an iteration, the list looks like this: After the second iteration it will look like this: Notice that after each iteration at least one item has moved to the correct position. After the third iteration the list will look like this. When an iteration results in no swaps being needed then the bubble sort is stopped!

27 Searching Algorithms Searching for data is one of the basic operations of computing. We often need to find one particular item of data amongst many hundreds, thousands, millions or more. For example, you might need to find someone’s phone number on your phone, or a particular business’s address in the UK. This is why searching algorithms are important. Without them you would have to look at each item of data – each phone number or business address – individually, to see whether it is what you are looking for. In a large set of data, it will take a long time to do this. Instead, a searching algorithm can be used to help find the item of data you are looking for.

28 Linear Search The linear search is a very simple search algorithm. Each item in the data set is compared with the search condition in sequence until the item is found or the end of the data set is reached. As the items are compared in sequence the linear search is sometimes known as the sequential search. The items in the list are not in any particular order within the data set. The linear search is not an efficient search. We can measure the efficiency of a search by considering the number of comparisons that are made before the required item is found. The items in the list are not ordered so the probability that the item we are looking for is in any particular position is exactly the same for each position in the list. This means that we may have to compare every item before we find the required one in the last position. We would also have to search the entire list before we discovered that the item was not included in the list.

29 Linear Search Example In the example on the right the array is being searched for the number 3. The first thing the algorithm does is check Element 0 (remember computers count from 0) If it’s a match it will stop, otherwise it checks element 1 and so on.

30 Binary Search A more efficient method of searching a list of data is an algorithm known as the binary search. For a search to be more efficient it is necessary to sort the data into order. Once the data is in order you can adopt methods that would not work on unordered data. Rather than starting the search at the beginning of the list, the search starts at the mid point of the list. The data item is compared with the search item with three possible outcomes: The item at the mid point will match the search item The search item will be less than the item at the mid point The search item will be greater than the item at the mid point. If the search item is less than the item at mid point then all the items after the mid point can be ignored. Similarly if the search item is greater than the mid point then the first half of the list can be discarded. This process is then repeated on the remaining data time after time until the required item is found.

31 Binary Search Example The list has been sorted. We are going to search this list for the number 31. To calculate the mid point we use this formula: mid point = low + (high – low)/2 mid point = 0 + (8 – 0)/2 mid point = 4 With the mid point being 4 we need to compare our search item (31) with the data at position 4 (29). The search item is greater than the data at position 4 we can discard the first part of the list. The search item is less than the data item at position 6 so we can discard the from the mid point upwards.

32 Search Efficiency By using the Binary search we have had to make 3 comparisons to find the required data. This is far more efficient than a linear search. It is important to remember that our examples have limited data. If you were searching thousands of data items the difference between the two methods would be significant.

33 Grade 4: Programming Constructs
Put the heading “Programming Constructs” in your book and answer the grade 4 exercises. Extension Move on to the Grade 5-8 Exam Questions

34 Grade 5-8 Exam Questions Complete them Self Assess them Stick them in
Bring them to me

35 Exit Ticket Complete the Exit Ticket and Stick it in your books.

36 Homework Graded Exercises Complete up to your year 11 target grade
Revision At least 2 pages of revision resources. For example: Cue Cards Mind Maps Notes Posters SAT Topic List: Software Development Lifecycle High and Low Level Programming Languages Program Compilation Programming Errors Binary, Hexadecimal, and Arithmetic Shifts Standards in programming Boolean Logic Hardware Software Development Environments Network Packet Switching and Topologies Algorithms Sound Representation


Download ppt "Component 1.6."

Similar presentations


Ads by Google