Sparklabs Learning
ClassesSearchPrintable packs
Back to SS 3 First Term
Full packLearner notesTeacher plansCurriculum onlyInclude all weeks

Sparklabs Learning / Digital Technology

SS 3 First Term

Week 3: Functions, Arrays and Data Structures

School
Creative Brains Academy
Subject
Digital Technology
Pack
Learner notes
Prepared
7 November 2026

Week index

  1. 01Senior Review and Computational Problem Solving
  2. 02Advanced Programming
  3. 03Functions, Arrays and Data Structures
  4. 04Object-Oriented Programming
  5. 05Database Systems
  6. 06Computer Networks and Internet Technologies
  7. 07Web Development and Web Design
  8. 08Software Development Life Cycle
  9. 09Electronic Commerce
  10. 10Cyber Security and Emerging Digital Technologies
  11. 11Revision
  12. 12Examination

Week 3 / First Term

Functions, Arrays and Data Structures

Monday 21 September 2026 to Friday 25 September 2026

Lesson notes

Learning Objectives

  • Use arrays and lists to store many values.
  • Write functions that process lists.
  • Explain searching and sorting algorithms.
  • Use structured programming and the SDLC in overview.

Arrays and Lists in Detail

Real-world data is almost always a collection. A school holds lists of students, subjects, fees and scores; a bank holds lists of transactions; a clinic holds lists of patients. Without lists a program could only handle one value at a time. An array or list is an ordered collection of values stored under one variable name. Each value is an element, and each element is identified by its index, the position number. In JavaScript, lists are written with square brackets and indexing starts at zero, so in the list [78, 85, 92, 60, 74] the first element (index 0) is 78 and scores[2] returns 92. The list name, scores, is a single variable that silently holds five values, which is far more practical than writing five separate variables for forty-five students.

Common list operations make the idea concrete. Creating a list uses square brackets and commas. Reading an element uses the index inside brackets such as names[0]. Changing an element assigns a new value such as names[1] = Obinna. Adding to the end uses the push method. The length property returns how many elements the list holds, and a for loop can visit every element in order. The natural way to process a whole list is iteration. A for loop runs the index i from 0 to one less than the length, and inside the loop scores[i] reaches each element in turn, adding it to a running total. After the loop ends, dividing by the length gives the average. This one pattern, loop through a list and accumulate, powers most real data-processing programs.

Functions That Process Lists

A function can receive a list as a parameter, just like any other value, and can loop through the list to compute a result. A function such as computeAverage(scores) sums every element with a for loop and returns total divided by scores.length. Parameters are the names in the definition; arguments are the actual values passed when the function is called. A function may also be given a default value, so a caller can omit the argument when the default is acceptable. A function can return a list containing several results, which the caller unpacks, and this is how one function provides the average, the highest and the lowest score at once.

Reuse is the power of functions. Once computeAverage or analyzeScores is written, it can be called with any suitable list. For three classes the same function runs three times with different data, once per class, without copying or changing the code. The same logic is written once and executes for every class, every term and every dataset the school will ever feed to it. This is why functions are the natural unit of decomposition, each one small, named and reusable, directly continuing the computational thinking of Week 1.

Searching, Sorting and Why Data Structures Matter

A data structure is a way of organising data so that operations on it are efficient. The same data can be stored in different structures, and the choice affects how fast a program can search, sort or update it. For small lists in school exercises the difference is negligible, but for a bank holding millions of transactions or a clinic holding thousands of patient records the choice can mean seconds instead of hours. Linear search is the simplest search method. It checks each element one by one from the beginning until it finds the target or reaches the end. Its main limitation is that for a very large list it may have to examine every element, which becomes slow; but for small lists it is perfectly adequate and easy to write.

A compare-and-swap sort, often called bubble sort, steps through the list repeatedly, compares neighbouring elements and swaps them whenever they are in the wrong order. Each full pass settles one more value into its final position, so the next pass can ignore it. Tracing, also called dry-running, is how learners truly understand an algorithm, writing down the list after every pass by hand. For [5, 3, 8, 1] the first pass carries 8 to the end to give [3, 5, 1, 8], the second pass gives [3, 1, 5, 8], the third pass gives [1, 3, 5, 8], and the final pass finds no swaps because the list is already sorted.

Bubble sort is not the fastest algorithm for large lists, but it is easy to understand and it demonstrates the core idea that sorting means repeatedly correcting the order until neighbour pairs are all in position. The choice of data structure and algorithm is deeply connected to the four pillars of computational thinking. Abstraction keeps only the attributes that matter, such as name and score. Pattern recognition sees the same compare-and-swap action repeated, which becomes the loop. Decomposition splits the overall task into separate functions for computing averages, sorting and searching. Algorithmic thinking designs the exact steps each function follows. In a school that must rank students by total score and then find where a specific student placed, a list of paired name-and-score records, a compare-and-swap sort and linear search work together to produce the ranked report.

Core Coding Styles and Structured Programming Principles

Good programs are not only correct; they are also easy to read, understand and change. Structured programming builds a program from clear, well-organised blocks instead of tangled jumps. Its core idea is that every program can be expressed using only three control structures: sequence (running statements one after another), selection (choosing between alternatives) and iteration (repeating a block of statements).

Clean code follows simple practices. Indentation shows which statements belong inside a loop or a decision. Descriptive names explain what a variable or function does, for example calling a variable classAverage instead of x. Short, focused functions do one job well, and comments explain why a tricky block exists rather than restating the code line by line.

Naming conventions keep a project consistent. JavaScript code in this course uses camelCase for variables and functions (computeAverage, totalScore), and CAPITAL_SNAKE_CASE for constants that never change. These habits make the difference between code that a learner can return to after a month and code that is impossible to trace. Structured, clean code is the foundation of every larger topic that follows, including functions, arrays and algorithms.

Sequence: run statements in order.

Selection: choose a path with if and else.

Iteration: repeat work with loops.

Use indentation and descriptive names.

Keep functions small and comments meaningful.

camelCase for variables; CAPITAL_SNAKE_CASE for constants.

Control Structures: Sequence, Selection and Iteration

Control structures decide the order in which statements run, and no program can be written without them. Sequence is the default: the program runs line by line from top to bottom, as when a program collects a student name, collects the score, then computes the average. Almost every block of real code begins with a sequence.

Selection lets a program choose between paths using conditions. The if statement checks a condition and runs its block only when the condition is true, while if else decides between two branches. Selection is what lets a search report Found or Not found, or a grading program award pass or fail based on a score.

Iteration repeats a block of statements, which is how a program processes every element of a list. A for loop with a counter visits each index, while a while loop repeats as long as a condition holds, such as reading scores until the user stops entering them. Because sequences, selections and iterations nest inside one another, tracing the control flow of a program predicts exactly what it will do.

Sequence: statements run in order.

if and if else: selection by condition.

for and while: iteration over a known or unknown number of runs.

Nesting lets small structures build complex behaviour.

Tracing control flow prevents logic errors.

The Software Development Life Cycle in Overview

Building real software is a project, not just typing code. The Software Development Life Cycle (SDLC) structures that project into phases. Planning defines the problem, the users and the goals, including budget and deadlines. Analysis studies the current situation and gathers detailed requirements, turning vague requests into a clear specification of what the software must do.

Design turns the requirements into a blueprint: the system architecture, the data structures, the modules and the user interface. Implementation is where the design becomes working code. Testing checks the software against the requirements and finds defects before the users do. Deployment releases the finished system, and maintenance keeps it working by fixing errors, adding features and adapting the software as needs change.

The SDLC is not always strictly linear. Many teams use agile approaches that repeat short cycles of plan, build, test and review, but the same activities always appear. The algorithms of this week, searching, sorting and data structures, feed directly into the analysis and design phases, because decisions about how data is organised are made before the implementation phase begins.

Planning: define the problem, users, budget and deadlines.

Analysis: gather and document the requirements.

Design: produce the architecture and data model.

Implementation: write and integrate the code.

Testing: verify the software against its requirements.

Deployment: release the working system.

Maintenance: fix, enhance and adapt the software over time.

PassComparisons and swapsList after pass
15 over 3 swap, 5 under 8 no swap, 8 over 1 swap[3, 5, 1, 8]
23 under 5 no swap, 5 over 1 swap, 5 under 8 no swap[3, 1, 5, 8]
33 over 1 swap, 3 under 5 no swap[1, 3, 5, 8]
4No swaps needed, list is sorted[1, 3, 5, 8]

Practical Work

  1. Write a function that finds the largest value in a list.
  2. Trace a linear search through a list of numbers.
  3. Sort a short list of numbers by hand using a sorting method.
  4. State one reason data structures matter.

Scenario-Based Questions

  1. A teacher stores the scores of five students in a list called scores = [72, 85, 61, 90, 54]. Write a Python function computeAverage that accepts this list, loops through it to find the sum and returns the average. Explain how 0-based indexing is used and why scores[0] gives 72.
  2. A bank stores the day's transactions in a queue. The first customer to arrive should be served first. Explain why a queue is more appropriate than a stack for this situation and describe what happens if the bank accidentally uses a stack instead.
  3. A librarian has 500 books sorted by catalogue number and needs to find whether number 347 exists. Compare linear search and binary search for this task: state the best-case and worst-case number of comparisons for each and explain why binary search is faster on sorted data.
  4. Trace the first two passes of bubble sort on the list [4, 1, 3, 2]. Show the list after each pass and state which swaps occur. Explain why bubble sort is described as a compare-and-swap algorithm.
  5. A developer has three different data storage needs: (a) the last 10 error messages displayed in reverse order, (b) a list of registered users that grows as people sign up, (c) a print queue where the longest job was submitted first. Choose a stack, a list or a queue for each case and justify each choice.
  6. A hospital records patient temperatures every hour for 24 hours in a list. Write a short Python function that finds the highest and lowest temperatures. Explain how the function processes the list and why passing the list as a parameter (rather than hard-coding values) makes the function reusable for any patient.
  7. A student implements bubble sort but the list [8, 3, 5, 1] is not sorted after one pass. Explain why multiple passes are needed and describe the condition that tells the algorithm the list is finally sorted.

Sparklabs Learning / SS 3 First Term / Learner notes

Lesson content is provided for classroom planning. Adapt timings and tasks to the approved school calendar and available devices.

Sparklabs Learning

Digital Technology lesson notes and teaching plans for JSS 1 to SS 3.

Curriculum

Open educational resources for JSS 1 to SS 3 Digital Technology.

Quick links

Search the curriculumBrowse classesPrintable term packs

Academic session 2026 / 2027