Computer Science
Grade 9
20 min
Lesson 10: Algorithm Challenge: Solving a Problem Together
Work in groups to design and represent an algorithm (pseudocode and flowchart) to solve a given problem.
Tutorial Preview
1
Introduction & Learning Objectives
Learning Objectives
Break down a complex problem into smaller, manageable sub-problems.
Write clear and logical pseudocode to plan an algorithm before writing code.
Identify and test for common edge cases in a problem.
Trace an algorithm's execution with sample data to verify its correctness.
Articulate their thought process and collaborate with a partner to refine a solution.
Translate a pseudocode plan into a working program in a familiar language.
How would you give a robot instructions to make a peanut butter and jelly sandwich? 🤖🥪 What if it only understands simple commands like 'pick up' and 'move left'?
This lesson is all about the process of solving problems like a computer scientist. We'll learn a structured, step-by-step method to t...
2
Key Concepts & Vocabulary
TermDefinitionExample
Problem DecompositionThe process of breaking down a large, complex problem into smaller, more manageable, and solvable parts.Problem: 'Build a social media app.' Decomposition: Break it into 'User login,' 'Create a post,' 'View a feed,' and 'Add a friend.'
PseudocodeA plain-language description of the steps in an algorithm. It's not a real programming language but helps you plan your logic before coding.FUNCTION findMax(numbers):
SET max_num = first number in list
FOR EACH number in numbers:
IF number > max_num:
SET max_num = number
RETURN max_num
ConstraintsThe limitations or rules that a solution must follow. These can include things like the size of the input, memory limits, or required spee...
3
Core Syntax & Patterns
The 4-Step Problem-Solving Framework
1. Understand the Problem -> 2. Devise a Plan (Pseudocode) -> 3. Implement the Plan (Code) -> 4. Review and Refactor
A structured approach to solving any programming challenge. Always follow these steps in order. Skipping steps, especially planning, leads to more bugs and wasted time.
Pseudocode Structure
Use keywords for actions (SET, GET, PRINT, IF/ELSE, FOR, WHILE) and use clear, human-readable names for variables and functions.
Use this pattern to write pseudocode that is easy for you and a partner to understand and translate into any programming language. It focuses on logic, not syntax.
4 more steps in this tutorial
Sign up free to access the complete tutorial with worked examples and practice.
Sign Up Free to ContinueSample Practice Questions
Challenging
You are asked to write an algorithm to find the *second-largest* number in a list of unique integers (list has at least two numbers). Decomposing this problem, what two key variables do you need to track as you iterate through the list?
A.The current number and the next number
B.The largest number found so far and the second-largest number found so far
C.The first number and the last number in the list
D.The sum of the numbers and the count of the numbers
Challenging
A student's palindrome algorithm returns `true` for 'racecar' but also incorrectly for 'racetar'. What is the most likely logical flaw in their pseudocode: `... WHILE l < r: IF s[l] == s[r] THEN RETURN true; ELSE RETURN false; END WHILE ...`?
A.It returns true as soon as it finds a single matching pair of letters
B.The loop condition should be `l <= r`
C.It doesn't handle case-insensitivity
D.The pointers are not updated inside the loop
Challenging
In a pair programming session, the Driver says, 'Okay, I'll loop from 0 to the list length.' The Navigator says, 'Wait, our plan is to initialize 'max_value' to the first element *before* the loop. Also, the loop should go to length minus one.' The Navigator's intervention successfully prevents what two common pitfalls?
A.Jumping to code and poor communication
B.Forgetting edge cases and an off-by-one error
C.Poor communication and forgetting edge cases
D.Jumping to code and an off-by-one error
Want to practice and check your answers?
Sign up to access all questions with instant feedback, explanations, and progress tracking.
Start Practicing Free