CAIE-A2 Level-Computer Science - Practical
CAIE-A2 Level-Computer Science - Practical
ORG
CAIE A2 LEVEL
COMPUTER SCIENCE
SUMMARIZED NOTES ON THE THEORY SYLLABUS
Prepared for Viduranga for personal use only.
CAIE A2 LEVEL COMPUTER SCIENCE
The binary search algorithm has a Big O notion of O(log n).
Python Code
Algorithms
def binary_search(arr, target):
Part of the Computational Thinking and Problem-Solving
Chapter low, high = 0, len(arr) - 1
WWW.ZNOTES.ORG Copyright © 2024 ZNotes Education & Foundation. All Rights Reserved. This document is
authorised for personal use only by Viduranga at Royal Institute on 09/12/24.
CAIE A2 LEVEL COMPUTER SCIENCE
Popping (pseudocode)
WWW.ZNOTES.ORG Copyright © 2024 ZNotes Education & Foundation. All Rights Reserved. This document is
authorised for personal use only by Viduranga at Royal Institute on 09/12/24.
CAIE A2 LEVEL COMPUTER SCIENCE
Interrupt Handling
The contents of the register and the PC are saved and 2.3. Linked Lists
put on the stack when the interrupt is detected
The return addresses are saved onto the stack as well
Retrieve the return addresses and restore the
register contents from the stack once the interrupt
has been serviced
Evaluating mathematical expressions held in Reverse
Polish Notation
Procedure Calling
Every time a new call is made, the return address
must be stored
Return addresses are recalled in the order ‘the last
one stored will be the first to be recalled.’
If there are too many nested calls, then stack
overflow
2.2. Queues
WWW.ZNOTES.ORG Copyright © 2024 ZNotes Education & Foundation. All Rights Reserved. This document is
authorised for personal use only by Viduranga at Royal Institute on 09/12/24.
CAIE A2 LEVEL COMPUTER SCIENCE
Binary Tree
START at Root Node
REPEAT
IF WantedItem = ThisItem
ELSE
3. Recursion
Part of the Computational Thinking and Problem-Solving
Chapter
WWW.ZNOTES.ORG Copyright © 2024 ZNotes Education & Foundation. All Rights Reserved. This document is
authorised for personal use only by Viduranga at Royal Institute on 09/12/24.
CAIE A2 LEVEL COMPUTER SCIENCE
Advantages Disadvantages
Less efficient in terms of Objects: Instances of classes representing real-world
Can produce simpler, more entities.
computer time and storage
natural solutions to a problem Properties/Attributes: The data items/attributes and
space
A lot more storage space is the data types // characteristics defined in a class.
used to store return addresses Methods: the procedures/ functions / programmed
and states. instructions in a class that act on the
This could lead to infinite properties/attributes.
recursion. Classes: Blueprint for creating objects with shared
attributes and methods.
3.3. How A Compiler Translates Inheritance: It is a mechanism for creating a new class
based on an existing one, inheriting its attributes and
Recursive Programming Code methods. Through inheritance, attributes contained in
one class (parent class) are made available to / reused by
Before the procedure call is executed, the current state of another class (child class).
the registers/local variables is saved onto a stack. Polymorphism: Ability to use different classes through a
When returning from a procedure call, the registers/local common interface. It allows the same method to take on
different behaviours depending on which class is
variables are re-instated on the stack
instantiated. These methods can be redefined for
When the stopping condition/base case is met, the
derived classes.
algorithm unwinds the last set of values that are taken
off the stack (in reverse order) Containment (Aggregation): Combining multiple
objects to create a more complex object.
Encapsulation: Hiding the internal details of a class from
4. Object-Oriented the outside.
Getters and Setters: Methods for accessing and
Programming modifying object attributes. Get methods/Getters are
used to access attributes, while set methods/setters are
Part of the Further Programming Chapter used to modify object attributes.
Instances: Individual objects created from a class.
4.1. Key Terms & Definitions
4.2. Constructor
Constructors are functions that are used for initializing the
attributes/Properties of a class.
For example:
WWW.ZNOTES.ORG Copyright © 2024 ZNotes Education & Foundation. All Rights Reserved. This document is
authorised for personal use only by Viduranga at Royal Institute on 09/12/24.
CAIE A2 LEVEL COMPUTER SCIENCE
• The child class inherits the attributes and methods of the
parent class and can also add new attributes and methods
or override the ones inherited.
In the context of the Person class, Inheritance would involve
creating a child class, such as a Student or Employee, that
inherits attributes and methods from the Person class. For
When you create an instance of the class, the constructor
example, a Student class could inherit the name and age
is invoked automatically to set the object's initial state.
attributes and the get_name method from the Person class.
This ensures that objects are created in a valid and
consistent state. Polymorphism
4.3. Defining Classes and Methods • Polymorphism is the ability of different classes to be
treated as instances of a common base class. It allows
• To define a class in Python, use the class keyword followed objects of different classes to be used interchangeably if
by the class name. they implement the same methods or interface.
• Inside the class, you can define attributes (variables) and • Polymorphism promotes flexibility and extensibility in your
methods (functions) that belong to the class. code.
Here's a simple example of defining a class called Person In the context of the Person class, Polymorphism could be
with attributes and methods as shown below: applied when you have different types of persons, such as
students, employees, and teachers, each having a get_name
method. You can call get_name on instances of these
different classes without knowing their specific type, as long
as they all have a get_name method.
Encapsulation
• Encapsulation is the practice of hiding the internal details
of a class and providing a controlled interface to access and
modify the class's attributes.
• This helps maintain the integrity and consistency of the
4.4. Get and Set Methods object's state by controlling how data is accessed and
modified.
These methods are used to access/change attributes set to In the context of the Person class, Encapsulation is applied
be private in a class. These methods are decelerated inside by making the name attribute private (by convention, using a
the class. leading underscore). This indicates that __name it should not
be accessed directly from outside the class. Instead, you
provide a controlled interface through the get_name and
set_name methods, ensuring that name changes are
validated and controlled.
Below is a brief code example illustrating how inheritance,
polymorphism, and encapsulation could be applied to the
Person class:
4.5. Inheritance
• Inheritance is a fundamental concept in OOP that allows
you to create a new class (a derived or child class) based on
an existing class (a base or parent class).
WWW.ZNOTES.ORG Copyright © 2024 ZNotes Education & Foundation. All Rights Reserved. This document is
authorised for personal use only by Viduranga at Royal Institute on 09/12/24.
CAIE A2 LEVEL COMPUTER SCIENCE
WWW.ZNOTES.ORG Copyright © 2024 ZNotes Education & Foundation. All Rights Reserved. This document is
authorised for personal use only by Viduranga at Royal Institute on 09/12/24.
CAIE A2 Level
Computer Science
© ZNotes Education Ltd. & ZNotes Foundation 2024. All rights reserved.
This version was created by Viduranga on Mon Dec 09 2024 for strictly personal use only.
These notes have been created by Ashmit Bhola for the 2024-2025 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).