Programming Fundamentals

Chapter 1
Programming and Computational Thinking

Certificate in Java-Python-Programming Languages
Programming Fundamentals   •   Certificate

Programming and Computational Thinking

Introduction

Programming is the disciplined process of expressing a solution to a problem in a form that a computer can execute. It is not simply the activity of writing commands in Java or Python. Effective programming requires a way to understand problems, represent information, design procedures, evaluate alternatives, and communicate solutions precisely. These abilities are collectively developed through computational thinking.

Computational thinking is a problem-solving approach based on ideas from computer science. It can be applied to software development, scientific research, business processes, administration, engineering, and everyday decision-making. A programmer must be able to reduce a complex situation to manageable parts, identify relevant information, recognize repeated structures, describe a sequence of operations, and test whether the result is correct.

This chapter introduces the concepts that support later study of Java and Python: programming terminology, algorithms, abstraction, decomposition, pattern recognition, pseudocode, flowcharts, and the input-process-output model. It also presents a basic problem-solving lifecycle that can be used before, during, and after implementation.

Learning Objectives

By the end of this chapter, you should be able to:

  • distinguish among programs, programming languages, algorithms, and software;
  • describe the four major practices of computational thinking;
  • decompose a problem and identify suitable abstractions;
  • write clear pseudocode and interpret standard flowchart symbols;
  • apply the input-process-output model to simple problems;
  • follow a basic problem-solving lifecycle from requirements to maintenance;
  • identify common sources of programming error and improve solution quality;
  • explain why testing, documentation, ethics, and maintainability matter in professional programming.

1. Programming Terminology

A computer is an electronic system that accepts data, performs operations according to instructions, stores information, and produces results. A program is an ordered set of instructions that directs a computer to perform a task. A collection of programs, data, and related documentation is generally called software.

A programming language is a formal language used to express algorithms and computational instructions. Java and Python are high-level programming languages: they provide abstractions that allow people to write instructions without directly specifying individual machine operations. A computer ultimately executes machine instructions, so source code must be translated or interpreted before or during execution.

Important terms include:

TermMeaning
Source codeHuman-readable instructions written in a programming language
SyntaxRules governing the form of valid statements
SemanticsThe meaning or behavior represented by valid code
CompilerA program that translates source code, often into another executable form, before execution
InterpreterA program or runtime system that executes source instructions through an interpretation process
RuntimeThe period during which a program is executing, or the software environment supporting execution
VariableA named storage location or reference whose associated value may change
ConstantA value intended not to change during a computation
DataRepresentations of facts, measurements, symbols, or observations
InformationData interpreted in a meaningful context
BugA defect that causes a program to behave incorrectly or undesirably
DebuggingThe systematic process of locating and correcting defects
AlgorithmA finite, ordered, and sufficiently precise procedure for solving a problem
Function or methodA named, reusable unit of instructions that performs a task
User interfaceThe means through which a user interacts with a program

Syntax and semantics must be distinguished. For example, a statement may be syntactically valid but semantically inappropriate. A program that adds a person's age to a telephone number may execute without a syntax error, yet the operation may not make sense for the intended problem.

2. Algorithms and Problem Solving

An algorithm is a procedure for solving a problem or completing a task. A useful algorithm has several characteristics:

  1. Finiteness: it eventually terminates.
  2. Definiteness: each step is stated clearly enough to be carried out.
  3. Input: it may accept zero or more well-defined inputs.
  4. Output: it produces at least one result or effect.
  5. Effectiveness: each operation is feasible and understandable.
  6. Generality: it applies to a relevant class of problems rather than only one accidental example.

An algorithm is not the same as a program. An algorithm is a solution design that can often be expressed in natural language, pseudocode, a flowchart, or code. A program is an implementation of an algorithm in a particular programming language and execution environment.

For example, the problem “determine whether a number is even” can be described algorithmically:

  1. Obtain a number.
  2. Divide it by 2 and inspect the remainder.
  3. If the remainder is 0, report that the number is even.
  4. Otherwise, report that the number is odd.

For an integer n, the condition can be expressed as n mod 2 = 0. The symbol mod denotes the remainder operation. This condition assumes that n is an integer; the same wording is not automatically appropriate for arbitrary real-number values.

A good algorithm separates what must be achieved from the details of a particular programming language. This separation makes the solution easier to inspect, discuss, test, and translate into Java or Python.

3. Computational Thinking

Computational thinking is commonly explained through four complementary practices: decomposition, abstraction, pattern recognition, and algorithmic thinking. These are not strictly sequential. A programmer may move repeatedly among them as understanding develops.

3.1 Decomposition

Decomposition means breaking a large or complex problem into smaller parts. A decomposed problem is easier to understand because each part has a more limited purpose. For example, an online examination system might be divided into:

  • registering a candidate;
  • presenting questions;
  • recording answers;
  • calculating a score;
  • producing a report.

Each component can be designed, implemented, and tested separately. Decomposition also encourages modularity. A module should have a clear responsibility and a well-defined relationship with other modules.

A useful decomposition asks:

  • What is the overall goal?
  • What major tasks are necessary?
  • Can each task be divided further?
  • What information must pass between tasks?
  • Can one task be reused in another context?

Decomposition should not create unnecessary complexity. Excessively small modules may make a program difficult to understand, while excessively large modules may be difficult to test and maintain.

3.2 Abstraction

Abstraction is the practice of focusing on important characteristics while suppressing unnecessary detail. A map is an abstraction of a physical region: it preserves information needed for navigation but omits most buildings, trees, and surface details. Similarly, a function named calculateTotal allows a programmer to use a calculation without repeatedly considering every internal operation.

Abstraction operates at different levels. At a high level, a program may be described as “process a customer order.” At a lower level, this may involve validating an item code, retrieving a price, multiplying price by quantity, applying a discount, and recording a transaction.

A useful abstraction must preserve the details relevant to the current purpose. Omitting irrelevant detail improves clarity, but omitting essential detail produces an incomplete or misleading model. In programming, abstraction is supported by functions, classes, data types, interfaces, and libraries.

3.3 Pattern Recognition

Pattern recognition involves identifying similarities, repetitions, or relationships that can support a general solution. If a program repeatedly validates a number, a reusable validation function may be appropriate. If several reports use the same calculation, that calculation can be represented once and reused.

Patterns may occur in:

  • repeated data structures, such as lists of student marks;
  • repeated operations, such as reading and validating input;
  • repeated control structures, such as processing every item in a collection;
  • recurring errors, such as failure to handle empty input;
  • relationships between inputs and outputs.

Pattern recognition must be used carefully. Superficial similarity does not guarantee that two situations should be handled identically. A pattern is useful when the shared characteristics are relevant and the differences can be represented safely.

3.4 Algorithmic Thinking

Algorithmic thinking involves designing a precise sequence of steps, decisions, and repetitions. It requires anticipating different cases rather than describing only the most convenient example. An algorithm for calculating a student average must specify what happens when no marks are supplied, when an input is invalid, or when a mark lies outside the permitted range.

Algorithmic thinking also encourages efficiency. At certificate level, efficiency can be considered practically: avoid unnecessary work, repeated calculations, and confusing procedures. More advanced study may measure time and memory requirements formally, but the fundamental principle is already useful: a correct solution should also be reasonably usable and maintainable.

4. The Input-Process-Output Model

The input-process-output (IPO) model provides a simple way to analyze a computational task.

  • Input is data supplied to the system.
  • Process is the transformation or computation applied to that data.
  • Output is the result produced by the system.

For a program that calculates the area of a rectangle:

  • Input: length and width;
  • Process: multiply length by width;
  • Output: area.

The relationship is:

area = length × width

Here, length and width represent measurements in the same linear unit, and area is expressed in the corresponding square unit. The formula assumes a rectangle and non-negative physical dimensions.

The IPO model can be expanded to include storage, validation, and feedback. A real program may read input, validate it, process it, store intermediate or final results, and display output. Nevertheless, IPO remains valuable because it prevents a common design error: beginning to code before identifying what information is required and what result is expected.

Consider a program that calculates a worker’s gross weekly pay. Inputs might include hours worked and hourly rate. Processing includes multiplication, but a complete specification must also state how overtime is handled. If overtime begins after 40 hours and is paid at 1.5 times the regular rate, then the algorithm must distinguish ordinary hours from overtime hours. This illustrates that a simple IPO description may need business rules before it can become a reliable algorithm.

5. Pseudocode

Pseudocode is an informal, structured description of an algorithm. It resembles programming code but does not follow the exact syntax of Java, Python, or another language. Its purpose is to communicate logic clearly before implementation.

Good pseudocode should:

  • use one action per step where practical;
  • use meaningful names;
  • show sequence, selection, and repetition explicitly;
  • identify inputs and outputs;
  • avoid language-specific details unless they clarify the logic;
  • handle important exceptional or boundary cases.

Common pseudocode structures include:

Sequence

READ length
READ width
SET area TO length × width
DISPLAY area

Selection

READ mark
IF mark >= 50 THEN
    DISPLAY "Pass"
ELSE
    DISPLAY "Fail"
END IF

Repetition

SET total TO 0
FOR each mark in the collection
    SET total TO total + mark
END FOR
DISPLAY total

Pseudocode is not executable, and conventions vary. The important requirement is consistency and clarity. A reader should be able to follow the logic without guessing what a step means.

6. Flowcharts

A flowchart is a graphical representation of an algorithm. Standard symbols communicate different roles:

Symbol or conventionPurpose
OvalStart or end of a process
RectangleProcessing step
ParallelogramInput or output
DiamondDecision or condition
ArrowDirection of control flow

A decision should normally have clearly labelled branches, such as “Yes” and “No.” Flow lines should move in a readable direction and should not create ambiguous crossings. Although flowcharts are useful for small and medium-sized procedures, very large programs are often better represented through modular documentation, pseudocode, models, and source code.

A flowchart for determining whether a number is positive can be described as follows: start, read a number, test whether it is greater than zero, display “positive” if true, otherwise display “zero or negative,” and end. The decision is essential because the output depends on a condition.

Pseudocode and flowcharts represent similar logic in different ways. Pseudocode is often faster to write and easier to revise. Flowcharts can provide an immediate visual overview, particularly for decisions and loops. Neither representation guarantees correctness; both must be reviewed and tested.

7. The Basic Problem-Solving Lifecycle

A disciplined programming lifecycle reduces wasted effort and improves reliability.

7.1 Understand and Specify the Problem

First identify the purpose, users, constraints, and expected result. Ambiguous requirements are a major source of defects. Ask what must be entered, what rules apply, what output is required, and what should happen when input is invalid or incomplete.

A requirement such as “calculate the bill” is insufficient. A better specification identifies products, quantities, prices, tax rules, discounts, currency, rounding policy, and receipt requirements.

7.2 Analyze Inputs, Processes, and Outputs

List the data required, describe the transformations, and define the expected results. Identify data types where relevant: a count may be an integer, a price may require decimal representation, and a name is text.

7.3 Design the Solution

Use decomposition, abstraction, pseudocode, flowcharts, or another suitable design method. Consider normal cases, boundary cases, invalid cases, and exceptional conditions. Select a design that is understandable and appropriately reusable.

7.4 Implement

Translate the design into Java, Python, or another appropriate language. Use meaningful names, consistent formatting, comments that explain decisions, and small functions with clear responsibilities. Implementation should follow the approved logic, but coding may reveal requirements that need clarification.

7.5 Test and Debug

Testing involves executing a program with selected data and comparing actual results with expected results. Useful categories include:

  • Normal-case testing: ordinary valid inputs;
  • Boundary testing: values at or near limits;
  • Invalid-input testing: values that violate requirements;
  • Extreme-case testing: unusually large, small, or empty inputs;
  • Regression testing: checking that later changes have not broken earlier behavior.

Debugging is not random trial and error. A systematic approach is to reproduce the problem, isolate the relevant section, inspect assumptions and values, correct the cause, and retest.

Errors are often classified as:

  • Syntax errors: violations of language grammar, usually detected before successful execution;
  • Runtime errors: failures occurring while the program runs, such as attempting an invalid operation;
  • Logic errors: the program runs but produces an incorrect result.

7.6 Document and Maintain

Documentation explains purpose, assumptions, input formats, outputs, and important design decisions. Maintenance includes correcting defects, adapting to changed requirements, improving performance, and updating compatibility. A program is rarely finished when it first produces an output; it must remain understandable and useful over time.

8. Worked Example: Determining a Course Result

Suppose a training centre needs a program that receives a learner’s examination mark and reports “Pass” when the mark is at least 50; otherwise it reports “Fail.” The permitted mark range is 0 to 100.

Problem analysis

  • Input: one numerical mark.
  • Validation: the mark must be between 0 and 100 inclusive.
  • Process: compare the mark with 50.
  • Output: an error message for invalid input, or “Pass”/“Fail” for valid input.

Pseudocode

READ mark
IF mark < 0 OR mark > 100 THEN
    DISPLAY "Invalid mark"
ELSE IF mark >= 50 THEN
    DISPLAY "Pass"
ELSE
    DISPLAY "Fail"
END IF

Test design

Test inputExpected outputPurpose
75PassNormal passing case
40FailNormal failing case
50PassLower passing boundary
49FailValue immediately below boundary
0FailLower valid limit
100PassUpper valid limit
-1Invalid markInvalid low input
101Invalid markInvalid high input

This example demonstrates that a comparison alone is not a complete solution. Input validation is part of the problem specification. It also shows why boundary testing is valuable: an error such as using > instead of >= would be exposed by the mark 50.

9. Applied Case: A Small Library Loan System

The following is an illustrative case.

Background. A community learning centre lends books to registered members. Staff currently record loans manually, resulting in missing return dates and difficulty identifying overdue items.

Problem. The centre wants a simple system that records a member identifier, book identifier, loan date, and due date; checks whether a member is registered; and reports overdue loans.

Analysis. The system inputs member and book information, validates identifiers, stores loan records, calculates or records due dates according to centre policy, and produces reports. Important questions include: Can a member borrow more than a specified number of books? Can a book already on loan be issued again? What happens when a date is missing or invalid? Who may view member information?

Approach. Decompose the system into member validation, book availability, loan creation, return processing, and overdue reporting. Abstract the operation of creating a loan into a reusable function or method. Recognize the pattern that many records must be processed in the same way when producing an overdue report. Use pseudocode before implementation:

FOR each loan record
    IF return date is empty AND today is later than due date THEN
        DISPLAY member identifier, book identifier, and due date
    END IF
END FOR

Outcome. A well-designed system can reduce search time and improve consistency. The outcome depends not only on code but also on accurate data entry, clearly defined loan policies, backups, access controls, and staff training.

Learning points. The case demonstrates that programming begins with requirements and modelling, not syntax. It also demonstrates the importance of privacy. Member identifiers and borrowing histories may be personal information and should be accessed only for legitimate purposes. A programmer should collect only necessary data, restrict access, protect stored records, and avoid exposing private information in test data or error messages.

10. Quality, Ethics, and Contemporary Practice

A technically functioning program may still be poor software if it is inaccessible, insecure, unfair, or impossible to maintain. Professional programming therefore considers more than immediate output.

Correctness and reliability require explicit requirements, validation, testing, and careful handling of exceptional cases. Usability requires understandable messages and interfaces. Accessibility means that people with different abilities should be able to use the system where feasible. Security involves protecting data, controlling access, and avoiding unsafe handling of input.

Programming also has ethical implications. Automated decisions can reproduce bias if the data or rules are biased. A developer should question whether a system collects excessive personal information, whether users understand important decisions, and whether an automated result can be reviewed or corrected. Privacy and data-protection obligations vary by jurisdiction, so professional work must follow applicable laws, institutional policies, and contractual requirements.

Artificial intelligence tools can assist with explanations, code suggestions, and test generation, but they do not replace human responsibility. Generated code may contain defects, insecure practices, licensing problems, or inappropriate assumptions. Any AI-assisted output must be reviewed, tested, documented, and checked against the requirements. Confidential data should not be entered into tools without authorization.

Best practices for beginning programmers include:

  • clarify the problem before coding;
  • use meaningful names and consistent formatting;
  • keep functions focused on one main responsibility;
  • validate external input;
  • test normal, boundary, and invalid cases;
  • make assumptions explicit;
  • avoid duplicating logic unnecessarily;
  • document decisions and limitations;
  • protect personal and confidential information;
  • use version control and preserve working versions;
  • treat error messages as part of the user experience.

Challenges and Limitations

The techniques in this chapter are foundational rather than complete. IPO can oversimplify interactive systems in which input and output occur repeatedly. Flowcharts may become unwieldy for large software systems. Pseudocode can be ambiguous if authors use inconsistent conventions. Decomposition may be difficult when requirements are unclear or when components are strongly dependent on one another. Pattern recognition can lead to inappropriate generalization. Finally, a correct algorithm may still be inefficient, inaccessible, or unsuitable if the surrounding assumptions are wrong.

These limitations do not reduce the value of the techniques. They show why programming is iterative. A design is proposed, examined, implemented, tested, and refined as new information becomes available.

Chapter Summary

Programming is the implementation of computational solutions in a formal language. An algorithm is a finite and precise procedure, while a program is an implementation of that procedure. Computational thinking supports programming through decomposition, abstraction, pattern recognition, and algorithmic thinking.

The input-process-output model helps identify the data a system receives, the transformations it performs, and the results it produces. Pseudocode and flowcharts provide language-independent ways to design and communicate algorithms. A basic problem-solving lifecycle consists of understanding requirements, analysing inputs and outputs, designing, implementing, testing, debugging, documenting, and maintaining a solution.

Professional programming requires more than code that runs. Correctness, validation, testing, maintainability, usability, security, privacy, accessibility, and ethical responsibility must also be considered. These foundations prepare learners to study Java and Python with a problem-solving mindset rather than treating programming as memorization of syntax.

Key Terms

Algorithm: A finite, precise procedure for solving a problem.

Abstraction: Focusing on relevant features while omitting unnecessary detail.

Bug: A defect in a program.

Computational thinking: A structured approach to solving problems using computer-science ideas.

Compiler: Software that translates source code into another executable representation.

Decomposition: Breaking a complex problem into smaller parts.

Debugging: Finding and correcting program defects.

Flowchart: A graphical representation of an algorithm.

Input: Data supplied to a computational system.

Logic error: An error in which a program runs but produces an incorrect result.

Output: A result produced by a computational system.

Pattern recognition: Identifying useful similarities or repetitions.

Pseudocode: A structured, language-independent description of an algorithm.

Programming language: A formal language used to express computational instructions.

Runtime error: An error occurring while a program executes.

Semantics: The meaning or behavior of a program statement.

Syntax: The rules governing the form of valid program statements.

Testing: Executing a program with selected data to evaluate its behavior.

Variable: A named storage location or reference associated with a value that may change.

Review Questions

Short Answer Questions

  1. What is the difference between an algorithm and a program?
  2. Define decomposition and give one programming-related example.
  3. What are the three elements of the input-process-output model?
  4. Why is pseudocode useful before implementation?
  5. Distinguish a syntax error from a logic error.

Long Answer Questions

  1. Explain the four major practices of computational thinking and show how they can work together when designing a program.
  2. Describe the stages of the basic problem-solving lifecycle from requirements analysis through maintenance.
  3. Compare pseudocode and flowcharts, including advantages and limitations of each.
  4. Explain why input validation and boundary testing are necessary for reliable programs.
  5. Discuss the ethical, privacy, security, and accessibility responsibilities of a programmer.

Analytical / Application Questions

  1. Design the IPO model and pseudocode for a program that accepts three numbers and displays the largest. State how ties should be handled.
  2. A payroll program produces correct results for ordinary hours but fails when an employee works exactly 40 hours or enters a negative number of hours. Identify the likely design and testing issues and propose test cases.
  3. Decompose a small appointment-booking system into modules. For each module, identify its inputs, main process, outputs, and at least one possible validation rule.

Multiple Choice Questions with Answers

Question 1

Which statement best describes an algorithm?

A. A finite and precise procedure for solving a problem

B. A hardware component that stores data

C. A graphical user interface only

D. A programming language keyword

Correct Answer: A. A finite and precise procedure for solving a problem

Question 2

Which computational-thinking practice breaks a complex problem into smaller parts?

A. Abstraction

B. Decomposition

C. Compilation

D. Debugging

Correct Answer: B. Decomposition

Question 3

In the input-process-output model, multiplying length by width is the:

A. Input

B. Storage

C. Process

D. Output

Correct Answer: C. Process

Question 4

Which flowchart symbol normally represents a decision?

A. Oval

B. Rectangle

C. Parallelogram

D. Diamond

Correct Answer: D. Diamond

Question 5

What is the main purpose of pseudocode?

A. To provide a language-independent description of logic

B. To replace all program testing

C. To execute directly on a computer

D. To specify computer hardware circuits

Correct Answer: A. To provide a language-independent description of logic

Question 6

A program runs successfully but calculates an incorrect result because a comparison is wrong. This is a:

A. Syntax error

B. Logic error

C. Compilation unit

D. Hardware error

Correct Answer: B. Logic error

Question 7

Which test input is most useful for checking whether a mark of at least 50 is correctly classified as a pass?

A. 25

B. 40

C. 50

D. 80

Correct Answer: C. 50

Question 8

Which practice focuses on relevant features while hiding unnecessary implementation detail?

A. Abstraction

B. Iteration

C. Validation

D. Output

Correct Answer: A. Abstraction

Question 9

For a rectangle with length 6 cm and width 4 cm, the area is:

A. 10 cm

B. 20 cm²

C. 24 cm²

D. 24 cm

Correct Answer: C. 24 cm²

Question 10

Which action is most appropriate when using AI-generated code?

A. Use it without review if it compiles

B. Review, test, and check it against requirements

C. Assume it is secure because it was generated automatically

D. Enter confidential data into any AI tool for better results

Correct Answer: B. Review, test, and check it against requirements

Programming Fundamentals
Chapter 1 of 14