## General advice
- Do not use a subprogram unless you are told to.
- Watch out for spaces in identifiers. They will cost your marks.
- Don't ever increment the `count` inside a `for` loop.
- Writing prompts in `input()` statements is a waste of time unless the question tells you otherwise.
- Don't forget to start subprogram definitions with `def`.
## 11
### a.i
Fine. NB the command word: [[state]]. Brevity.
### a.ii
Fine.
### b
Some attempts at iterating over 2D arrays were problematic. This is something many need to practice.
Be careful if you are using a Pythonic `for` loop:
```python
for item in items:
...
```
where `item` represents the inner-array, so you access its contents by indexing from it directly, e.g., `item[0]` and not `item[0][1]`. `item[0][1]` would access the character at index 1 of the string at index 0—which is not what we want.
I would do it like this:
```python
empty = True
for item in p1Items:
if item[0] != "empty":
empty = False
if empty:
print("No items found")
```
alternatively:
```python
empty = True
for i in range(len(p1Items)):
if p1Items[i][0] != "empty":
empty = False
if empty:
print("No items found")
```
NB my use of a flag variable rather than counting the number of items. The question doesn't require a count, just a simple presence check[^1].
## 12
This question was poorly answered.
Trees can be weighted so you should never write "graphs can be weighted but trees can't be" as a distinguishing point between graphs and trees. This point was credited on older mark schemes but is no longer recognised as correct by OCR.
Your language must be precise for a question like this. Rather than describing the parent/child relationship of trees, describe it as **hierarchy**. Rather than loosely describing the fact that some nodes don't have to link to other nodes in a graph, say that graphs can be **disconnected**.
NB trees having leaves is not a defining characteristic. It is also untrue that tree nodes can have at most two children—this is true of binary trees, but not all trees.
Common misconception: trees are not directed; trees are actually always undirected!
Be precise in your language: "graphs are cyclical" is different to "graphs can be cyclical." I can be pedantic but I am not always pedantic[^2].
## 13
Responses to this question suggest a lack of understanding about how binary search trees work. When searching a binary search tree (BST), no time is ever wasted exploring irrelevant branches. Instead, you perform a binary search down the BST, discarding one half of the tree at a time. The problem with an unbalanced BST is that you end up discarding less than half of the tree each time, which in its absolute worst case makes the search take as long as a linear search (e.g., when the tree is equivalent to a linked list).
Remember that OCR are fussy about language: "takes more time" and "slower" are not the same thing. Saying something is "slower" is rarely credited. Think of it like this: there is nothing operationally slower about searching a balanced vs an unbalanced BST: a single comparison in an unbalanced BST is no slower than one in a balanced BST. However, an unbalanced BST may require more comparisons to find the search term, so the search takes more time overall.
NB this question is generic so reference to the diagram is not required (in fact, it is actively unhelpful: nothing is meaningful about the "left" side of a generic BST).
While this question is worded as [[describe]], it feels more [[explain]] to me.
## 14
This question was answered poorly due to poor understanding of the key knowledge required. Poor knowledge means poor application, which leads to poor evaluation, which results in a poor mark. Often, attempts at evaluation were absent or fleeting.
The question specifically mentions post-order traversals. Post-order traversals were frequently performed incorrectly; breadth-first searches were generally done correctly.
Many attempts at demonstrating depth-first traversals seem to use algorithms invented on the spot.
Very few people annotated the tree given in the question to aid them in performing a post-order traversal. Annotating the diagram can help you:
- write the correct order; and
- construct an accurate description of the way the algorithm works if you don't have it memorised.
When it comes to evaluating algorithms, saying that an algorithm is easier to understand or easier to implement is rarely going to get much credit. When evaluating algorithms, we care about efficiency (not speed!) in different scenarios. Specifically, we care about time to execute and how much memory an algorithm uses.
```mermaid
graph TD
A[2005] --> B[1920]
A --> C[2350]
B --> D[1500]
B --> E[1985]
C --> F[2100]
C --> G[2560]
E --> H[1952]
E --> I[2000]
```
|Order|Result|
|---|---|
|Pre-order|2005, 1920, 1500, 1985, 1952, 2000, 2350, 2100, 2560|
|In-order|1500, 1920, 1952, 1985, 2000, 2005, 2100, 2350, 2560|
|==Post-order==|==1500, 1952, 2000, 1985, 1920, 2100, 2560, 2350, 2005==|
|==Breadth-first==|==[2005], [1920, 2350], [1500, 1985, 2100, 2560], [1952, 2000]==|
## 15
### a
Everyone got full marks. Good.
### b
Some odd attempts with the first gap. Some people wrote `5` which is just incorrect—the question clearly describes an array of 20 elements. I would guess that `5` is a hangover from the previous question.
Remember that arrays are 0-indexed so the maximum index is `19` and not `20`.
If you are going to use `len()` or `.length()`, make sure you do it correctly!
The last three gaps were filled in correctly by most.
### c
This question was answered poorly. What it wants you to do is actually very simple but it requires thinking across the different questions parts—it is a good example of a real multi-part exam question.
Read the question very carefully. It describes `pop()` and `push()` but only tells you to write the main program. This means you can assume `pop()` and `push()` are already implemented. From the previous part and this question, we know that pointer updates are handled—so the main program should not touch the pointer.
NB that we are told `pop()` and `push()` are functions—they are not stack methods, so dot notation is inappropriate (but I credited it when used plausibly).
We are told the main program should use `pop()` to output, and we are also told that `pop()` returns a value. This means we need to handle the output ourselves.
```python
for i in range(10):
c = input()
push(c)
for i in range(10):
print(pop()) # rather than just pop() which would not be output
```
## 16
The easiest way to answer a [[describe]] question that asks you to describe the steps of an algorithm over given data is to treat it like a show question and liberally annotate. The annotations are essential as it is still a describe question.
Insertion sort and bubble sort are not the same thing. Many need to study insertion sort.
Talking about 'swapping' is risky with insertion sort as values are not swapped. They are inserted into their correct, sorted position—hence 'insertion' sort.
## 17
### a.i
Very few got the mark for the private attributes. Private attributes must be shown using double underscores or comments when writing Python. Single underscores are not acceptable with OCR mark schemes.
When it says to make a `new()` method, this means the constructor—which in Python is `__init__()`.
Remember to define the class!
```python
class Treasure: # this line is needed to define the class
def __init__(self, p_value, p_level):
self.__value = p_value
self.__level = p_level
```
### a.ii
Please remember to write `def`.
Don't return `p_level`. That isn't the attribute.
### a.iii
Several described encapsulation without naming it which meant were not able to get full marks.
Some just described what the get method does—which isn't what the question asked.
Some incorrectly identified it as 'data hiding'—they key term you need to know is 'encapsulation.'
### b
Many got the third gap wrong. Common incorrect answers:
- Board
- Array_of_Treasure (or some variant of this)
- Treasure
### c
This question was poorly answered.
This question requires careful synthesis of information from all the previous parts. This is typical of real multi-part A-level exam questions.
All the methods introduced in the previous parts must be used here. We need to use the getters and setters as all the attributes are private—so directly accessing the attributes doesn't work.
```python
def guessGrid(board):
x = int(input())
y = int(input())
item = board.getGridItem(x, y)
if item.getLevel() == "":
print("No treasure")
else:
print(f"level: {item.getLevel()}; value: {item.getValue()}")
```
## 18
I have nothing to add outside the examiner commentary.
## Notes
[^1]: Why use many code when few code do trick?
[^2]: Ha.