Order of Steps in Problem Solving (OCR A-Level Computer Science): Revision Notes
Order of Steps in Problem Solving
Overview
Solving a problem in computer science requires a clear and logical sequence of steps. Determining the correct order of steps ensures that algorithms and programmes work as intended. Understanding how to structure these steps is essential for writing efficient and error-free code.
This note covers how to identify, arrange, and represent the steps needed to solve a problem using pseudocode, flowcharts, and code.
Problem-Solving Steps
- Definition: The sequence of actions or operations required to achieve a specific goal or solve a problem.
- Purpose: Ensures the solution follows a logical order, avoiding errors and inefficiencies.
Common Problem-Solving Steps:
- Understand the Problem: Define the inputs, processes, and outputs.
- Break Down the Problem: Divide the problem into smaller, manageable tasks.
- Plan the Solution: Identify the sequence of operations.
- Implement the Solution: Write pseudocode, code, or draw a flowchart.
- Test the Solution: Check if it works as expected, and refine it if necessary.
Representing Problem-Solving Steps
Pseudocode
- Definition: A high-level, language-agnostic description of the algorithm.
- Purpose: Helps plan the sequence of steps before actual coding.
Example:
START
INPUT temperature
IF temperature > 30 THEN
PRINT "It's hot"
ELSE
PRINT "It's not hot"
ENDIF
END
Flowcharts
- Definition: A visual representation of the steps in an algorithm.
- Purpose: Provides a clear view of the process flow, making it easier to understand and debug.
- Symbols:
- Oval: Start/End.
- Rectangle: Process/Task.
- Diamond: Decision point.
- Arrow: Flow of control.
Example: Start → Input Temperature → Decision: Is temperature > 30? → Yes: Print "It's hot" → No: Print "It's not hot" → End.
Code
- After pseudocode or flowcharts, the steps are translated into code using a programming language.
Example in Python:
temperature = int(input("Enter temperature: "))
if temperature > 30:
print("It's hot")
else:
print("It's not hot")
How to Determine the Order of Steps
- Identify Inputs: Determine what data the programme requires to start (e.g., user inputs, data files).
- Define Processes: Identify the operations needed to process the inputs (e.g., calculations, decisions).
- Determine Outputs: Define what the programme should produce or display.
- Sequence the Steps: Arrange the steps in a logical order:
- Start with inputs.
- Process the data.
- Make decisions if needed.
- Produce outputs.
- End the programme.
- Use Control Structures:
- Sequential Steps: Execute one step after another.
- Conditional Steps: Use IF or CASE to make decisions.
- Loops: Use FOR, WHILE, or REPEAT to repeat processes.
Example: Vending Machine Problem
Problem Statement: Design a programme for a vending machine that dispenses a drink when the correct amount is inserted.
Steps in Order:
- Start.
- Display available drinks and their prices.
- Accept user input for drink selection.
- Prompt the user to insert money.
- Check if the inserted amount is sufficient:
- If yes, dispense the drink and return any change.
- If no, prompt for additional money.
- End. Pseudocode:
START
DISPLAY "Select a drink:"
INPUT drink
DISPLAY "Insert money:"
INPUT money
WHILE money < price[drink] DO
DISPLAY "Insufficient funds, insert more money:"
INPUT additional_money
money = money + additional_money
ENDWHILE
DISPENSE drink
IF money > price[drink] THEN
RETURN change
ENDIF
END
Flowchart:
- Start.
- Display drinks → Input selection → Input money.
- Decision: Is money sufficient?
- Yes → Dispense drink → Return change → End.
- No → Loop back to "Input additional money."
Note Summary
Common Mistakes
- Skipping Steps: Omitting essential steps (e.g., error handling) can cause the programme to fail.
- Incorrect Order: Performing steps out of sequence leads to logical errors (e.g., processing data before it is collected).
- Lack of Testing: Failing to test each step can result in undetected errors.
- Overcomplicating: Including unnecessary steps makes the algorithm inefficient and harder to understand.
Key Takeaways
- Determining the correct order of steps is critical for solving problems efficiently and accurately.
- Steps should follow a logical sequence, from input collection to processing and output.
- Use pseudocode and flowcharts to plan and visualise the steps before implementing them in code.
- Proper ordering ensures the programme works as intended, avoiding logical and runtime errors.