Download COS 102 Introduction to Problem Solving – Algorithms, Pseudocode, Flowcharts & Algorithm and more Study notes Computer Science in PDF only on Docsity!
COS 102
Introduction to Problem Solving
Original study-guide edition
Algorithms • Pseudocode • Flowcharts • Control Structures • Recursion • Decomposition •
Testing • Complexity
A concise, reorganized version of the uploaded handwritten course notes. Personal
identifiers, scanner labels, dates and repeated classroom wording have been
removed.
Copyright-aware preparation
External-looking graphics in the upload were not reproduced where no licence or permission was
supplied. Equivalent concepts are redrawn as original diagrams. Sources are listed at the end.
Student study guide
. Contents
Topic
1 Computational problem solving 2 Defining a problem: input, output, constraints 3 Problem-solving skills and problem types 4 Computational approaches and algorithmic strategies 5 Algorithm development 6 Pseudocode and flowcharts 7 Control structures 8 Recursion 9 Decomposition and modularisation 10 Testing and debugging 11 Time and space complexity 12 Worked examples and revision checklist
Study method
For each topic: understand the definition, trace the example, then explain the idea without
looking at the page.
2. Defining the problem
Before designing an algorithm, define exactly what the program is expected to do. Vague
requirements produce vague algorithms and difficult tests.
Element Question Example Input What information is supplied? Length and width Output What result is required? Area and perimeter Constraints What limits or rules apply? Length must be positive Success criteria How do we know it is correct? Result matches the required formula
Problem-identification routine
- Observe the situation and collect relevant information.
- Ask questions until the required outcome is clear.
- Separate symptoms from underlying causes.
- Identify boundaries, assumptions and constraints.
- State the problem precisely.
- List inputs, processing requirements and outputs.
Failure mode
Starting to code before the problem is defined often causes rework. If input, output or constraints
are unclear, the algorithm is not ready for implementation.
3. Problem-solving skills and problem types
Skill Purpose Analytical thinking Break complex information into smaller parts and identify relationships. Abstraction & modelling Filter irrelevant detail and build a simpler representation. Creative thinking Generate alternative approaches. Debugging mindset Use evidence to locate causes of unexpected behaviour. Communication & documentation Make assumptions, logic and decisions understandable.
Routine vs non-routine problems
Routine / well-structured: the initial state, desired state and permitted operations are largely
known, so the solution path is relatively predictable.
Non-routine / ill-structured: the goal or constraints may be ambiguous, several solutions may
exist, and exploration or iteration may be required.
Do not confuse
Non-routine does not mean impossible. It means the problem structure or solution path is less
predictable.
5. Algorithm development
Stage What happens
1 Understand Define inputs, outputs, constraints and success criteria. 2 Analyse Identify data, relationships, rules and edge cases. 3 Design Choose an approach and decompose the work. 4 Refine Expand each stage until operations are precise. 5 Represent Use pseudocode or a flowchart when useful. 6 Test Use normal, boundary and invalid cases. 7 Implement & debug Translate the verified logic and correct defects. 8 Review Check efficiency, readability and maintainability.
Precision rule
A good algorithm should be detailed enough that two competent programmers would implement
essentially the same behaviour from it.
6. Pseudocode and flowcharts
Pseudocode represents algorithmic logic in a human-readable, language-independent form. A
flowchart represents the same kind of logic visually using standard symbols and arrows.
Common pseudocode keywords INPUT OUTPUT SET IF / ELSE WHILE FOR REPEAT END
Original flowchart diagram
START / END PROCESS DECISION
INPUT / OUTPUT
No / alternate path
This diagram was redrawn for this guide rather than copied from the uploaded internet image. Example: average of n values
START
INPUT n
SET total = 0
FOR i = 1 TO n
INPUT value
SET total = total + value
END FOR
SET average = total / n
OUTPUT average
END
8. Recursion
Recursion occurs when a procedure solves a problem by calling itself on a smaller or simpler
instance of the same problem. A correct recursive solution needs a base case and a recursive
step.
FUNCTION solve(problem)
IF problem is simple THEN
RETURN direct solution // base case
ELSE
smaller = reduce(problem)
RETURN solve(smaller) // recursive case
END IF
END FUNCTION
Key points
- The base case is the smallest case solved directly.
- The recursive case must reduce the problem.
- Each call should move toward a reachable base case.
- Recursive calls consume call-stack memory.
- Divide-and-conquer algorithms frequently use recursion.
Common mistake
A recursive definition without a reachable base case does not terminate. Incorrect reduction can
also prevent termination.
9. Decomposition and modularisation
Decomposition breaks a complex problem into smaller manageable parts. Modularisation
organizes those parts into components with clear responsibilities and interfaces.
Benefits
- Reduces cognitive load.
- Makes testing easier.
- Supports reuse.
- Localizes maintenance changes.
- Allows different components to be developed more independently. Cohesion and coupling
Concept Meaning Preferred direction Cohesion How strongly the responsibilities inside a module belong together. High Coupling How strongly one module depends on other modules. Low
Design target
Prefer modules that do one coherent job and expose only the information other modules actually
need.
11. Algorithm efficiency: time and space
Time complexity describes how the amount of computational work grows with input size. Space
complexity describes how additional memory requirements grow.
Pattern Intuition Example O(1) Roughly constant work. Array access by index O(log n) Repeatedly reduce the search space. Binary search O(n) Work grows proportionally with n. Linear scan O(n²) Nested work over the input is common. Simple comparison sorts O(2ⁿ) Can grow extremely rapidly. Some exhaustive searches
Important
Big-O describes asymptotic growth. Two algorithms with the same Big-O can still have very
different practical running times because of constants, implementation details and hardware.
12. Worked examples and revision
checklist
Example A — rectangle
INPUT length
INPUT width
SET area = length × width
SET perimeter = 2 × (length + width)
OUTPUT area
OUTPUT perimeter
Example B — even or odd
INPUT n
IF n MOD 2 = 0 THEN
OUTPUT "Even"
ELSE
OUTPUT "Odd"
END IF
Revision checklist
- Can I identify input, output and constraints?
- Can I distinguish an algorithm, pseudocode and a flowchart?
- Can I identify sequence, selection and iteration?
- Can I explain base case and recursive case?
- Can I explain divide, conquer and combine?
- Can I distinguish cohesion from coupling?
- Can I design normal, boundary and invalid tests?
- Can I explain time complexity versus space complexity?
- Can I trace pseudocode by hand?
Exam habit
For an algorithm question, start with INPUT → PROCESS → OUTPUT. Then check correctness,
termination and edge cases.