Pattern Recognition CS Thinking Example 2
Follow the full solution, then compare it with the other examples linked below.
Example 2
mediumThree programs are described: (a) calculates total price of items in a shopping cart, (b) calculates total marks of a student across subjects, (c) calculates total rainfall over a week. What pattern do they share?
Solution
- 1 Step 1: All three take a list of numbers and add them up.
- 2 Step 2: The pattern is: initialise a total to 0, iterate through a list, add each value to the total.
- 3 Step 3: The same algorithm (summing a list) solves all three problems โ only the context differs.
Answer
All three use the 'sum a list of values' pattern. The same code structure works for all.
Recognising that different problems share the same underlying pattern lets us reuse solutions. This is a key skill in programming โ write once, apply many times.
About Pattern Recognition
Pattern recognition is the process of identifying similarities, trends, or regularities across data or problems in order to build general solutions. By spotting what is the same across different cases, you can create reusable strategies instead of solving each case from scratch.
Learn more about Pattern Recognition โMore Pattern Recognition Examples
Example 1 easy
Look at the sequence: 2, 6, 18, 54, ... Identify the pattern and predict the next number.
Example 3 easyIdentify the pattern: Monday โ M, Tuesday โ T, Wednesday โ W. How would you extract the first letter
Example 4 mediumThree tasks all require counting items that meet a condition: counting even numbers in a list, count