CodeIEB
Theory Notes/๐Ÿ—„๏ธ Topic 4: Data & Information Management, Solution Development/12.4.8
12.4.8Grade 12

Algorithms on Collections of Objects

Applying the searching/sorting/manipulation algorithms from 11.4.8, now specifically to arrays of objects and extended/inherited objects.

This subtopic doesn't introduce new algorithms โ€” it's about correctly applying search, sort, insert, delete and related array manipulation techniques (11.4.8) to more complex data:

  • Arrays of objects โ€” e.g. sorting an array of Learner objects by their average mark field, rather than sorting simple integers.
  • Extended (inherited) objects โ€” e.g. searching through a mixed array of superclass-typed objects that are actually various subclasses.

Example

// Selection sort adapted to sort an array of Learner objects by average for (int i = 0; i < learners.length - 1; i++) { int minIndex = i; for (int j = i + 1; j < learners.length; j++) { if (learners[j].getAverage() < learners[minIndex].getAverage()) { minIndex = j; } } Learner temp = learners[minIndex]; learners[minIndex] = learners[i]; learners[i] = temp; }

๐Ÿ’ก Exam Tip

When adapting an algorithm you already know to work on objects, the core algorithm structure barely changes โ€” the only real change is comparing a specific FIELD of each object (e.g. .getAverage()) instead of comparing simple values directly.