COMP1000 Week 10

  • Week 10 content focuses on arrays of arrays and arrays of objects. These structures are essential for handling more complex data arrangements and are frequently used in algorithm design.

  • Nested loops are loops inside other loops, often used for patterns, grids, and 2D arrays. They allow you to iterate over each element in a multi-dimensional structure.

    • The outer loop is the first loop, and the inner loop is inside the outer loop. The outer loop controls the rows, while the inner loop typically handles the columns in a grid or 2D array.

    • Be careful not to mix up indices in nested loops. Ensure that the loop variables are correctly used to access the intended elements.

  • Arrays are compound data types with a reference to memory, a length, and elements of the same type. Understanding how arrays are stored in memory is crucial for optimizing performance and avoiding common pitfalls.

    • Arrays can be of any type, including arrays of arrays (2D arrays). This flexibility allows for creating highly structured and organized data storage.

    • 2D arrays are arrays of arrays. They are particularly useful for representing matrices or tables.

    • The arrays inside the array don't have to have the same length. This is known as a jagged array, and it provides flexibility in memory usage.

  • Common mistakes with arrays include mixing up indices, off-by-one errors, and hard-coded boundaries. Always validate your indices against the array length to prevent runtime exceptions. Use variables instead of hard-coded values for array boundaries to make your code more maintainable.

  • Arrays of objects: alias (arrays) can be of any type including object. This is a powerful feature, allowing you to create complex data structures by combining objects.

    • You can have arrays of objects (e.g., an array of Disk objects). Each element in the array holds a reference to an object.

    • It's important to instantiate objects within the array using new. Without instantiation, you'll have an array of null references, leading to NullPointerExceptions when you try to access their methods or fields.

    • Methods can take arrays of objects as arguments. This allows you to perform operations on multiple objects in a structured manner.

    • The keyword this refers to the object's own reference. It's used to access the object's attributes and methods from within the object itself.

  • When avoiding objects make sure they are not themselves by either excluding when the indexes are the same, or using some metric (distance) to avoid a division by zero error. This is especially important in geometric or mathematical computations.

  • Practice quiz: Opens soon with a mixture of multiple choice and CodeLiner questions. Practice quizzes are designed to help you assess your understanding of the material and prepare for the summative assessment.

  • Summative assessment: during the SGTAs, 10 questions + 1 bonus. The summative assessment will test your ability to apply the concepts learned in this week's content.

  • Viva: during week 12 and 13. The viva is an oral examination that provides an opportunity to discuss your understanding of the material in more detail.