0% found this document useful (0 votes)
4K views9 pages

Caie As Level Computer Science 9618 Practical 634fb2359fe6a24c6da54e50 246

The document provides an overview of key concepts in algorithm design and problem solving, data representation, and file handling. It discusses topics like abstraction, decomposition, different types of loops, data types, ASCII and Unicode encoding, arrays, sorting algorithms, and opening and reading files in Python.

Uploaded by

liuziyun591
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4K views9 pages

Caie As Level Computer Science 9618 Practical 634fb2359fe6a24c6da54e50 246

The document provides an overview of key concepts in algorithm design and problem solving, data representation, and file handling. It discusses topics like abstraction, decomposition, different types of loops, data types, ASCII and Unicode encoding, arrays, sorting algorithms, and opening and reading files in Python.

Uploaded by

liuziyun591
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

ZNOTES.

ORG

UPDATED TO 2017 SYLLABUS

CAIE AS LEVEL
COMPUTER
SCIENCE
SUMMARIZED NOTES ON THE PRACTICAL SYLLABUS
Prepared for David Liu for personal use only.
CAIE AS LEVEL COMPUTER SCIENCE

Iterate over an array: FOR Loop


Reading a file into a variable: WHILE Loop
1. Algorithm Design & Asking for user input: WHILE/REPEAT Loop
A loop that should execute n times: FOR Loop
Problem-Solving
1.4. Stepwise Refinement
Abstraction: filtering out and concentrating on the
relevant information in a problem; allowing a Process of developing a modular design by splitting a
programmer to deal with complexity problem into smaller sub-tasks, which themselves are
Decomposition: breaking down problems into sub- repeatedly split into even smaller sub-tasks until each is
problems in order to understand a process more clearly; just one element of the final program.
program modules, procedures and functions all help the
programmer to break down large problems
Algorithm: a solution to a problem expressed as a
1.5. Program Modules
sequence of steps
This refers to a modular program design
Subroutines: self-contained section of code, performing a
1.2. Identifier Table specific task; part of the main program
Procedures: performs a specific task, no value returned to
Identifier: name given to a variable in order to call it
part of code where called
An identifier table depicts information about the variable,
Functions: performs a specific task, returns a value to part
e.g. of code where called

1.6. Logic Statements


Operator Meaning
< Less than

Rules for naming identifiers: <= Less than/equal


Must be unique > Greater than
Spaces must not be used >= Greater/equal
Must begin with a letter of the alphabet = Equal to
Consist only of a mixture of letters and digits and the
<> Not equal to
underscore character ‘_’
Must not be a ‘reserved’ word – e.g. Print, If, etc.
2. Data Representation
1.3. Basic Program Operations
Assignment: an instruction in a program that places a 2.1. Data Types
value into a specified variable
Integer:
Sequence: programming statements are executed
consequently, as they appear in the program
Positive or negative number; no fractional part
Selection: control structure in which there is a test to Held in pure binary for processing and storage
decide if certain instructions are executed Some languages differentiate short/long integers (more
IF selection: testing 2 possible outcomes bytes used to store long integers)
CASE selection: testing more than 2 outcomes
Repetition/Iteration: control structure in which a group of Real:
statements is executed repeatedly
FOR loop: count-controlled; executed a set no. of times Number that contains a decimal point
WHILE loop: pre-conditional; executed based on Referred to as singles and doubles depending upon
condition at start of statements number of bytes used to store
REPEAT loop: post-conditional; executed based on
Character:
condition at end of statements
A character is any letter, number, punctuation or space
As for selecting what loop to use, it is best to use FOR loops
Takes up a single unit of storage (usually a byte).
when you know the number of iterations required, and a
WHILE or REPEAT loop if you do not know the number of String:
iterations required.

WWW.ZNOTES.ORG Copyright © 2024 ZNotes Education & Foundation. All Rights Reserved. This document is authorised
for personal use only by David Liu at undefined on 14/05/24.
CAIE AS LEVEL COMPUTER SCIENCE

Combination of alphanumeric characters enclosed in “ ”


Each character stored in one byte using ASCII code
Each character stored in two bytes using Unicode
Max length of a string limited by available memory.
Incorrect to store dates or numbers as strings
Phone no. must be stored as string else initial 0 lost

Boolean:

Can store one of only two values; “True” or “False”


Stored in 1 byte: True = 11111111, False = 00000000

Date:

Dates are stored as a ‘serial’ number


Equates to number of seconds elapsed since 1st January
1970 00:00:00 UTC, excluding leap seconds. 2-Dimensional (2D) Array: declared using two indices, can
Usually take 8 bytes of storage be represented as a table
Displayed as dd/mm/yyyy or mm/dd/yyyy

Array:

Data structure consisting of a collection of elements


Identified by at least one array index (or key)

File:

Object that stores data, information, settings or


commands
Can be opened, saved, deleted & moved
Transferrable across network connections

Pseudocode:
2.2. ASCII Code 1-D Array: array = []
2-D Array: array = [[], [], [], …]
Uses 1 byte to store a character
Python:
7 bits available to store data and 8th bit is a check digit Declaring an array: names = []
27 = 128, therefore 128 different values Adding to an array: names.append(‘ZNotes’)
ASCII values can take many forms: numbers, letters Length of array i.e. number of elements: len(names)
(capitals and lower case are separate), punctuation, non- Printing an element in a 1D array:
printing commands (enter, escape, F1) print(names[element position])
Printing element in a 2D array: print (a[row]
2.3. Unicode [column])
Printing row in a 2D array: names[row] = [new row]
ASCII allows few number of characters; good for English Printing column: use for loop and keep adding 1 to the
Unicode allows others too: Chinese, Greek, Arabic etc. row and keep column same
Different types of Unicode:
UTF-8: compatible with ASCII, variable-width encoding 2.5. Bubble Sort
can expand to 16, 24, 32, 40, 48
UTF-16: 16-bit, variable-width encoding can expand to
32 bits
UTF-32: 32 bit, fixed-width encoding, each character
exactly 32 bits

2.4. Arrays
1-Dimensional (1D) Array: declared using a single index,
can be represented as a list

WWW.ZNOTES.ORG Copyright © 2024 ZNotes Education & Foundation. All Rights Reserved. This document is authorised
for personal use only by David Liu at undefined on 14/05/24.
CAIE AS LEVEL COMPUTER SCIENCE

Testing for end of the file: EOF(filename)

Python:

Opening a file: variable = open(“filename”, “mode”)

Where the mode can be:


Mode Description
Opens file for reading only. Pointer placed at the
r
beginning of the file.
Opens a file for writing only. Overwrites file if file
w
exists or creates new file if it doesn’t
Opens a file for appending. Pointer at end of file if
a
it exists or creates a new file if not

Reading a file:
A FOR loop is set to stop the sort Read all characters: variable.read()
Setting a variable ‘sorted’ to be ‘true’ at the beginning Read each line and store as list: variable.readlines()
Another FOR loop is set up next in order to search through Writing to a file:
the array Write a fixed a sequence of characters to file:
An IF is used to see if the first number of the array is variable.write(“Text”)
greater than the second. If true: Write a list of string to file: variable.write(‘ ‘.join(‘Z’,
First number stored to variable ‘Notes’))
Second number assigned as first number
Stored variable assigned to second number
Set ‘sorted’ to ‘false’ causing loop to start again Abstract Data Types
The second FOR loop is count based thus will stop after a
specific number of times (ADT)
Goes through bigger FOR loop ∴ ‘sorted’ remains ‘true’
This exits the loop ∴ ending the program An Abstract Data Type (ADT) is a collection of data with
associated operations. There are three types of ADTs:
2.6. Linear Search Stack: an ordered collection of items where the addition of
new items and removal of existing items always takes
place at the same end.
Queue: a linear structure which follows the First In First
Out (FIFO) mechanism. Items are added at one end (called
A FOR loop goes through the array the rear) and removed from the other end (called the
It compares item in question to those in list using an IF: front)
If item matches with another then search is stopped Linked List: a linear collection of data elements whose
Also the location where it was found is returned order is not given by physical placements in memory
If not found it exits the FOR loop (non-contiguous). Each element points to the next.
Then returns fact that item in question is not in the list

2.7. File Handling


3. Programming
Programming is a transferable skill
Files are needed to import contents (from a file) saved in
Transferable skill: skills developed in one situation which
secondary memory into the program, or to save the
output of a program (in a file) into secondary memory, so can be transferred to another situation.
that it is available for future use
3.2. Variables
Pseudocode:
Declaring a variable:
Opening a file: OPENFILE <filename> FOR
Pseudocode: ‘’’DECLARE : ‘’’
READ/WRITE/APPEND
Python: no need to declare however must write above
Reading a file: READFILE <filename>, <variable>
as a comment (‘’’python #...‘’’)
Writing a line of text to the file: WRITEFILE <filename>,
Assigning variables:
<string>
Closing a file: CLOSEFILE <filename>

WWW.ZNOTES.ORG Copyright © 2024 ZNotes Education & Foundation. All Rights Reserved. This document is authorised
for personal use only by David Liu at undefined on 14/05/24.
CAIE AS LEVEL COMPUTER SCIENCE

‘’’python ← ‘’’ or ‘’’python ‘’’ Create routines that can be called like built-in command

‘’’python identifier = value‘’’ or ‘’’python expression‘’’ or ‘’’python


“string”‘’’
3.7. Procedure
Procedure: subroutine that performs a specific task without
3.3. Selections returning a value

“IF” Statement Procedure without parameters:


Pseudocode: IF…THEN…ELSE…ENDIF
Python: if (expression): (statements) else: PROCEDURE def
(statements) <statement(s)>ENDPROCEDURE identifier():statement(s)
“CASE” Statement
Pseudocode: CASE OF variable: … … … When a procedure has a parameter, the function can
OTHERWISE: … ENDCASE either pass it by either reference or value
Python: if (expression): (statement) elif Pass by value: data copied into procedure so variable not
(expression): statement) … else: (statement) changed outside procedure

PROCEDURE <identifier> (BYVALUE <param>:


3.4. Iterations <datatype>)
<statement(s)>
Count-controlled Loop ENDPROCEDURE
FOR <identifier> ← <val1> TO def identifier(param):
<val2> STEP <val3> statement(s)
<statement(s)>
ENDFOR Pass by reference: link to variable provided so variable
changed after going through procedure (not in Python)
for x in range(value1, value2):
statement(s) PROCEDURE <identifier> (BYREF <param>:
Post condition Loop <datatype>)
REPEAT Not possible in Python <statement(s)>
<statement(s)> Use ‘’’python WHILE‘’’ and ENDPROCEDURE
UNTIL <condition> ‘’’python IF‘’’
Calling a procedure:
Pre-condition Loop
WHILE <condition> CALL () Identifier()
while expression:
<statement(s)>
statement(s)
ENDWHILE
3.8. Function
3.5. Built-in Functions Function: subroutine that performs a specific task and returns
a value
String/character manipulation: Functions are best used to avoid having repeating blocks of
code in a program, as well as increasing the reusability of
Uppercase or lowercase all characters: code in a large program.
(“string”).upper() (“string”).lower() FUNCTION <identifier> (<parameter>: <data type>)
Finding length of a string: len(“string”) RETURNS <datatype>
Converting: <statement(s)>
String to Integer - int(“string”) ENDFUNCTION
Integer to String - str(integer) def identifier(param):
statement(s)
Random number generator: random.randint(a, b)
return expression
Where a and b defines the range

3.6. Benefits of Procedures and 4. Software Development


Functions:
4.1. Program Development Cycle
Lines of code can be re-used; don’t have to be repeated
Can be tested/improved independently of program Analyze problem: define problem, record program
Easy to share procedures/functions with other programs specifications and recognize inputs, process, output & UI

WWW.ZNOTES.ORG Copyright © 2024 ZNotes Education & Foundation. All Rights Reserved. This document is authorised
for personal use only by David Liu at undefined on 14/05/24.
CAIE AS LEVEL COMPUTER SCIENCE

Design program: develop logic plan, write algorithm in Purpose: used in structured programming to arrange
e.g. pseudocode or flowchart and test solution program modules, each module represented by a box
Code program: translate algorithm into high level Tree structure visualizes relationships between modules,
language with comments/remarks and produce user showing data transfer between modules using arrows.
interface with executable processes Example of a top-down design where a problem
Test and debug program: test program using test data, (program) is broken into its components.
find and correct any errors and ensure results are correct
Formalize solution: review program code, revise internal Rules:
documentation and create end-user documentation
Process: Represents a programming module e.g. a
Maintain program: provide education and support to end-
calculation
user, correct any bugs and modify if user requests

There are three different development life cycles:

Waterfall model: a classical model, used to create a


system with a linear approach, from one stage to another
Data couple: Data being passed from module to module
Iterative model: a initial representation starts with a small
that needs to be processed
subset, which becomes more complex over time until the
system is complete
Rapid Application Development (RAD) model: a
prototyping model, with no (or less) specific planning put Flag: Check data sent to start or stop a process. E.g. check
into it. More emphasis on development and producing a if data sent in the correct format
product-prototype.

4.2. Integrated Development


Selection: Condition will be checked and depending on the
Environment result, different modules will be executed

A software application that allows the creation of a


program e.g. Python
Consists of a source code editor, build automation tools, a
debugger

Coding:

Reserved words are used by it as command prompts


Listed in the end-user documentation of IDE
A series of files consisting of preprogrammed-
subroutines may also be provided by the IDE Iteration: Implies that module is executed multiple times

Initial Error Detection:

The IDE executes the code & initial error detection carried
out by compiler/interpreter doing the following:
Syntax/Logic Error: before program is run, an error
message warns the user about this
Runtime Error: run of the program ends in an error

Debugging:

Single stepping: traces through each line of code and Example:


steps into procedures. Allows you to view the effect of
each statement on variables
Breakpoints: set within code; program stops temporarily
to check that it is operating correctly up to that point
Variable dumps (report window): at specific parts of
program, variable values shown for comparison

4.3. Structure Charts

WWW.ZNOTES.ORG Copyright © 2024 ZNotes Education & Foundation. All Rights Reserved. This document is authorised
for personal use only by David Liu at undefined on 14/05/24.
CAIE AS LEVEL COMPUTER SCIENCE

4.6. Adaptive Maintenance


Making amendments to:
Parameters: due to changes in specification
4.4. Types of Errors Logic: to enhance functionality or more faster or both
Design: to make it more user friendly
Syntax errors:

When source code does not obey rules of the language 4.7. Testing Strategies
Compiler generates error messages
Black box testing:
Examples:
Misspell identifier when calling it Use test data for which results already calculated &
Missing punctuation – colon after if compare result from program with expected results
Incorrectly using a built-in function Testing only considers input and output and the code is
Argument being made does not match data type
viewed as being in a ‘black box’
Run-time errors: White box testing:
Source code compiles to machine code but fails upon Examine each line of code for correct logic and accuracy.
execution (red lines show up in Python) May record value of variables after each line of code
When the program keeps running and you have to kill it Every possible condition must be tested
manually
Examples: Stub testing:
Division by 0
Infinite loop – will not produce error message, Stubs are computer programs that act as temporary
program will just not stop until forced to replacement for a called module and give the same
output as the actual product or software.
Logic errors: Important when code is not completed however must be
tested so modules are replaced by stubs
Program works but gives incorrect output
Examples: Dry run testing:
Out By One – when ‘>’ is used instead of ‘>=’
Misuse of logic operators A process where code is manually traced, without any
software used
The value of a variable is manually followed to check
4.5. Corrective Maintenance whether it is used and updated as expected
Used to identify logic errors, but not execution errors
Corrective Maintenance is correcting identified errors
White-Box testing: making sample data and running it Walkthrough testing:
through a trace table
Trace table: technique used to test algorithms; make sure A test where the code is reviewed carefully by the
that no logical errors occur e.g. developer’s peers, managers, team members, etc.
It is used to gather useful feedback to further develop the
code.

Integration testing:

Taking modules that have been tested on individually and


testing on them combined together

WWW.ZNOTES.ORG Copyright © 2024 ZNotes Education & Foundation. All Rights Reserved. This document is authorised
for personal use only by David Liu at undefined on 14/05/24.
CAIE AS LEVEL COMPUTER SCIENCE

This method allows all the code snippets to integrate with the developer.
each other, making the program work. Basically another term for ‘second round of testing’

Alpha testing: Acceptance testing:

This is the testing done on software ‘in-house’, meaning it A test carried out by the intended users of the system: the
is done by the developers people who requested the software.
Basically another term for ‘first round of testing’ The purpose is to check that the software performs
exactly as required.
Beta testing: The acceptance criteria should completely be satisfied for
the program to be released.
This is the testing done on the software by beta users,
who use the program and report any problems back to

WWW.ZNOTES.ORG Copyright © 2024 ZNotes Education & Foundation. All Rights Reserved. This document is authorised
for personal use only by David Liu at undefined on 14/05/24.
CAIE AS LEVEL
Computer Science

© ZNotes Education Ltd. & ZNotes Foundation 2024. All rights reserved.
This version was created by David Liu on 14/05/24 for strictly personal use only.
These notes have been created by Zubair Junjunia for the 2017 syllabus
The document contains images and excerpts of text from educational resources available on the internet and
printed books. If you are the owner of such media, test or visual, utilized in this document and do not accept its
usage then we urge you to contact us and we would immediately replace said media.
No part of this document may be copied or re-uploaded to another website. Under no conditions may this
document be distributed under the name of false author(s) or sold for financial gain.
“ZNotes” and the ZNotes logo are trademarks of ZNotes Education Limited (registration UK00003478331).

You might also like