English:Pseudocode, flowcharts and standard algorithms - Computing Year 10
Introduction
You are designing a search feature for a collection of numbered exhibits. Decide when a search can rule out half of a list, how to put a list into order and how to test the choices. Work from an algorithm description to a trace table and use evidence to explain which approach suits a particular dataset.
Represent inputs, decisions and repetition
An algorithm is a sequence of precise steps for solving a problem. Pseudocode describes those steps using a readable convention. A flowchart uses shapes and arrows to make the control flow visible. A trace table records selected variable values as the algorithm runs. These representations help you explain what should happen before you enter code.
Identify the inputs, output and assumptions first. For the exhibit search, the inputs are a list of identifiers and a target identifier. The output is either an index or a clear not-found result. Decide whether the first index is zero and whether the algorithm must return a particular one if there are duplicates. The example below uses zero-based indexing and can return any one match.

The diamonds represent decisions. Label outgoing paths so a reader knows which condition selects each route. For search you could use a diamond with the test “Does the middle value match the target?” and give the two outgoing arrows clear yes and no labels. Draw the condition for ending before the algorithm tries to read an index from an empty interval.
Trace binary search on a sorted list
Binary search requires ordered data and a way to read a middle element. In this lesson the list is sorted in ascending order and supports indexing. Keep a lower and an upper index, both inclusive. Compare the target with the middle item. If the target is larger, the lower bound moves to one after the middle. If it is smaller, the upper bound moves to one before the middle. When the lower bound passes the upper bound, there are no candidates left.
| Step | Low index | High index | Mid index | Middle value | Decision for target 10 |
|---|---|---|---|---|---|
| First | 0 | 6 | 3 | 8 | Keep indexes 4 to 6 |
| Second | 4 | 6 | 5 | 12 | Keep index 4 |
| Third | 4 | 4 | 4 | 10 | Found at index 4 |
The list is 2, 4, 6, 8, 10, 12, 14. With an even number of candidates, this example uses the lower of the two middle positions. Returning an index of 4 identifies the fifth element. For a target of 7, the visited middle values are 8, 4 and 6. The bounds then cross, so the algorithm returns not found. Each unsuccessful comparison reduces the number of candidates.
def find_sorted(values, target):
low, high = 0, len(values) - 1
while low <= high:
middle = (low + high) // 2
if values[middle] == target:
return middle
if target > values[middle]:
low = middle + 1
else:
high = middle - 1
return NoneVideo route. Pause at a comparison and predict which portion of a sorted list remains. Written route. Start with the interval from index 0 to index 6. When the middle value is 8 and the target is 10, every value at or below index 3 is too small. The next interval begins at index 4.
Split and merge to sort a list
Merge sort first divides a list into smaller lists until each has at most one element. It then repeatedly merges two sorted lists. Compare their first unmerged values and copy the smaller to the output. If one list is exhausted, append the remaining values in the other list in their existing order.

The diagram works through seven values. Read the top line and trace the part with 38 and 27. Each value can stand alone as a sorted list. On merging, 27 comes before 38. In the lower part of the diagram check that every rejoined list is sorted.
For a second example take 5, 1, 4, 2. Split it into 5, 1 and 4, 2, then into singletons. Merge the singletons to get 1, 5 and 2, 4. Compare 1 versus 2, then 5 versus 2, then 5 versus 4. The output so far is 1, 2, 4. Append 5 to finish. Splitting produces smaller problems, while merging puts the values into order. Appending the two sublists without comparing their heads would give 1, 5, 2, 4, which is not sorted.
Video route. Choose one merge step and write the two first unmerged values before the choice. Written route. Merge 2, 6 and 1, 5. Take 1 first, then 2, then 5 and append 6. The result is 1, 2, 5, 6.
Check boundaries and assumptions with test data
A normal example checks everyday operation. An edge case checks a valid input near the limits, such as an empty list or a list of one value. A missing target also needs a defined result. Unsorted input violates the assumption of this binary search. For an indexable list that changes frequently, maintaining the order is part of the design decision.
| Sorted input | Target | Expected result | Reason to test it |
|---|---|---|---|
| 2, 4, 6, 8, 10, 12, 14 | 10 | Index 4 | Found after both bound changes |
| 2, 4, 6, 8, 10, 12, 14 | 7 | Not found | Bounds cross between neighbouring values |
| Empty list | 2 | Not found | Loop must not attempt to read an index |
| 4 | 4 | Index 0 | First and last index are the same |
| 2, 4, 4, 6 | 4 | Index 1 or 2 | Search contract permits any match |
Try supplying the unsorted list 2, 14, 4, 8, 6, 12, 10 and target 14. The first comparison is against 8. The sorted-list rule would discard the left portion that contains 14, showing exactly which assumption fails. The trace shows why testing many valid cases alone cannot excuse invalid inputs.
A merge-sort test can check that the output has all the original values, including duplicates, and is in order. For 4, 2, 4, the required output is 2, 4, 4. If equal values carry labels and their order matters, taking a tied value from the left sublist first preserves their original relative order for this merge sort.
Evaluate which algorithm fits the use
Linear search compares items one at a time, in list order. It works without sorting. In the seven-item sorted list, a linear search from the start reaches 10 on its fifth comparison, while the binary example needs three. For target 2, linear search succeeds on its first comparison and the example binary search looks at 8, then 4, then 2. Explain results in relation to the tested input.
For one search in a small unsorted list, use a linear search in a straightforward design. If the exhibit numbers can be sorted once and searched frequently, an indexed sorted list can support repeated binary searches. If items are inserted often, plan how to preserve order. For a list that must itself be sorted, merge sort is a separate action that produces a sorted result. A straightforward implementation uses additional storage for merged lists, so consider available memory and the scale of the task.
Write a conclusion that connects evidence to the requirement. Keep the search precondition, comparison counts and missing-target handling visible. A test set that includes found, missing, empty and repeated values gives more evidence about fitness for purpose than one successful example. A sorting test should also check both ordering and preservation of the input values.
Interactive Tasks
Quiz: Test Your Knowledge
What does a flowchart diamond usually represent? (A decision) (!A list cell) (!A stored source file) (!A completed merge)
What must the chapter’s binary search assume? (The values are in ascending order) (!The values are in a random order) (!The output is always the last index) (!Every target must be present)
What is the first middle value in the seven-item example? (8) (!2) (!10) (!14)
The middle value is 8 and the target is 10. Which indexes remain after the first comparison? (4 to 6) (!0 to 2) (!0 to 3) (!Only index 3)
What index does the example return for target 10? (4) (!3) (!5) (!6)
What is the result when low becomes greater than high? (There is no remaining candidate) (!The middle item is always a match) (!The whole list is searched again) (!The order of the list is reversed)
Which is the correct merge of 1, 5 and 2, 4? (1, 2, 4, 5) (!1, 5, 2, 4) (!2, 4, 1, 5) (!5, 4, 2, 1)
What should a correct sorting algorithm preserve? (The original values and how many times each appears) (!Only the first value and the last value) (!The original index of every unequal value) (!Exactly three comparisons for any list)
When can linear search be the simplest fit? (One lookup in a small unsorted list) (!Repeated lookups in a sorted indexed list where reductions are needed) (!When you have to merge sorted lists) (!When finding a middle index is required)
Which dataset checks that the search loop avoids invalid index access on an empty interval? (An empty list and a target) (!An ordered list of seven items with a centre target) (!Only one pair of sorted lists to merge) (!Seven successful queries for the same target)
Memory Game
| Middle index of the 0 through 6 interval | Index 3 |
| Found position of target 10 in the model | Index 4 |
| Exhausted binary-search interval | The lower bound is greater than the upper bound |
| Merge of 1, 5 and 2, 4 | 1, 2, 4, 5 |
| One lookup in a short unsorted list | A linear search can run without prior sorting |
Drag and Drop
| Show a decision and two paths | Flowchart diamond |
| State the numbers when a program runs | Trace table |
| Test a list with no elements | Empty-input case |
| Remove half of a sorted search interval | One binary-search step |
| Take the smaller of two front values | One merge step |
Crossword Puzzle
| TRACE | Record of selected states as an algorithm runs |
| BOUNDS | Lower and upper limits of an interval |
| INDEX | Position used to locate an item in a list |
| MERGE | Combine sorted sublists into one sorted list |
| TARGET | Value being sought by a search |
| SORTED | In the required sequence by value |
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
Open Tasks
Easy
- Make the first decision: Draw a diamond with yes and no paths for whether a middle value equals a target.
- Identify a middle index: Find the lower middle index of the inclusive interval from 0 to 5.
- Read a sorted pair: Show how merging one-value lists containing 7 and 2 gives an ordered pair.
- State a precondition: Write a one-sentence requirement for using the model binary search.
Standard
- Trace an even-length example: On 3, 6, 9, 12, 15, 18 trace the search for 15. Record low, high, middle, value and decision.
- Show a merge sort: Split and merge the values 8, 7, 2, 6. Record each rejoined sorted list.
- Propose a small test set: Write a found, missing, empty and duplicate test and give the expected outcomes.
- Find an off-by-one issue: Explain what can happen if a comparison against a smaller middle value leaves low equal to middle.
Advanced
- Evaluate two workloads: Compare one lookup in an unsorted list with 100 lookups in a stable list. Include any initial sorting cost or ordering requirement.
- Explain the failed assumption: Create and trace a new unsorted example in which binary search discards the very interval containing the target.
- Check duplicate labels: Merge A2, C4 with B2, D5, where the number is the key. Compare two tie rules and explain which preserves the order of equal items.
- Create a comparison report: Select six searches. Record counts under linear and binary search. Make a conclusion that states the inputs and any limits on the comparison.
Learning Check
- Complete a binary trace: Search for 15 in 3, 6, 9, 12, 15, 18. State the visited values and final index.
- Find a missing value: Search for 7 in the seven-item lesson list. Explain the final stop.
- Merge ordered values: Merge 0, 8, 10 and 3, 3, 12. Preserve repeats.
- Explain a bound change: Why must low become middle plus one after observing a middle value smaller than the target?
- Choose a search: A file of eight unsorted records will be searched for one identifier today. Which approach would you choose and why?
- Audit a sorter: A sorting function maps 4, 2, 4 to 2, 4. How can you tell it is incorrect despite the result being in order?
Worked checks and assessment guidance
- With floor midpoint, the first middle is index 2 with value 9. The interval becomes 3 to 5. The next middle is index 4 with value 15, so return 4.
- The values are 8, 4 and 6. The lower bound rises to 3 while the upper bound is 2, leaving no candidate.
- The output is 0, 3, 3, 8, 10, 12. After copying 10, append the remaining 12.
- All positions at or below the middle contain values at most equal to that smaller value. They cannot match the target. Reusing the middle can also prevent progress.
- A linear search needs no prior ordering and handles the small one-time task. A binary search would need sorted indexed data first.
- The output is missing one occurrence of 4. A sorting operation in this task must keep each original value and its multiplicity.
Learning evidence
You can trace a binary search with inclusive bounds, justify the precondition, and split and merge a list while keeping every value. Your test plan distinguishes normal, missing and boundary cases and your evaluation names the workload.
OER and Wikipedia
Department for Education, GCSE computer science subject content. Cambridge OCR, GCSE Computer Science J277. Test cases and traces are original classroom examples.
Flowchart example, Manuela knoop, CC BY-SA 3.0. Merge sort diagram, VineetKumar, based on eleschinski2000, public domain. Optional animations Binary search, Mazen Embaby, CC BY-SA 4.0, and Merge sort, Swfung8, CC BY-SA 3.0. Wikimedia Commons.
Binary Search – CS50 Shorts, CS50. Merge Sort – CS50 Shorts, CS50. Written alternatives accompany both.
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-HauptseiteMediathek
Mediathek wird aus dem Wiki geladen ...
Keine passenden Inhalte gefunden. Bitte ändere Suche oder Filter.
NEWSLernweltNOAH fragen