Download presentation
Presentation is loading. Please wait.
Published byShon Hawkins Modified over 6 years ago
1
Starter 15//2 = 7 (Quotient or Floor) (Modulus) 22%3 =1
State the values that would be stored in the variable “result”. (a) Result = 15 DIV 2 15//2 = 7 (Quotient or Floor) (Modulus) 22%3 =1 (b) Result = 22 MOD 3 (Exponent or power) 3**3 = 27 (c) Result = 3^3
2
true false true 2 For the following, X = 3 and Y = 6.
(a) State whether the following statements are true or false: (i) X = Y/2 (ii) X > Y (iii) Y <= X*2 true false true
3
X = 3 and Y = 6. State what would be output from the following algorithm: (i) If (X > 2 AND Y < 5) print (“true”) else print (“false”) endif false
4
true false X = 3 and Y = 6. (ii) If the first line states:
If (X > 2 OR Y < 5) (iii) If the first line states: If NOT (X < 4 OR Y < 5) true false
6
GCSE Computer Science Algorithms Revision
7
Abstraction Some examples Real life Abstraction Your School day
A way of looking at a real-life thing that helps us to think more clearly about it. Some examples Real life Abstraction Your School day Your time table
8
Abstraction Abstraction is the method of removing the unnecessary details and include only the relevant details in order to solve a problem.
9
Lets imagine you are creating an interface for a Satnav.
How would you apply abstraction?
12
7 9 A B 1 F 2 7 E 1 2 G H 8 3 C D
13
7 9 A B 1 F 2 7 E 1 2 G H 8 3 C D
14
Input or Output Decision Input or Output Stop
15
Challenges Then print the result of the calculation
1) Write a python program that inputs 2 numbers and a + - * / Then print the result of the calculation 2) Write a Python program to input 4 numbers then calculate and print the average 3) Write a Python program to input a list of n numbers and print the average (while loop)
16
Abstraction of code… When we code our program a flowchart is technically an “abstraction” of our algorithm and the code we write.
19
Thinking about the data
We can use abstraction to visualise the data structure. We can store this data in 2 dimensional array (List)
20
We know we want to search each row in the grid.
A FOR loop suits this perfectly.
21
Decomposition Get the paddle to interact with the user
Validation on paddle. Don’t want to go off the screen Draw the ball Add sound Get Ball to bounce Add better graphics Draw the tiles Add special effects Get the ball to detect when its hit a tile Add in game winning and losing conditions
22
Block Diagram Development
Ball Small Get paddle to display Draw the ball Draw the tiles Play sounds Manage score Draw paddle in pixels and display Get Ball to bounce Remove hit tiles Monitor win/lose conditions Set variable for x co position Get the ball to detect when its hit a tile Set y co position as a constant so it doesn’t move Set boundary co-or for edge of screen
23
Decomposition Makes problems easier to solve
Different people can work on different parts of a problem at the same time, reducing development time Program components developed in one program can easily be used in other programs
24
Challenges Then print the result of the calculation
1) Write a python program that inputs 2 numbers and a + - * / Then print the result of the calculation 2) Write a Python program to input 4 numbers then calculate and print the average 3) Write a Python program to input a list of n numbers and print the average (while loop)
25
Linear search A linear search involves methodically searching one location after another until the searched for value is found. Data is held in consecutive locations Data is not ordered Good if… data cannot be ordered Step through until... Value found – return location Value not found – return not found Adam Debbie Chris Felix Aaron John Sarah Will
26
Binary search In order For the binary search to work the list must be?
A binary Search is an example of a Divide and Conquer Algorithm. “This is where you repeatedly break down a problem into smaller problems and tackle these smaller problems to build an answer to the original” In order For the binary search to work the list must be?
27
2 33 1 2 3 4 5 6 7 8 2 33 1 2 3 4 5 6 7 8
28
Bubble Sort 2 1 3 6 5 4 Set swapMade = true WHILE swapMade is true
Set swapMade to false Start at position 0 For position = 0 to listlength-2 Compare the item at position you are at with the one ahead of it If they are out of order THEN Swap items and set swapMade to true END IF Next position End WHILE 2 1 3 6 5 4
29
Bubble Sort 2 1 3 6 5 4 Set swapMade = true WHILE swapMade is true
Set swapMade to false Start at position 0 For position = 0 to listlength-2 Compare the item at position you are at with the one ahead of it If they are out of order THEN Swap items and set swapMade to true END IF Next position End WHILE 2 1 3 6 5 4
30
Bubble Sort 2 1 3 6 5 4 1 2 3 6 5 4 1 2 3 6 5 4 1 2 3 6 5 4 1 2 3 6 5 4
31
Bubble Sort 1 2 3 5 6 4 1 2 3 5 6 4 1 2 3 5 4 6 1 2 3 5 4 6 1 2 3 5 4 6 1 2 3 5 4 6
32
Bubble Sort 1 2 3 5 4 6 1 2 3 4 5 6 How do we know it has finished?
33
Bubble Sort 1 2 3 4 5 6 1 2 3 4 5 6 We go through the list again and if no swaps are made then it is sorted 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6
34
Insertion Sort Make the first item the sorted list and the remaining items are the unsorted list. WHILE there are items in the unsorted list Take the first item of the unsorted list. WHILE there is an item to the left of it which is smaller than itself Swap with that item. END WHILE The sorted list is now one item bigger 3 1 2 5 6 4 3 1 2 5 6 4 3 1 2 5 6 4 Sorted Unsorted 1 3 2 5 6 4 Sorted Unsorted 1 2 3 5 6 4 Sorted Unsorted
35
Insertion Sort 1 2 3 5 6 4 Sorted Unsorted 1 2 3 5 6 4 Unsorted Sorted 1 2 3 5 6 4 Unsorted Sorted 1 2 3 5 6 4 Unsorted Sorted
36
Insertion Sort 1 2 3 5 4 6 Unsorted Sorted 1 2 3 4 5 6 Unsorted Sorted How do you know it has finished ? You have processed the last item in the Unsorted list and you have positioned it in the sorted list next to one that is smaller.
37
Arrays An array is a list of data items of the same type that can referred to by the same variable name NumberList=[3,5,7,9,11] print(NumberList[0]) print(NumberList[1]) print(NumberList[2]) print(NumberList[3]) print(NumberList[4])
47
Should say identify the symbol
48
Should say identify the symbol
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.