Lesson Notes By Weeks and Term v5 - Grade 11

Advanced programming: modularisation and data structures (Grade 11 focus) – Week 4 focus

Download the Lessonotes Mobile South Africa app for faster lesson access on Android and iPhone.

Subject: Information Technology

Class: Grade 11

Term: 3rd Term

Week: 4

Theme: General lesson support

Lesson Video

This page supports the lesson note with a companion video and a short classroom-ready summary.

For class groups and homework, share this lesson page so learners also get the summary, objectives, and full lesson context.

Performance objectives

Lesson summary

This week, we delve deeper into advanced programming concepts, focusing specifically on modularization and data structures. These are crucial skills for any aspiring programmer, allowing you to build complex and maintainable software applications. Imagine trying to build a house without a blueprint or standardized building blocks – it would be chaotic and prone to collapse! Similarly, without modularization and appropriate data structures, your code becomes unmanageable, difficult to debug, and challenging to extend. Think about the SARS eFiling system or a banking app used by millions of South Africans.

Lesson notes

Modularization Modularization is the process of breaking down a large, complex program into smaller, independent, and reusable modules (or functions/procedures). This makes the code easier to understand, debug, maintain, and reuse. Imagine each module as a specialist in a particular task, collaborating to achieve the overall goal.

Benefits of Modularization: Improved Readability: Smaller modules are easier to understand than a single, monolithic block of code.

Reduced Complexity: Dividing the problem into smaller parts simplifies the overall development process.

Increased Reusability: Modules can be reused in different parts of the program or in other programs. This saves time and effort. For example, a module that validates a South African ID number could be used in various applications.

Easier Debugging: Errors are easier to locate and fix in smaller, self-contained modules.

Team Collaboration: Modularization allows different developers to work on different modules simultaneously.

Maintainability: Changes or updates to one module are less likely to affect other parts of the program.

Example (Python): ```python def calculate_average(numbers): """Calculates the average of a list of numbers.""" if not numbers: return 0 # Avoid division by zero total = sum(numbers) average = total / len(numbers) return average def find_maximum(numbers): """Finds the maximum value in a list of numbers.""" if not numbers: return None # Handle empty list case maximum = numbers[0] for number in numbers: if number > maximum: maximum = number return maximum Main program student_marks = [75, 82, 90, 68, 88] average_mark = calculate_average(student_marks) highest_mark = find_maximum(student_marks) print(f"The average mark is: {average_mark}") print(f"The highest mark is: {highest_mark}") ``` Explanation: The code is divided into two modules: `calculate_average` and `find_maximum`. Each module performs a specific task. The `main` part of the program calls these modules to perform the calculations. Each module handles the case of an empty list to prevent errors.

Data Structures: Arrays (Lists) A data structure is a particular way of organizing and storing data in a computer so that it can be used efficiently. An array (or list in Python) is a fundamental data structure that stores a collection of elements of the same data type in contiguous memory locations.

Key characteristics of Arrays/Lists: Ordered: Elements have a specific order and can be accessed by their index (position).

Mutable (in Python): Elements can be modified after the array/list is created. Homogeneous (Ideally, but Python allows mixed types): Although Python lists technically allow different data types, it's generally good practice to store elements of the same type for consistency and efficiency.

Example (Python): ```python Creating a list of student names student_names = ["Ayanda", "Bongani", "Chantelle", "David", "Emily"] Accessing elements by index print(student_names[0]) # Output: Ayanda print(student_names[2]) # Output: Chantelle Modifying an element student_names[1] = "Busi" print(student_names) # Output: ['Ayanda', 'Busi', 'Chantelle', 'David', 'Emily'] Adding elements student_names.append("Farouk") print(student_names) # Output: ['Ayanda', 'Busi', 'Chantelle', 'David', 'Emily', 'Farouk'] Length of the list print(len(student_names)) # Output: 6 ``` Searching Algorithms: Linear Search A searching algorithm is a method for finding a specific element within a data structure. Linear search is the simplest searching algorithm. It iterates through each element of the array/list, comparing it to the target value until a match is found or the end of the list is reached.

Example (Python): ```python def linear_search(list_data, target): """Performs a linear search on a list.""" for index, element in enumerate(list_data): if element == target: return index # Return the index if found return -1 # Return -1 if not found Example usage numbers = [10, 25, 5, 30, 15] target_number = 30 index = linear_search(numbers, target_number) if index != -1: print(f"Target {target_number} found at index {index}") else: print(f"Target {target_number} not found in the list") ``` Explanation: The `linear_search` function iterates through the `list_data`. For each element, it checks if it matches the `target`. If a match is found, the function returns the index of the element. If the target is not found after iterating through the entire list, the function returns -

1. Sorting Algorithms: Bubble Sort A sorting algorithm is a method for arranging the elements of a data structure in a specific order (e.g., ascending or descending). Bubble sort is one of the simplest sorting algorithms. It repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order. The larger elements "bubble" to the end of the list with each pass.