Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Comp 2 - Computer Science Ko

Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

KNOWLEDGE ORGANISERS

COMP 2 REVISION: COMPUTATIONAL THINKING, ALGORITHMS &


PROGRAMMING

1
2.1 – Algorithms - Computational Thinking
What is Computational thinking?
KEY TERMS
Algorithm: Steps to provide a solution
3
Flowcharts
to a problem, usually represented in
The thought processes involved in flowcharts or pseudocode
Displays an algorithm in diagram form using
formulating a problem and its symbols and arrows to show to flow of
Decompose: Breaking down a large information
solution(s), so that a computer,
problem into smaller sub-problems
human or machine can effectively Pseudocode
carry out Abstraction: Representing 'real world' A structured use of English used to define
problems in a computer using variables the steps needed to solve a problem.
1 and symbols and removing unnecessary
elements from the problem

How do you think Algorithmic Thinking: Identifying the WHILE TRUE:

computationally? steps involved in solving a problem. temp = “”


3
Sequence: Completing steps in the IF temp > than 20c THEN
To effectively solve problems you need order which they must happen Open windows AND heaters OFF
to…. ELSE
Selection: Where a choice is made in a Close windows AND heaters ON

• Decompose program depending on a condition or


outcome TIME = “”
• Abstract IF TIME = 18.00 THEN
• Algorithmic thinking Sprinklers on
Iteration: Act of repeating or lopping
• Create algorithms specific sections of code ELSE
1 Sprinklers off
2 Continue
2
BREAK
2.1 – Algorithms – 4. Flowcharts SUB
ROUTINE
START/STOP
Sequence that performs a specific task.
Always start and end with this You can use this within your flowchart
to show more detail in a specific section

INPUT/OUTPUT
PROCESS

Use when there is an input or output To do something in


required e.g. user inputs their name, the program e.g a
program displays their name calculation
Decision

Is No Flow lines – show


A>10 the flow of
? information in the
When a choice has to
be made in the algorithm
program 3
YES
2.1 – Algorithms – 5. Pseudocode The OCR Pseudocode guide has more
information if you wish to do more
Here are some symbols to use research.
Pseudocode uses English.
It mimics how your code may look Comparison operators
WHILE TRUE:
in the programming language BUT temp = “”
it DOESN’T have to be exact == Equal to
IF temp > than 20c THEN
!= Not equal to
Open windows AND heaters OFF
< Less than ELSE
Some useful terms you could <= Less than or equal to Close windows AND heaters ON
use.  Greater than
>= Greater than or equal to TIME = “”
IF TIME = 18.00 THEN
START Sprinklers on
IF Arithmetic Operators ELSE
Sprinklers off
ELIF Continue
ELSE + Add BREAK
FOR
WHILE TRUE
- Subtract This repeats, it reads the temp of a
/ Divide greenhouse. If greater than 20 degs then
ENDIF open windows and turn heaters off ELSE
* Multiply close windows and heaters on
END MOD will return the remainder for the
It checks the time if the time is 6pm then turn
division sprinklers on otherwise keep sprinklers off
4
2.1 – Search Algorithms - Binary and Linear searches

5
2.1 – Sorting Algorithms – Bubble, Insertion & merge

6
2.2 Programming Techniques Syntax Error
Constant An error in the rules/grammar of the language Eg missing colon / spelling mistake
Value STORED IN A MEMORY LOCATION that
never changes WITHIN A PROGRAM Logic Error
The program is written to do something other than what the programmer intended
Variable Eg Resetting only the first 9 elements in an array instead of all 10.
Value STORED IN MEMORY LOCATION that
Run Time Error:
can change WITHIN IN A PROGRAM More difficult to spot as it can run a program without reporting an error. E.g. runs but
Doesn’t give an output. Or the program hangs or Becomes inactive

Sequence: Completing steps in the order


which they must happen
Data Types Other Info
Real /Float
Selection: Where a choice is made in a Number with decimal Point Concatenate
program depending on a condition or Integer To join different data types together
outcome Number without a decimal Point
String # Comments
Iteration: Act of repeating or lopping Use these to add comments in to your code to
A series of characters/TEXT
explain what you have done
specific sections of code Character
Count controlled Iteration: A single letter or symbol
Validation: An computer check to
Repeats a set number of times Date/Time
ensure that the data entered is sensible
Condition controlled: Repeats Date and Time in any format
Boolean and reasonable. It does not check the
until a condition is met or something in the
Yes no, true false value accuracy of data.
program changes 7
2.2 Programming Techniques

TYPE INFO SYNTAX


LIST MUTABLE [ ]
DIFFERENT DATA TYPES E.G. [1,”HELLO”, 3.4]

TUPLE IMMUTABLE ()
DIFFERENT DATA TYPES E.G. (1,2, “Hello”, 4.3)

ARRAY IMMUTABLE []
SAME DATA TYPE E.G [1,2,3,4] 8
2.3 Robust Programs Data Validation techniques

Producing robust programs so that they are


defensive against hacks and attacks.

Data Validation: check to ensure that the data entered


is sensible and reasonable. It does not check the
accuracy of data.

Data Sanitisation: Trims or strips strings, removing


unwanted characters to make sure it contains only
permitted characters . E.g. Da%ve the % would be
removed.

Authentication: The process of verifying the identify of


a user or process

Maintainability : Updating code so that it is compatible Anticipating Misuse: Defensive program design will consider and anticipate
with current requirements misuse. Misuse may be in the form of a brute force attack on the program.
E.G Many programs and systems only allow a user to enter a password three
Comments: To help describe the code and structures or four times before it locks out the system.
in a program using #
Contingency Planning: Once a programmer has anticipated the misuse they can
Indentation: used to show the programs structure e.g. then plan for the these issues. For example: Limiting the number of logon
where selection or iteration or functions are used . attempts. Ensuring the code is robust in validating the data entered
9
2.3 Robust Programs Test data – When testing your programs it is important to use of
data to test and to create a test plan.
Iterative testing: This happens overtime and is repeated
throughout the development of the program

Final/terminal testing: is when the product is released


and real end users begin using it. Very often, end users
find things wrong with systems that the programmers
did not expect.

Syntax Errors: An error in the rules/grammar of the


language Eg missing colon / spelling mistake

Logic errors: The program is written to do something


other than what the programmer intended Eg Resetting
only the first 9 elements in an array instead of all 10.

Test Data: Something which has been specifically


identified for use in tests, typically of a computer
program

Example test plan

10
2.4 Computational logic Truth Tables: Display all possible
outcomes for that gate
Logic Gate: A building block of a digital circuit. They
perform logical functions in a circuit and use binary
IN OUT
Not Gate 0 1
Inverts the input (0 becomes 1 and 1 1 0
becomes 0
A B Out
OR Gate 0 0 0
0 1 1
Wait for either inputs to be 1 for output to
be 1 1 0 1
A OR B 1 1 1

A B Out
AND Gate
0 0 0
Both inputs to be 1 for output to be 1 0 1 0
A AND B
1 0 0
11
1 1 1
TRANSISTOR: A tiny switch that is activated by the
2.4 Computational logic electronic signals it receives. The digits 1 and 0
used in binary reflect the on and off states of this.

Logic CIRCUIT: A combination of


different logic gates used to perform HINT: when completing the
inputs in a truth table – don’t How many rows do you need in a
more complex tasks forget to count up in binary, to truth Table?
make sure you have all possible 𝑁𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑅𝑜𝑤𝑠
inputs = 2𝑛𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑖𝑛𝑝𝑢𝑡𝑠
A and B re inputs. There are 4
So for 1 input = 1 x 2 = 2
Notation rows – starting from 0 make the
binary numbers 0,1,2,3.
For 2 inputs = 2 x 2 = 4
The symbols used to describe logic
For 3 inputs = (2x2)x2 = 8
gates A B Out For 4 inputs = 2x2x2x2 = 16
⋀ And 0 0 0 0
V Or 1 0 1 0
¬ 𝐍𝐨𝐭
2 1 0 0
3 1 1 1
EG. The notation below means – P =
A and b and not c. When you draw
the circuit the one in brackets goes
first
Y = A ⋀ B (¬ C) C
12
Why is data represented in Binary in a
2.4 Computational logic computer system?:
• Binary is the representation of the
‘presence’ of electricity
An example logic circuit, with notations and truth table • If present or ‘on’ we use a: 1
A⋀(BVC)
• If absent or ‘off’ we use a: 0
• We can use this idea to change 1 and 0
states through the use of logic gates
• Logic Gates take inputs and covert them to
an output
• The digit 1 or 0 is stored in transistors
which are in the processor.

Half Adder: A circuit to add two binary bits


together

Full Adder circuit: 2 half adders together.


This can add more than two binary bits
together and deal with carrying bits over
13
2.5 Translators and Facilities Selection
A condition is used to decide
executed
High Level Language (eg Python) How Instructions are stored in Binary. • if x = 1 then y = 3 else x whether
• Use Instructions are in Words code should be = 2
• Designed to be read by human programmers • The instruction consists of an operator/op
• Portable/translated for different machines code and an operand Sequence
PROS: Easy for humans to understand as written in English • both stored as bit patterns A list of instructions to be
CONS: Needs to be translated in to machine code so not as • (op code) from a given instruction set followed one after the other.
fast to execute • Each op code has a unique bit pattern Step by step

Why Use Binary.


• So that computers can be based on logic Iteration
Machine Code (Binary Code) (low level) circuits. code is executed repeatedly
• Instructions are in binary code Designed to be • (each part of the circuit) can be in one of two For I in range (10);
read/executed by the computer states Print (i)
• Specific to a particular machine • 0 and 1/true or false
PROS: Fast no need to translate already in binary, close to
CPU Translators
CONS: Difficult to read and understand for humans Interpreters:
Translates one line of HL code at a time…
… and executes it
Assembly Language (low level) … stops when it finds an error
• Low Level Language written in mnemonics that closely … can be resumed
reflect the operations of the CPU Compilers:
• Eg LOAD Translates whole program of HL code at a time…
PROS: A bite easier to understand than binary as uses … and executes it
mnemonics … stops when it finds an error
CONS: Still needs translating to machine code using an
Assembler: 14
Assembler translator
Translates Assembly language into machine code
2.5 Translators and Facilities
TOOLS FOR PROGRAMMING
Source Code: The code the programmer writes
IDE (intergrated Development Environment): A software
application that provides all the facilities to computer programmers for
developing programs. It normally consists of a source code editor, build
Object Code: code converted by the compiler
automation tools and a debugger so that it can be understood by the computer

Code Editor – edits program text, you can type our your source Executable Code: Files which contain
code here instructions in machine code. These
Syntax Checks – Highlights syntax errors instructions are carried out in the computer
hardware
Runtime Environment – allows programs to be run one line at a
time – helps test programs and locate errors. Programming Standards
Code should follow agreed conventions (EG Lowercase for
Translator – Compiles or interprets the code variable names, schemes to be followed).
Language code is written in.
Libraries – Provides functions not included in core part of Functions used to tidy up repeated code.
programming languages (eg Random)
Comments explain the code clearly.
Correct use of indentation.
Debugger – Helps to detect errors. Suggests what type of error it
is and what line it is on. Useful identifiers (File names & Variable names)
Code should follow agreed conventions 15

You might also like