To set your students up for success on the Algorithm Performance Profiler task (Digital Technologies 3.7 / AS91906), here is a breakdown of the key concepts and Python skills to review with them, structured from foundational refreshers to complex techniques.
Since students may be rusty on basic constructs, brief revision on the following core elements is recommended:
Control Structures & Loops:
while loops for creating persistent main application menus.
Nested for loops for basic sorting logic (e.g., iterating through an array to compare and swap elements).
Data Types & Data Structures:
Manipulating Python list objects (.append(), .copy(), len()).
Understanding scalar data types (strings, integers, floats) and working with list copies (e.g., list.copy()) to preserve the original unsorted dataset across multiple algorithm test runs.
Timing & Randomization:
Generating synthetic test datasets using random.randint().
Measuring elapsed execution time using the time module (start_time = time.time()).
Functions are key to structuring clean, readable code and avoiding duplication:
Function Definitions & Arguments: Passing list datasets into functions and returning values or modifying lists in-place.
Scope & Encapsulation: Understanding local vs. global variable scope to prevent unintended state side-effects during benchmarking.
Modularizing Repetitive Logic (Merit/Excellence Pathway): Abstracting common routines (such as dataset generation or timing execution) into helper functions rather than repeating code blocks for each algorithm.
A. Persistent Storage (csv module)
Writing Data: Using open(), csv.writer(), writerow(), and writerows() to log benchmark parameters (Dataset_Size, Algorithm_Name, Execution_Time).
Reading Data: Opening existing log files, parsing rows with csv.reader(), skipping header rows (next(reader)), and casting string fields back to numerical types (int(), float()).
Context Managers: Best practice for file handling using with open(...) as file: to manage file streams cleanly.
B. Third-Party Libraries & Data Visualization
matplotlib.pyplot: Constructing line plots (plt.plot()), setting chart metadata (plt.title(), plt.xlabel(), plt.ylabel(), plt.legend()), and displaying graphics with plt.show().
pandas (Optional for Excellence): Reading CSV files into DataFrames (pd.read_csv()) and grouping data dynamically (df.groupby()) to plot multiple series cleanly.
To help students target higher achievement bands, highlight how to make their applications resilient:
Input Validation: Trapping user entries with try/except blocks or validation loops (e.g., handling non-numeric menu input gracefully instead of letting the application throw a ValueError).
File Handling Traps: Catching FileNotFoundError or PermissionError when reading/writing CSV log files to prevent unexpected application crashes.
Review how to construct and document tests according to the NCEA marking schedule criteria:
Expected Cases: Baseline tests using standard random integer datasets (e.g., N = 100, 1000).
Boundary Cases: Operational limits, such as minimal arrays (N = 0, 1) or high upper boundaries before performance degradation occurs.
Invalid/Unexpected Cases: Error handling for invalid menu entries, missing CSV files, or corrupted log data.
Would you like me to draft a student-facing review worksheet/starter guide or help create a sample solution template for any specific achievement level (Achieved, Merit, or Excellence)?