← VCE Software Development U3O1

Applying an algorithm to a task

A step-by-step method for solving a problem, like search or sort. Choose one by matching its input and output to your data, then wrap it in a function to reuse it.

Understanding Applying an algorithm to a task in VCE Software Development U3O1

What it does: A membership check searches the data for a value and gives a yes or no result, which matches the task. sorted() takes an unordered list and returns an ordered one, so it fits a leaderboard task. Sorted data is the right input for binary search. Sorting it again would waste time and wouldn't answer the question. Speed is about how many steps an algorithm needs on the same input. Short code is not always fast. To find the highest score you want a single value as output, so use max(scores) or sort and then pick the first item. The output must match the task.

Common mistakes: A single = assigns a value, but a linear search needs to compare each item. It should be == (if items[i] == target:). The .sort() method changes the list in place and returns None, so ordered would be None. To get a new sorted list, use sorted(names).

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 156–166) and word search (Modules 142–166).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
A teacher has a list of student names and wants to know if "Mia" is in it. Which algorithm fits the task?
Sort, because the output is a list of namesSearch, because the output is found or not found
Matches
top_score = sort(scores)
↓
Using a sort when the task needs one value found and not an ordered list. Also, sort() is not a built-in function; sorted() or max() should be used.
Applying
Meanings
Term
algorithm
Meaning
A step-by-step method for solving a problem, like search or sort. Choose one by matching its input and output to your data, then wrap it in a function to reuse it.
Practice
def find_mark(marks, target):
Testing
Gaps
ranked = (scores)
Check Answer
Spots
2 for i in range(len(items)):
3 if items[i] = target:

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Sea Dragon' badge — OOP Pioneer, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. A teacher has a list of student names and wants to know if "Mia" is in it. Which algorithm fits the task?
A. Sort, because the output is a list of names
B. Search, because the output is found or not found ✓
The task asks a yes/no question about one value, so the output is found or not found. That matches a search algorithm.
2. You want to show a list of race times from fastest to slowest. Which algorithm matches the output you need?
A. Sort, because the output is the same data in a new order ✓
B. Linear search, because it looks at every time
The required output is the whole list in order. Sorting takes a list in and gives an ordered list out.
3. Your data is a list of scores that is already sorted. You need to check if 72 is in it. Which is the better choice?
A. Binary search ✓
B. Selection sort
Sorted data is the right input for binary search. Sorting it again would waste time and wouldn't answer the question.
4. A list of 1,000,000 unsorted usernames is searched once for "kai_99". Which is the better choice?
A. Linear search, because sorting first would take longer than one search ✓
B. Binary search, because it is always faster
Binary search needs sorted data. Sorting a huge list just for one search costs more than a single linear search.
5. You write a search once and need it for many different lists. What is the best way to reuse the algorithm?
A. Copy and paste the code and edit it for each list
B. Wrap it in a function with the list and target as parameters ✓
A function takes the data as input and returns the result as output. You can then call it with any list.

Match the Pairs

def find_student(names, target): return target in names → Wraps a search algorithm in a function so you can reuse it on any list of names and any target.
sorted(scores, reverse=True) → Applies a sort algorithm to a list of scores to give a new list in order from highest to lowest.
The task asks 'Is this username already taken?' so the input is a list and a value, and the output is yes or no. Choose a search. → if username in all_users:
The task asks for a leaderboard from highest to lowest, so the input is an unordered list and the output is an ordered list. Choose a sort. → leaderboard = sorted(points, reverse=True)
top_score = sort(scores) → Using a sort when the task needs one value found and not an ordered list. Also, sort() is not a built-in function; sorted() or max() should be used.
names.sort() print(names.sort()) → Printing the result of .sort() shows None because .sort() changes the list and returns nothing. Print names, or use sorted(names).

Key Term

algorithm
A step-by-step method for solving a problem, like search or sort. Choose one by matching its input and output to your data, then wrap it in a function to reuse it.

Fill in the Blanks

1. scores = [72, 95, 58, 83] ranked = sorted(scores) print(ranked)
Hint: Type the built-in function that returns a new list with the scores in order.
2. names = ["Ava", "Ben", "Cal"] found = "Ben" in names print(found)
Hint: Type the operator that searches a list and gives True or False.
3. def rank(scores): return sorted(scores) print(rank([4, 2, 9]))
Hint: Type the keyword that wraps the algorithm in a function so it can be reused.
4. data = [21, 3, 15, 8] data.sort() print(data)
Hint: Type the list method that orders the data in place, ready for a binary search.
5. linear = 1000 binary = 10 print(linear > binary)
Hint: Type the comparison operator that checks whether linear search takes more steps.

Spot the Error

Question 1
A def find(items, target):
B for i in range(len(items)):
C if items[i] = target:
D return i
E return -1
Line C — A single = assigns a value, but a linear search needs to compare each item. It should be == (if items[i] == target:).
Question 2
A names = ["Zoe", "Ali", "Mia"]
B ordered = names.sort()
C print(ordered)
Line B — The .sort() method changes the list in place and returns None, so ordered would be None. To get a new sorted list, use sorted(names).
Question 3
A def is_sorted(nums)
B return nums == sorted(nums)
C print(is_sorted([1, 2, 3]))
Line A — A function definition must end with a colon. It should be def is_sorted(nums):
Question 4
A def count_steps(items, goal):
B steps = 0
C for item of items:
D steps += 1
E if item == goal:
F return steps
Line C — Python loops use the keyword in, not of. It should be for item in items: so the function can count the steps of a linear search.
Question 5
A def smallest[nums]:
B return min(nums)
C print(smallest([5, 2, 9]))
Line A — Function parameters go in round brackets, not square brackets. It should be def smallest(nums):

Student with a class code? Join your class →