MATSEC SEC Computing study materials
MATSEC SEC Computing study resources

The 420 Exam Marks Before the Deadline

MATSEC SEC Computing · Put your knowledge to work in context.

All case studies

The 420 Exam Marks Before the Deadline

A teacher at a Maltese college has a spreadsheet of 420 exam marks, one per student, entered in the order students sat the exam. The marks are whole numbers from 0 to 100, and some cells contain 'ABS' for absent students. The teacher must produce a rank order, find the median mark, and check whether any two students have exactly the same mark. A colleague suggests sorting the list and then using a binary search to find the median. The teacher also wants to find a specific student's mark by name, and the names are currently unsorted. The exam board requires that absent students are excluded from the median but shown in the rank order with a dash. The teacher has 15 minutes before the results must be submitted.

1. Evaluate the colleague's suggestion to sort the list and then use a binary search to find the median. Consider the 420 records, the 'ABS' entries, and what the median actually requires.

Read the worked answer

The suggestion contains a conceptual error. Once a list is sorted, the median is found by position, not by searching for a value. For an odd number of valid marks, the median is the middle element; for an even number, it is the average of the two middle elements. Binary search is for locating a known target in sorted data, so using it to 'find the median' is unnecessary. The teacher should simply index the sorted list.

Sorting 420 items is inexpensive. A comparison sort such as merge sort does on the order of n log n comparisons, roughly 420 × 9 ≈ 3,800, which is trivial. The real issue is handling 'ABS'. If 'ABS' is left in the list as text, sorting may place it inconsistently or fail in a numeric sort, and including it as zero would distort the median. The teacher must filter absent students out of the median calculation while keeping them in the rank order with a dash. A separate list of valid numeric marks is the simplest approach.

The colleague's method is therefore not harmful at this size, but it is logically wrong and adds a step. The correct reasoning is: filter, sort, index the middle. At 420 records, clarity and correctness matter more than algorithmic sophistication.

2. Design an algorithm, in structured English or pseudocode, that takes the 420 records and produces the median of valid marks and a list of duplicate marks. Explain how you handle 'ABS' and why your duplicate method is suitable at this size.

Read the worked answer

One suitable algorithm is:

valid = []
counts = empty dictionary
duplicates = empty set
for each record in the 420 records:
    if record.mark == 'ABS':
        continue
    valid.append(record.mark)
    if record.mark in counts:
        duplicates.add(record.mark)
    counts[record.mark] = counts.get(record.mark, 0) + 1
sort valid
n = length(valid)
if n is odd:
    median = valid[n // 2]
else:
    median = (valid[n // 2 - 1] + valid[n // 2]) / 2

'ABS' is skipped rather than converted to 0, because converting it would pull the median downwards and misrepresent the cohort. The absent students remain in the separate rank-order output with a dash. Duplicate detection uses a dictionary, so each mark is checked in average constant time and the whole pass is O(n). At 420 records this is trivial and avoids a second sort. An alternative is to sort the valid marks and compare adjacent values, which is also acceptable at this size. The dictionary approach is chosen because it detects duplicates during the same pass that builds the median list, reducing the chance of inconsistency before the deadline.

3. The teacher also needs to look up a named student's mark and may repeat this lookup many times. Compare keeping the names unsorted and using linear search with sorting by name and using binary search. Recommend one approach for this specific situation and justify it.

Read the worked answer

Linear search checks names one by one. With 420 records, the average successful lookup examines about 210 names and the worst case 420. For a handful of lookups this is negligible. It also works on the data exactly as entered and carries no risk of separating names from marks.

Sorting by name and using binary search costs O(n log n) once, roughly 3,800 comparisons, and then about 9 comparisons per lookup. The break-even point is several hundred lookups; below that, the sort dominates. Sorting also introduces a practical risk in a spreadsheet: if only the name column is sorted, marks become attached to the wrong students. Any sort must move whole records together. 'ABS' entries also need to remain aligned.

For this teacher, with 15 minutes and a one-off results task, linear search or a spreadsheet filter/lookup is the better recommendation. It is adequate at n = 420, easier to verify, and less error-prone under time pressure. Sorting by name is justified only if the teacher expects to perform many repeated lookups, for example when entering late results over several days. The decision should be based on the number of expected searches, not on the theoretical superiority of binary search.