Standard Methods Of A Solution
Learn it by playing
Answer these questions to earn energy, then fish and explore. No account needed.
Notes
Linear Search
- A **linear search** checks every value in a dataset one by one from the start.
- It works on **unsorted** data.
- Algorithm: check first value; if match → stop; else move to next; repeat until found or end.
- Uses a **boolean flag** (e.g., `found`) to track if the target is located.
- In pseudocode, a `FOR` loop iterates through the array; `IF` compares each element to the target.
- If found, set flag to `TRUE` and output message; after loop, if flag still `FALSE`, output 'not found'.
Bubble Sort
- A **bubble sort** repeatedly passes through a list, comparing adjacent pairs and swapping if out of order.
- Each full pass is called a **pass**; the algorithm may need multiple passes.
- After each pass, the largest (or smallest) element 'bubbles' to its correct position at the end.
- The algorithm stops when a complete pass makes **no swaps**.
- In pseudocode, a `WHILE` loop runs while `swaps = TRUE`; inner `FOR` loop compares `nums[y]` and `nums[y+1]`.
- Swap uses a temporary variable; after each pass, the range decreases by 1.
- In exams, you only need to show the state after each pass, not every individual swap.
Totalling
- **Totalling** accumulates a running total of values as they are input or processed.
- Initialise total to 0, then in a loop add each value: `Total ← Total + ItemValue`.
- Example: summing item prices on a receipt.
Counting
- **Counting** increments (or decrements) a counter by a fixed amount (usually 1) each iteration.
- Used to track the number of times an action occurs, e.g., loop iterations.
- Increment example: `Count ← Count + 1`; decrement: `Count ← Count - 1`.
- Often used with `DO...UNTIL` or `WHILE` loops to control repetition.
Maximum, Minimum & Average
- **Maximum** and **minimum** find the largest and smallest values in a dataset.
- In pseudocode, use built-in functions: `Highest ← max(Scores)`, `Lowest ← min(Scores)`.
- **Average** (mean) is calculated by summing all values and dividing by the count.
- Sum via loop: `Total ← Total + Scores[Count]`; then `Average ← Total / LENGTH(Scores)`.
- These methods are commonly used for grades, scores, or any numeric data.
Linear search through an array checking each element; target 11 not found.
Bubble sort passes on [5,2,4,1,6,3] showing final sorted order after 4 passes.
Illustration of totalling and counting methods.
Practice questions
Free preview — 8 of 40 questions. Sign up to see them all.
1.What is a linear search?
Easy- AAn algorithm that starts at the first value and checks every value one at a time
- BAn algorithm that divides the dataset in half repeatedly to find a value
- CAn algorithm that sorts data by comparing adjacent pairs and swapping them
- DAn algorithm that uses a hash table to locate data quickly
2.Which of the following is true about a bubble sort?
Easy- AIt compares adjacent values and swaps them if they are in the wrong order
- BIt selects the smallest value and moves it to the beginning
- CIt requires the dataset to be already sorted to work
- DIt only works on numeric data
3.What does the 'found' variable represent in a linear search algorithm?
Easy- AWhether the target value has been found in the dataset
- BThe index of the current element being checked
- CThe total number of comparisons made
- DThe value of the target being searched for
4.A linear search is performed on the list [5, 2, 8, 1, 9] to find the value 8. How many comparisons are made before the value is found?
Medium- A3
- B2
- C5
- D4
5.What is the purpose of the 'swaps' variable in a bubble sort algorithm?
Medium- ATo indicate whether any swaps were made during a pass
- BTo count the number of passes completed
- CTo store the temporary value during a swap
- DTo determine the length of the array
6.After one pass of a bubble sort on the list [5, 2, 4, 1, 6, 3], what is the order of the list?
Medium- A[2, 4, 1, 5, 3, 6]
- B[2, 5, 4, 1, 6, 3]
- C[2, 1, 4, 3, 5, 6]
- D[1, 2, 3, 4, 5, 6]
7.Which of the following is a valid advantage of a linear search?
Medium- AIt can be performed on unsorted data
- BIt is the fastest search algorithm for large datasets
- CIt uses divide and conquer to reduce search time
- DIt requires the data to be sorted first
8.In the context of standard methods of a solution, what is 'totalling'?
Medium- AKeeping a running total of values entered into the algorithm
- BCounting the number of times a loop iterates
- CFinding the largest value in a list
- DSorting a list into ascending order
Unlock all 40 questions, slides & more
Create a free account to see every question, the slides, flashcards and revision notes for this topic.
Past papers
Past-paper practice for this topic is coming soon.