A Practical ZNotes
A Practical ZNotes
ORG
CAIE A2 LEVEL
COMPUTER
SCIENCE
SUMMARIZED NOTES ON THE PRACTICAL SYLLABUS
Prepared for SDKLyrics JR for personal use only.
CAIE A2 LEVEL COMPUTER SCIENCE
Python Code
1. Sorting and Searching def binary_search(arr, target):
low, high = 0, len(arr) - 1
Algorithms while low <= high: mid = (low + high) // 2 mid_element =
arr[mid]
Part of the Computational Thinking and Problem-Solving
Chapter if mid_element == target:
return f"Item {target} found at index {mid}."
elif mid_element < target:
1.1. Linear Search low = mid + 1
else:
How does it work?
high = mid - 1
The user is asked to enter an item they want to find in an
return f"Item {target} not found in the array."
array.
All elements of an array are searched one by one until the
item the user entered is found. ## 1.3. Bubble Sort
When an item is found, the algorithm outputs an
appropriate message saying that the item is found and ### How Does It Work?
which index/location the item is at.
If the particular item is not found, the algorithm outputs * Bubble sort compares adjacent elements in the list/array
an appropriate message saying that the item is not found. * They are swapped if the elements are in the wrong order
* The algorithm iterates through the array multiple times i
The linear search algorithm has a Big O notion of O(n).
* On each pass, the largest unsorted element "bubbles up"
* The process is repeated until the entire array is sorted.
Python Code
### Python Code
WWW.ZNOTES.ORG Copyright © 2024 ZNotes Education & Foundation. All Rights Reserved. This document is authorised
for personal use only by SDKLyrics JR at DPS International, Gurgaon on 25/08/24.
CAIE A2 LEVEL COMPUTER SCIENCE
Front = 1
**Part of the Computational Thinking and Problem-Solving Chapter**
Rear = 6
## 2.1. Stacks
NumberInQueue := 0
* Stack – an ADT where items can be popped or pushed from the top of the stack only
* LIFO – Last In First Out data structure
END PROCEDURE
```
### **Popping (pseudocode)**
* **To add an Element to the Queue (pseudocode):**
ENDPROCEDURE
**<span class="underline">Use of Stacks:</span>**
```
* **Interrupt Handling** * The front of the queue is accessed through the pointer Fr
* To add an element
* The contents of the register and the PC are saved and put on the stack when thetointerrupt
the queue, the pointers have to be
is detected
* The return addresses are saved onto the stack as well * In some implementations, two pointers are kept: 1 to the
* Retrieve the return addresses and restore the register contents from the stack once the interrupt has been serviced:
* To Remove an Item from the Queue **(pseudocode)**
* **Evaluating mathematical expressions held in Reverse Polish Notation**
WWW.ZNOTES.ORG Copyright © 2024 ZNotes Education & Foundation. All Rights Reserved. This document is authorised
for personal use only by SDKLyrics JR at DPS International, Gurgaon on 25/08/24.
CAIE A2 LEVEL COMPUTER SCIENCE
\
FOR Index ← 1 TO 49

* When you create an instance of the class, the constructo
## 3.1. Essential Features of a Recursion • Inside the class, you can define attributes (variables) and
* Must have a base case/stopping condition Here's a simple example of defining a class called Person w
* Must have a general case which calls itself (recursively) // Defined in terms of itself
* The general case should be changing its state and move toward  based on an existing class (a base or parent
Before the procedure call is executed, the current state of the •registers/local
The child class
variables
inherits is
the
saved
attributes
onto aand
stack.
methods of the
attributes and methods or override the ones inherited.
* When returning from a procedure call, the registers/local variables are re-instated on the stack
* When the stopping condition/base case is met, the algorithmInunwinds
the context
the last
of the
setPerson
of values
class,
that
Inheritance
are taken off
would
the involv
stack
**Part of the Further Programming Chapter** • Polymorphism is the ability of different classes to be trea
## 4.1. Key Terms & Definitions • Polymorphism promotes flexibility and extensibility in yo
 or sold for financial gain.
“ZNotes” and the ZNotes logo are trademarks of ZNotes Education Limited (registration UK00003478331).