Zum Inhalt springen

English:Algorithms, pseudocode and flowcharts - Computing Year 7

Aus MOOCsWiki Staging
aiMOOC-Siegel aiMOOC

Algorithms, pseudocode and flowcharts - Computing Year 7

QR-Code



Introduction

Number and symbol blocks introducing discrete values and ordering
The real Commons photograph is context for thinking about values and sequences. All lists, procedures, traces, comparison counts and optional programs below are original course examples, not data extracted from the picture.

Translate a precise problem into pseudocode and a matching flowchart, trace a first-match search, and compare maximum-finding and selection sort using explicit operation counts. Year 7 placement is editorial within England’s KS3 Computing programme.


Specify a problem and express a terminating search

An algorithm must solve a stated problem, not merely look like code. Specify the input, required output and rules before choosing steps. For this original search task the input is a finite list of integers and an integer target. Return the index of the first matching value, or a clear no-match result. The list need not be sorted, and repeated values are allowed.

The original list is [3, 7, 7, 2, 9]. We label its indices from zero, so the values have indices 0, 1, 2, 3 and 4. The first matching index for target seven is one, although it is the second physical item. A target nine is found at index four; target five has no match. Returning a matching value alone would not satisfy this particular index-returning specification.

Number and symbol blocks used as an illustration of discrete items
ajay_suresh’s unchanged photograph illustrates distinguishable tokens and arrangements. The photographed numbers are not the course’s original test list, and a visual arrangement is not by itself a complete search algorithm. The list values and index rules are stated separately in the text.

Linear search inspects items in order. Compare the first value with the target; if they match, return its index and stop this search. Otherwise advance one item and repeat while an item remains. If the end is reached without a match, return NONE. An empty list immediately gives no match, not an attempt to read its nonexistent first item.

The following is structured pseudocode, not executable Python. Indentation and closing words show which instructions belong to the loop and decision. NONE is the named no-match result for this notation; the later Python version uses None. There is no universal pseudocode spelling, so define conventions and use them consistently.

SET i TO 0
WHILE i IS LESS THAN LENGTH(values)
    IF values[i] EQUALS target
        RETURN i
    END IF
    SET i TO i + 1
END WHILE
RETURN NONE

Termination needs reasoning. Each unsuccessful comparison increases i by one; a finite list permits only finitely many such advances before the loop condition becomes false. A successful comparison returns early. If the increment were omitted, a missing target could leave the model examining the same item forever. If the final no-match return were wrongly placed inside the loop after the first failed comparison, later matches would be missed.

Correctness is different from speed. For every position already passed without returning, its value has been checked and did not match. Therefore a match found at the next position is the first; if the list ends, all positions have been checked. This argument explains the steps rather than inferring correctness from one convenient example.

Identify a problem, a precise repeated procedure and a condition that changes what happens next. The original search specification and pseudocode here are separate examples, not a transcript of the video. Use the written procedure and worked trace as the offline alternative. Original: TED-Ed, What's an algorithm? - David J. Malan. The written explanations and native tasks work without sound or the external player.


Draw matching control flow and trace every decision

A flowchart and pseudocode should express the same control flow. Use a start/end symbol for boundaries, a process box for updates, an input/output symbol where data is received or a result produced, and a decision with labelled outcomes. A decision arrow without a Yes/No or equivalent label can leave the next step ambiguous.

An input-process-output flowchart for Fahrenheit to Celsius conversion
Dave Braunschweig’s unchanged example shows procedure steps and a temperature conversion, not the original search loop. Use it to distinguish input, calculation and output. Our search chart additionally needs a repeated path and two decisions; its precise connections are supplied below.

Draw the original first-match search using the following node connections. Both representations receive the same list and target. Node C tests whether an item remains before node D reads it. Node F returns to C, so the loop condition is checked after each unsuccessful comparison. The no-match result is reached only from C’s No route.

Node Meaning Next connection
A Start B
B Set index to zero C
C Is index within the list? Yes: D; No: H
D Does this item equal target? Yes: E; No: F
E Return this index Z
F Increase index by one C
H Return NONE Z
Z End No next step

Trace one run with columns for index, value, comparison outcome and next action. For target seven, index zero has value three: not equal, so advance to one. Index one has value seven: equal, so return one and stop. The duplicate at index two is not inspected in this early-return run. For target five, all five values fail and the search returns no match after the last advance makes index five equal to the list length.

An off-by-one error often confuses the last valid index with the length. A five-item list has final valid index four. Testing whether index is less than or equal to length would allow a nonexistent index five to be read. Check the boundary before indexing, and include empty and single-item tests rather than relying only on a long list with an early match.

For comparison counts in this course, count only item-to-target equality tests for search. Do not mix them with loop-condition checks, assignments, list-length calls or elapsed seconds. The seven-target run uses two counted comparisons; target nine and a missing target each use five; an empty list uses zero. A different operation-count definition could be valid, but it must be stated before comparing algorithms.

Compare an early-return search with a full-scan version that retains the first match and still checks every item. Both can meet the same result specification; the full scan uses five item comparisons for every target on this five-item input, while early return can use fewer. If a supposed full-scan first-match algorithm overwrites its saved answer on every match, it returns index two for target seven and fails the original first-match requirement.

Another short trace illustrates an accumulating total. Under a separate specification, sum integers one through non-negative n, with an initial total zero. For n four the total after each addition is one, three, six and ten. For n zero there are no additions and the result remains zero. These are not index values from the search list; state the problem and variable meanings before carrying a trace convention into a new algorithm.



Compare algorithms and test optional implementations

Use more than one algorithm and test each against its own specification. Finding the maximum integer is different from finding the first matching index. For a nonempty list initialise best with its first value, compare each remaining value and replace best only when a larger one appears. Initialising best to zero would give the wrong answer for an all-negative list.

For [3, 7, 7, 2, 9], the initial best is three. The four remaining comparisons give best values seven, seven, seven and nine. The maximum is nine after four value-to-best comparisons, not index four as a value claim. This version explicitly returns None for an empty list, because an empty list has no greatest integer; that is a documented convention, not a maximum of zero.

The following original optional Python functions implement the taught procedures. The main pseudocode and flowchart tasks do not require you to know every Python feature first. Inputs here are finite lists of integers and integer targets. Functions return results and counts, have no network, account or real-device effects, and do not change the input list. They count the specific value comparisons described in the text.

def first_index(values, target):
    comparisons = 0
    for i in range(len(values)):
        comparisons += 1
        if values[i] == target:
            return i, comparisons
    return None, comparisons
def maximum(values):
    if not values:
        return None, 0
    best = values[0]
    comparisons = 0
    for value in values[1:]:
        comparisons += 1
        if value > best:
            best = value
    return best, comparisons

Sorting has another specification: return the same integer values in ascending order, preserving their multiplicities. Selection sort repeatedly finds the smallest remaining value and puts it at the start of the unsorted part. The prefix already placed remains sorted and contains the appropriate smallest values; the next scan considers only the remaining suffix.

For a separate original list [4, 1, 3, 2], first select one and exchange it with four, giving [1, 4, 3, 2]. Next select two from the remaining suffix and exchange it with four, giving [1, 2, 3, 4]. In the final scan three is already in position, so no actual exchange is needed. There are six counted value comparisons, from scans of three, two and one comparisons, and two exchanges between distinct positions.

def selection_sort(values):
    result = list(values)
    comparisons = 0
    swaps = 0
    for start in range(len(result) - 1):
        smallest = start
        for j in range(start + 1, len(result)):
            comparisons += 1
            if result[smallest] > result[j]:
                smallest = j
        if smallest != start:
            result[start], result[smallest] = (
                result[smallest], result[start]
            )
            swaps += 1
    return result, comparisons, swaps

This function copies the list before sorting. The comparison count is determined by the suffix scans even when the input is already sorted; that does not mean the number of exchanges is identical. Sorting a list is not the same as adding its values or deleting duplicates. If equal-valued records had separate identities, preserving their original order would be an additional stability requirement not guaranteed by this basic swapping version.

A photograph of Python code on a display
Weal2019’s unchanged code photograph supplies programming context. Its matrix and graph program is not the original search, maximum or selection-sort implementation. Use the explicit course code and independent test cases rather than copying an unrelated program from the picture.

Review data representation: Scratch Team — What Are Variables and Lists in Scratch? (Part 1)| Tutorial. Relate stored variables and ordered list items to the original algorithms. This course explicitly labels its indices from zero; check another tool’s indexing conventions rather than transferring index numbers without checking. The written list examples and trace tables provide the offline alternative.

Test normal, boundary and tricky inputs: an early and late match, no match, duplicates, an empty list, a single value and an all-negative maximum case. Compare results with independently specified expectations; do not call the program’s output its own proof. The exact optional functions in this course were actually checked on many small integer lists, including duplicates and negative values, for correct results, stated counts and unchanged inputs.

Compare methods using the same problem, input and counted operation. Our early-return search has a best case of one comparison for a match at the start and a worst case of n for an n-item list; no-match also uses n. Maximum scanning of a nonempty list uses n minus one value comparisons. This selection-sort version uses n times n minus one divided by two such comparisons. These counts are not timings and do not certify the fastest implementation on every device.

For the final portfolio, submit the search specification, consistent pseudocode and drawn flowchart, two traces including an invalid expectation you corrected, and a justified comparison with an alternative. Add a maximum or sorting trace as transfer. Explain what is counted, what assumptions apply and why the algorithm terminates; a confident-looking diagram is not a substitute for that reasoning.



Interactive Tasks


Quiz: Test Your Knowledge

What result does the original search specification require? (The first matching zero-based index or a clear no-match result) (!Any matching value without its position) (!The final duplicate position even when an earlier match exists) (!A sorted copy of the list regardless of the target)



What is returned for target seven in the original list? (Index one, the second item) (!Index two because the later duplicate must win) (!Value seven as the complete required index answer) (!No match because the list is not sorted)



Why must the loop check its boundary before reading an item? (An empty or finished list has no item at the next index) (!List length is always the last valid index) (!The photograph supplies an extra item beyond the list) (!Checking a boundary guarantees a target must exist)



What prevents a missing-target search from repeating one item forever? (Advance the index after a failed comparison and recheck the finite-list boundary) (!Return no match immediately after the first failure in all cases) (!Remove the loop condition so every input terminates) (!Reset the index to zero after every failure)



What does the target-seven early-return run count here? (Two item-to-target comparisons) (!Five comparisons because every search must scan all items) (!One comparison because the returned index is one) (!The number of seconds displayed by a stopwatch)



What must a full-scan first-match alternative do when later duplicates appear? (Keep the first saved matching index) (!Overwrite its saved result with every later match) (!Delete all equal items before searching) (!Assume its different answer still meets the first-match specification)



What is the separate sum from one through four? (Ten after running totals one, three, six and ten) (!Four because the counter alone is the answer) (!Nine because the initial zero is counted as a value to add) (!None because addition cannot be described algorithmically)



Why initialise a nonempty maximum scan from the first list value? (A zero initial value can fail on an all-negative list) (!Every list must contain zero as its maximum) (!The first value is automatically the maximum and no further checks are needed) (!It makes an empty list have a greatest integer)



What happens in the original selection-sort example? (Sorted result one, two, three, four with six comparisons and two distinct-position exchanges) (!A result with duplicates removed even if the input had duplicates) (!Four value comparisons because the list contains four values) (!The original input must be changed by the optional copy-based function)



How should algorithm efficiency be compared here? (Use the same problem and input with an explicitly defined counted operation) (!Treat comparison counts as exact wall-clock timings on every device) (!Choose the shortest-looking diagram without testing correctness) (!Compare a maximum value with a search index as if they solved the same problem)





Memory Game

Specification The required input, output and behaviour of a problem
Pseudocode Structured language-independent expression of an algorithm
Flowchart A graphical representation of procedure control flow
Trace A step-by-step record of values, decisions and actions
Linear search Inspecting list items in order to find the required match
Selection sort Repeatedly selecting the smallest remaining value for the next position





Drag and Drop

The first value does not match the target Advance one index before repeating the boundary check
A matching value is found in the first-match search Return its index and stop this search
The index equals the list length Take the no-match route without reading a nonexistent item
An all-negative maximum list is tested Initialise from an actual list item rather than zero
The next smallest value is already in its sorted position Count the scan but do not invent a distinct-position exchange





Crossword Puzzle

ALGORITHM What precise procedure solves a stated problem?
PSEUDOCODE What structured notation communicates logic without being executable Python?
FLOWCHART What diagram shows steps and labelled decision routes?
INDEX What identifies a position in the course’s zero-based list?
MAXIMUM What is the greatest value sought by the second algorithm?
COMPARISON What operation is counted explicitly in the efficiency examples?





LearningApps

Optional extra practice. Choose an appropriate activity with your teacher. If the external collection is unavailable, use the native activities and independent tasks in this course.


Cloze Text

Complete the explanation.
An algorithm must satisfy a

. The first item has index

in this course. A decision needs labelled

. After a failed search comparison the index must

. A successful first-match search returns an

. An empty list gives no

. The maximum scan starts from an actual list

. Selection sort chooses the smallest remaining

. Duplicates retain their

. Comparison counts are not wall-clock

.



Open Tasks


Easy

  1. Define the problem: State the original input, required first-match output and empty-list behaviour.
  2. Read a trace: Trace target seven with index, value, decision and next action.
  3. Draw the flowchart: Use all supplied nodes with labelled decision routes and the loop return.
  4. Compare quantities: Distinguish a list value, its index, the length and a counted comparison.


Standard

  1. Trace late and missing matches: Trace target nine and target five, including the final boundary without an out-of-range read.
  2. Repair a loop: Explain the effects of a missing increment, a less-than-or-equal boundary and an early misplaced no-match return.
  3. Compare two search methods: Preserve the first-match requirement while comparing early-return and full-scan counts on the same list.
  4. Trace a maximum and total: Find the original maximum and the separate sum-one-through-four trace without mixing the variable meanings.


Advanced

  1. Trace selection sort: Show every minimum scan and exchange for the original four-item list, including the no-exchange final pass.
  2. Audit the implementation: Use independently specified empty, singleton, duplicate and negative-list cases; verify results, counts and input preservation.
  3. Explain correctness: Use the already-checked prefix and finite index progress to justify first match and termination.
  4. Choose a comparison rule: Explain the stated best/worst comparison counts and why they do not establish universal runtime performance or stability.



Learning Check

  1. Specification and first-match trace: Use the stated zero-based index requirement.
  2. Boundaries and termination: Handle missing and empty cases before indexing.
  3. Matching representations and alternative search: Keep control flow and the result rule consistent.
  4. Accumulation and maximum: Use distinct initial values and variable roles.
  5. Selection-sort trace and count: Preserve the input values and state what is counted.
  6. Independent testing and comparison: Evaluate the implementation against the specification rather than its own output.


Worked checks and assessment guidance

  1. For the original list three,seven,seven,two,nine, indices run zero to four. Target seven fails at index zero and matches at index one, returning one after two item-to-target comparisons. The later duplicate is not inspected in this early-return run. Returning seven as a value or two as the last matching index would not meet the required first-match result.
  2. Target nine is found at index four after five comparisons. Target five fails at every item, then index five equals length five and the loop returns no match without reading index five. An empty list performs zero item comparisons. Incrementing after each failure guarantees progress through the finite list; a missing increment can loop forever, and a no-match return after the first failure can miss later matches.
  3. The flowchart initialises the index, checks for a remaining item, compares with the target, returns on Yes, or increments and loops on No. Its no-match route comes from the exhausted-boundary decision. A full scan can retain the first match and still use five comparisons on this list. Overwriting the saved answer at the later seven returns index two and fails the first-match specification, even if it is described as faster or simpler.
  4. The separate total from one through four has running values one,three,six,ten, with zero retained for the specified zero-count case. A maximum scan starts at list value three, then keeps seven,seven,seven,nine across four comparisons. Its result is value nine rather than index four. Starting a maximum at zero would fail for a list containing only negative integers; the defined empty-list result is None, not a greatest integer of zero.
  5. For four,one,three,two, select one and exchange to get one,four,three,two; then select two and exchange to get one,two,three,four; the last scan needs no exchange. Value comparisons are three plus two plus one, six, and distinct-position exchanges two. The optional function sorts a copy and preserves duplicates. This basic swapping version does not guarantee relative order of separately identified equal-key records.
  6. Check early/late/no match, empty and singleton lists, duplicates and negative maximum cases with independent expected answers. The course’s actual functions were run on many small integer lists to check output, specified comparison counts and input preservation. Early-return search uses one comparison in its nonempty first-match best case and n in the worst case; maximum uses n minus one for a nonempty list; this selection sort uses n times n minus one divided by two. These are operation counts, not universal elapsed-time guarantees.


Learning evidence

Submit the search specification, consistent pseudocode and flowchart, successful and no-match traces, an explicit comparison-count definition and a maximum or sorting transfer trace. Optional code evidence must include independently expected results and unchanged-input checks.


OER and Wikipedia

Original integer lists, search specification, pseudocode, node connections, maximum/selection-sort examples, optional Python functions and feedback. No real accounts, external services or device controls are used by the programs.

DfE Computing programme of study, KS3 algorithms, reasoning and comparison; Year 7 allocation is editorial. Official Python control-flow tutorial, range, loops and return behaviour only; code and test datasets here are original. TED-Ed original lesson identifies David J. Malan’s film; the verified original TED-Ed upload is used, with the initially found reposted version excluded before authoring. Checked 13 November 2026.

Additional original video: Scratch Team — What Are Variables and Lists in Scratch? (Part 1)| Tutorial, list/variable context, preview and embedding verified. All unchanged Commons sources retain actual credits and licences.

Toy Blocks (50995087111).jpg, ajay_suresh, CC BY 2.0. Unchanged original; caption and learning activities are original.

Flowgorithm Input Process Output.svg, Dave Braunschweig, CC BY-SA 4.0. Unchanged original; caption and learning activities are original.

Python Code.jpg, Weal2019, CC0. Unchanged original; caption and learning activities are original.


Linked learning areas


aiMOOC Projects



Schulfach+




aiMOOCs



aiMOOC Projekte









MOOCwiki · Deutsch

Nach dem Lernen ist vor dem Lernen

Entdecke direkt den nächsten Lernkurs. Weitere Inhalte erscheinen, wenn Du weiter nach unten scrollst.

Zur MOOCwiki-Hauptseite

Mediathek

Suche verfeinern

Dein Lernplan bestimmt, was oben steht. Alle anderen Inhalte bleiben erreichbar. Seitenaufrufe beeinflussen die Auswahl nicht.

Inhalte werden geladen ...

Mediathek wird aus dem Wiki geladen ...