Algorithm Design & Problem-Solving
PDLC, decomposition, design tools, standard algorithms, validation, trace tables and testing.
1 Program Development Life Cycle (PDLC)
The PDLC is a four-stage framework used to develop software in a structured and manageable way.
- Abstraction โ remove irrelevant detail
- Decomposition โ break into sub-problems
- Identify inputs, processes, outputs, storage
- Define requirements clearly
- Structure diagrams
- Flowcharts
- Pseudocode
- Plan before coding
- Write program code
- Use Python / VB.NET / Java
- Iterative testing during coding
- Fix bugs as they appear
- Test with normal, boundary, extreme, abnormal data
- Verify all requirements are met
- Document results
2 Decomposition & Abstraction
- Remove unnecessary detail from a problem
- Focus only on what is relevant to solving it
- Example: a map ignores buildings, shows roads
- Makes complex problems simpler to model
- Break a large problem into smaller sub-problems
- Each sub-problem is solved independently
- Sub-solutions combine to form the full solution
- Makes large problems manageable
IPO โ Inputs, Processes, Outputs & Storage
| Component | Description | Example (Grade Calculator) | ||||||
|---|---|---|---|---|---|---|---|---|
| Inputs | Data entered into the system | Student name, exam score | Processes | Operations performed on inputs | Outputs | Results produced | Storage | Data saved for later use |
3 Design Tools
Flowchart Symbols
| Symbol | Shape | Purpose | |||
|---|---|---|---|---|---|
| Terminator | Process | Decision | Input/Output | Subroutine | Flow line |
Always use a parallelogram for INPUT and OUTPUT โ not a rectangle. Using the wrong shape will lose marks.
4 Standard Algorithms
Checks each element one by one from start to end until the target is found or the list is exhausted.
Found โ FALSE Index โ 1 WHILE Index <= Length AND Found = FALSE DO IF List[Index] = Target THEN Found โ TRUE ELSE Index โ Index + 1 ENDIF ENDWHILE IF Found = TRUE THEN OUTPUT "Found at: ", Index ELSE OUTPUT "Not found" ENDIF
Repeatedly compares adjacent pairs and swaps them if out of order. Larger values "bubble" to the end.
DECLARE Swapped : BOOLEAN DECLARE Temp : INTEGER REPEAT Swapped โ FALSE FOR i โ 1 TO Length - 1 IF List[i] > List[i+1] THEN Temp โ List[i] List[i] โ List[i+1] List[i+1] โ Temp Swapped โ TRUE ENDIF NEXT i UNTIL Swapped = FALSE
// Totalling Total โ 0 FOR i โ 1 TO n Total โ Total + List[i] NEXT i // Counting (values > 50) Count โ 0 FOR i โ 1 TO n IF List[i] > 50 THEN Count โ Count + 1 NEXT i // Max value Max โ List[1] FOR i โ 2 TO n IF List[i] > Max THEN Max โ List[i] NEXT i Average โ Total / n
5 Validation & Verification
| Validation Check | Purpose | Example | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Range check | Value must be within set limits | Length check | String must have correct number of characters | Type check | Data must be the correct type | Presence check | Field must not be empty | Format check | Data must match a specific pattern | Check digit |
Validation checks data is reasonable (automated). Verification checks data was entered correctly. They are different โ do not confuse them.
6 Test Data
| Type | Description | Example (score 0โ100) |
|---|---|---|
| Normal} -- | ||
| Boundary} -- | ||
| Extreme} -- | ||
| Abnormal} -- |
Extreme data = largest/smallest accepted value. Boundary data also includes the first rejected value just outside the range. Related but not identical.
7 Trace Tables
A trace table (dry run) documents the value of every variable and output at each step of an algorithm, used to verify logic manually.
x โ 1 y โ 10 WHILE x < 4 DO y โ y - x x โ x + 1 ENDWHILE OUTPUT y
| Step | x | y | x < 4? | Output |
|---|---|---|---|---|
| Start | Iteration 1 | Iteration 2 | Iteration 3 | Check |
8 Identifying Errors
| Error Type | Description | Example |
|---|---|---|
| Syntax error} -- | ||
| Logic error} -- | ||
| Runtime error} -- |
