PROGRAMMING FUNDAMENTALS | REVISION
DESIGNED FOR IB EXAMINATIONS
OBJECTIVES
4.1.3 Explain the role of sub-procedures in solving a problem
4.1.7 Explain the relationship between the decisions and conditions of a system
4.1.13 Identify exceptions that need to be considered in a specified problem solution
4.1.15 Describe how concurrent processing can be used to solve a problem
4.1.16 Evaluate the decision to use concurrent processing in solving a problem
4.1.19 Construct an abstraction from a specified situation
4.1.20 Distinguish between a real-world entity and its abstraction
4.2.4 Analyse an algorithm presented as a flow chart
4.2.7 Suggest suitable algorithms to solve a specific problem
4.2.8 Deduce the efficiency of an algorithm in the context of its use
4.3.11 Construct algorithms using the access methods of a collection
4.1.3 Explain the role of sub-procedures in solving a problem
4.1.7 Explain the relationship between the decisions and conditions of a system
4.1.13 Identify exceptions that need to be considered in a specified problem solution
4.1.15 Describe how concurrent processing can be used to solve a problem
4.1.16 Evaluate the decision to use concurrent processing in solving a problem
4.1.19 Construct an abstraction from a specified situation
4.1.20 Distinguish between a real-world entity and its abstraction
4.2.4 Analyse an algorithm presented as a flow chart
4.2.7 Suggest suitable algorithms to solve a specific problem
4.2.8 Deduce the efficiency of an algorithm in the context of its use
4.3.11 Construct algorithms using the access methods of a collection
SECTION 1 | SUB PROCEDURES (4.1.3)
When solving complex computational problems, it is rarely effective to treat the solution as a single, continuous sequence of steps. Instead, problems are broken down into smaller, manageable components. These components are implemented as sub-procedures.
A sub-procedure is a named block of code (such as a procedure, function, or method) that performs a specific task and can be called from elsewhere in a program.
Decomposition of a Problem
The primary role of sub-procedures is to support decomposition, which is the process of breaking a large problem into smaller sub-problems.
Using sub-procedures allows a programmer to:
Improving Readability and Maintainability
Sub-procedures make algorithms easier to read and understand. A main program that calls well-named sub-procedures clearly communicates what the program does without needing to show how every task is performed.
This also improves maintainability:
Reuse of Code
A sub-procedure can be reused multiple times within the same program, or across different programs. This avoids duplication of code and ensures consistency.
For example, a sub-procedure that calculates a total or checks user input can be called whenever that functionality is required.
Code reuse:
Supporting AbstractionSub-procedures contribute to abstraction by hiding implementation details. When a sub-procedure is called, the programmer only needs to know:
Testing and Debugging
Sub-procedures can be tested individually, which simplifies debugging. If a program produces incorrect results, each sub-procedure can be checked separately to identify the source of the error.
This modular approach improves reliability and supports systematic testing.
Summary
Sub-procedures play a key role in problem solving by:
Example of a Sub-procedure
The following example shows how a problem can be broken down using a sub-procedure. The task is to calculate and display the total cost of items, including tax.
Instead of placing all instructions in the main program, a sub-procedure is used to calculate the total cost.
A sub-procedure is a named block of code (such as a procedure, function, or method) that performs a specific task and can be called from elsewhere in a program.
Decomposition of a Problem
The primary role of sub-procedures is to support decomposition, which is the process of breaking a large problem into smaller sub-problems.
Using sub-procedures allows a programmer to:
- Focus on one task at a time
- Reduce the complexity of the main program
- Solve each part of the problem independently
Improving Readability and Maintainability
Sub-procedures make algorithms easier to read and understand. A main program that calls well-named sub-procedures clearly communicates what the program does without needing to show how every task is performed.
This also improves maintainability:
- Errors are easier to locate and fix
- Changes can be made to one sub-procedure without affecting the entire program
- Programs are easier for other developers to understand and modify
Reuse of Code
A sub-procedure can be reused multiple times within the same program, or across different programs. This avoids duplication of code and ensures consistency.
For example, a sub-procedure that calculates a total or checks user input can be called whenever that functionality is required.
Code reuse:
- Saves development time
- Reduces the likelihood of errors
- Promotes efficient program design
Supporting AbstractionSub-procedures contribute to abstraction by hiding implementation details. When a sub-procedure is called, the programmer only needs to know:
- What the sub-procedure does
- What inputs it requires
- What output (if any) it produces
Testing and Debugging
Sub-procedures can be tested individually, which simplifies debugging. If a program produces incorrect results, each sub-procedure can be checked separately to identify the source of the error.
This modular approach improves reliability and supports systematic testing.
Summary
Sub-procedures play a key role in problem solving by:
- Breaking problems into smaller, manageable parts
- Improving readability and structure of algorithms
- Enabling code reuse
- Supporting abstraction
- Simplifying testing and debugging
Example of a Sub-procedure
The following example shows how a problem can be broken down using a sub-procedure. The task is to calculate and display the total cost of items, including tax.
Instead of placing all instructions in the main program, a sub-procedure is used to calculate the total cost.
PSEUDOCODE
How This Example Demonstrates the Role of Sub-procedures
- The sub-procedure calculateTotal performs one specific task: calculating a total including tax.
- The main program does not need to know how the calculation is done, only that the sub-procedure returns the correct value.
- If the tax calculation needs to change, only the sub-procedure must be updated.
- The same sub-procedure could be reused elsewhere in the program whenever a total cost needs to be calculated.
What is the main role of a sub-procedure in solving a problem?
To store large amounts of data permanently
To break a problem into smaller, manageable tasks that perform specific functions
To ensure a program always runs faster
To replace the need for a main program
SECTION 2 | DECISION RELATIONSHIPS (4.1.7)
The Relationship Between Decisions and Conditions in a System
In computational systems, programs often need to make decisions in order to respond correctly to different situations. These decisions are not made arbitrarily; they are based on conditions. Understanding the relationship between decisions and conditions is essential for designing correct and predictable algorithms.
Conditions in a System
A condition is a logical expression that evaluates to either TRUE or FALSE. Conditions are formed by:
Decisions in a System
A decision is an action taken by a system based on the result of a condition. Decisions determine:
How Conditions Drive Decisions
The relationship between conditions and decisions is cause and effect:
Multiple Conditions and Complex Decisions
More complex systems often require multiple conditions to be evaluated together. Logical operators allow conditions to be combined so that decisions can reflect more realistic scenarios.
For example:
Importance in System Design
Understanding the relationship between decisions and conditions helps to:
Summary
In computational systems, programs often need to make decisions in order to respond correctly to different situations. These decisions are not made arbitrarily; they are based on conditions. Understanding the relationship between decisions and conditions is essential for designing correct and predictable algorithms.
Conditions in a System
A condition is a logical expression that evaluates to either TRUE or FALSE. Conditions are formed by:
- Comparing values using relational operators (such as =, <, >)
- Combining expressions using logical operators (AND, OR, NOT)
Decisions in a System
A decision is an action taken by a system based on the result of a condition. Decisions determine:
- Which path of execution is followed
- Which instructions are performed
- How the system responds to different inputs or states
How Conditions Drive Decisions
The relationship between conditions and decisions is cause and effect:
- A condition is evaluated first
- The result of the condition determines which decision is made
Multiple Conditions and Complex Decisions
More complex systems often require multiple conditions to be evaluated together. Logical operators allow conditions to be combined so that decisions can reflect more realistic scenarios.
For example:
- A decision may require several conditions to be TRUE at the same time
- A decision may occur if at least one condition is TRUE
- A condition may be inverted using NOT to change the decision outcome
Importance in System Design
Understanding the relationship between decisions and conditions helps to:
- Predict system behaviour accurately
- Ensure all possible scenarios are handled
- Avoid logical errors and unexpected outcomes
- Design clear and efficient algorithms
Summary
- Conditions are logical expressions that evaluate to TRUE or FALSE.
- Decisions are actions or paths chosen based on those conditions.
- Conditions determine when and why decisions occur.
- Complex decisions are formed by combining multiple conditions.
Scenario: Login System — Build the correct condition → decision path
A system checks whether a user is allowed to log in.
Click the steps below in the order the system would perform them. Your chosen order appears in the “Your path” box.
Available steps (click to add to your path)
Your path (selected order)
SECTION 3 | EXCEPTIONS FOR PROBLEMS
When designing a solution to a computational problem, it is not enough to consider only the normal or expected inputs and outcomes. A robust system must also account for exceptions—situations that fall outside normal operation and could cause errors or unexpected behaviour if not handled correctly.
What Is an Exception?
An exception is a situation that occurs when a program encounters:
Why Exceptions Must Be Identified
Identifying exceptions early in the problem-solving process allows a programmer to:
Common Types of Exceptions
When analysing a problem, typical exceptions to consider include:
Identifying Exceptions in a Specified Problem
To identify exceptions effectively, a programmer should:
Handling Exceptions
Once exceptions have been identified, the solution can be designed to handle them appropriately by:
The method of handling an exception depends on the nature of the problem and the expected behaviour of the system.
Summary
What Is an Exception?
An exception is a situation that occurs when a program encounters:
- Invalid or unexpected input
- Unusual system conditions
- Situations that prevent the normal flow of an algorithm
Why Exceptions Must Be Identified
Identifying exceptions early in the problem-solving process allows a programmer to:
- Prevent system crashes or incorrect results
- Improve the reliability and robustness of a solution
- Ensure the system behaves predictably in all situations
- Provide meaningful feedback to users
Common Types of Exceptions
When analysing a problem, typical exceptions to consider include:
- Invalid input
Input that does not match the expected data type or format, such as text entered where a number is required. - Out-of-range values
Values that fall outside acceptable limits, such as negative quantities or values exceeding a maximum allowed value. - Missing data
Required information that has not been provided, such as empty fields or null values. - Boundary cases
Values at the extreme ends of acceptable ranges, such as zero, maximum capacity, or minimum values. - Logical conflicts
Inputs that are valid individually but invalid when combined, such as selecting mutually exclusive options.
Identifying Exceptions in a Specified Problem
To identify exceptions effectively, a programmer should:
- Examine all inputs and determine what makes them invalid
- Consider extreme and unusual cases
- Ask what could go wrong at each step of the algorithm
- Consider how the system should respond to unexpected situations
Handling Exceptions
Once exceptions have been identified, the solution can be designed to handle them appropriately by:
- Rejecting invalid input
- Requesting corrected input from the user
- Using default values
- Safely terminating or redirecting program execution
The method of handling an exception depends on the nature of the problem and the expected behaviour of the system.
Summary
- Exceptions are unusual or unexpected situations that disrupt normal program flow.
- Identifying exceptions is a key part of designing reliable solutions.
- Common exceptions include invalid input, boundary cases, and missing data.
- Anticipating exceptions helps ensure a system behaves correctly in all scenarios.
SECTION 4 | CONCURRENT PROCESSING
Some computational problems involve multiple tasks that can be carried out at the same time. Instead of executing these tasks one after another, a system can use concurrent processing to improve efficiency and responsiveness.
What Is Concurrent Processing?
Concurrent processing is the execution of multiple tasks during the same time period. These tasks may run:
How Concurrent Processing Is Used
Concurrent processing is used when a problem can be divided into independent or semi-independent tasks. Each task can be handled separately while the overall problem is being solved.
Examples include:
Improving Efficiency and Responsiveness
Concurrent processing can:
Problem-Solving with Concurrent Processing
When solving a problem using concurrent processing, the programmer must:
Example Scenario
Consider an online booking system:
Summary
What Is Concurrent Processing?
Concurrent processing is the execution of multiple tasks during the same time period. These tasks may run:
- Simultaneously on multiple processors or cores, or
- Interleaved on a single processor by rapidly switching between tasks
How Concurrent Processing Is Used
Concurrent processing is used when a problem can be divided into independent or semi-independent tasks. Each task can be handled separately while the overall problem is being solved.
Examples include:
- Handling multiple user requests in a system
- Performing background tasks while a main task continues
- Processing input while output is being generated
Improving Efficiency and Responsiveness
Concurrent processing can:
- Reduce total execution time
- Allow systems to remain responsive while performing complex operations
- Make better use of available hardware resources
Problem-Solving with Concurrent Processing
When solving a problem using concurrent processing, the programmer must:
- Identify tasks that can run independently
- Decide how tasks will share data or resources
- Ensure tasks do not interfere with each other
Example Scenario
Consider an online booking system:
- One process checks availability
- Another processes payments
- Another updates the database
Summary
- Concurrent processing allows multiple tasks to be active at the same time.
- It is used when a problem can be broken into parallel or overlapping tasks.
- It improves efficiency and responsiveness in many systems.
- Careful design is required to manage shared resources and ensure correctness.
How can concurrent processing be used to solve a problem?
By ensuring tasks are completed strictly one after another
By allowing multiple tasks to be in progress at the same time to improve efficiency
By removing the need for decision-making in a program
By guaranteeing that all programs run faster in every situation
SECTION 5 | DECISSION TO USE CONCURRENT PROCESSING
While concurrent processing can improve performance and responsiveness, it is not always the best choice for every problem. Evaluating whether to use concurrent processing requires weighing its advantages against its limitations in the context of a specific problem.
Potential Benefits of Concurrent Processing
Using concurrent processing can be beneficial when:
Potential Drawbacks of Concurrent Processing
Despite its advantages, concurrent processing introduces additional complexity.
Possible disadvantages include:
Factors to Consider When Evaluating the Decision
When deciding whether to use concurrent processing, a programmer should consider:
Example Evaluation
For a simple program that performs a single calculation, concurrent processing offers no advantage and adds unnecessary complexity.
In contrast, a web server handling many user requests simultaneously benefits greatly from concurrent processing.
This shows that the suitability of concurrent processing depends on the nature of the problem.
Summary
Potential Benefits of Concurrent Processing
Using concurrent processing can be beneficial when:
- Tasks can run independently with minimal interaction
- The system needs to handle multiple activities at the same time
- Responsiveness is critical, such as in interactive or real-time systems
- Hardware supports multiple processors or cores
Potential Drawbacks of Concurrent Processing
Despite its advantages, concurrent processing introduces additional complexity.
Possible disadvantages include:
- Increased difficulty in designing and debugging algorithms
- Risk of data conflicts when tasks share resources
- Overhead from managing multiple processes or threads
- Little or no performance gain if tasks are highly dependent or hardware is limited
Factors to Consider When Evaluating the Decision
When deciding whether to use concurrent processing, a programmer should consider:
- Task independence: Can tasks run without waiting for each other?
- Data sharing: Do tasks need access to the same data?
- System resources: Does the hardware support concurrency effectively?
- Problem scale: Is the problem large or time-sensitive enough to justify concurrency?
Example Evaluation
For a simple program that performs a single calculation, concurrent processing offers no advantage and adds unnecessary complexity.
In contrast, a web server handling many user requests simultaneously benefits greatly from concurrent processing.
This shows that the suitability of concurrent processing depends on the nature of the problem.
Summary
- Concurrent processing can improve efficiency and responsiveness.
- It increases complexity and can introduce new risks.
- The decision to use concurrency must be evaluated based on the specific problem.
- Effective evaluation balances performance gains against design complexity.
Which of the following scenarios could benefit from using concurrent processing?
Select all scenarios where concurrent processing would be appropriate, then click Check answers.
SECTION 5 | CONSTRUCT AND ABSTRACTION
In computer science, real-world situations are often too complex to be represented in full detail. To design effective solutions, programmers use abstraction to focus only on the elements that are relevant to the problem being solved.
What Is an Abstraction?
An abstraction is a simplified representation of a real-world situation or system. It includes:
Specified Situations and Abstraction
A specified situation provides a clear context, such as:
The abstraction must be detailed enough to solve the problem, but simple enough to avoid unnecessary complexity.
Steps in Constructing an Abstraction
To construct an abstraction from a specified situation, a programmer typically:
Example of Abstraction
In a real-world library system, many details exist, such as building layout, furniture, and staff uniforms.
When constructing an abstraction for a computer system, the focus might be limited to:
Importance of Abstraction in Problem Solving
Abstraction is essential because it:
Summary
What Is an Abstraction?
An abstraction is a simplified representation of a real-world situation or system. It includes:
- The essential features needed to solve the problem
- The relevant data and behaviours
- The removal of unnecessary detail
Specified Situations and Abstraction
A specified situation provides a clear context, such as:
- A description of a real-world system
- Rules or constraints that apply
- Goals the system must achieve
The abstraction must be detailed enough to solve the problem, but simple enough to avoid unnecessary complexity.
Steps in Constructing an Abstraction
To construct an abstraction from a specified situation, a programmer typically:
- Identifies the purpose of the system
What problem is being solved, and what outcome is required? - Selects relevant entities
These are the objects or components that directly affect the solution. - Identifies key attributes and behaviours
Only the data and actions needed for the problem are included. - Ignores irrelevant details
Real-world features that do not affect the solution are excluded.
Example of Abstraction
In a real-world library system, many details exist, such as building layout, furniture, and staff uniforms.
When constructing an abstraction for a computer system, the focus might be limited to:
- Books
- Users
- Loans
- Due dates
Importance of Abstraction in Problem Solving
Abstraction is essential because it:
- Reduces cognitive load when designing solutions
- Makes algorithms easier to design and understand
- Allows solutions to be adapted to similar problems
- Supports modular and scalable system design
Summary
- An abstraction is a simplified model of a real-world situation.
- Constructing an abstraction involves selecting relevant details and ignoring irrelevant ones.
- The abstraction is guided by the specified problem requirements.
- Effective abstraction is a key skill in algorithm design and system modelling.
Which action best demonstrates constructing an abstraction from a specified situation?
Including every real-world detail to ensure accuracy
Selecting only the relevant features needed to solve the problem
Writing code before analysing the problem
Ignoring the problem specification completely
SECTION 5 | REAL WORLD ENTITY AND ITS ABSTRACTION
Real-World EntitiesA real-world entity is a physical or conceptual object that exists outside a computer system.
Real-world entities:
Abstractions of Real-World Entities
An abstraction is a simplified representation of a real-world entity used within a computer system.
An abstraction:
Key Differences
The distinction between a real-world entity and its abstraction lies in purpose and level of detail:
Why This Distinction Matters
Understanding the difference helps programmers to:
Example Comparison
A real-world car has colour, weight, engine type, fuel level, and physical dimensions.
An abstraction of a car in a traffic simulation might only include position, speed, and direction.
Both represent the same concept, but at different levels of detail.
Summary
Real-world entities:
- Exist in the real world or in a real process
- Often have many attributes and behaviours
- May include details that are irrelevant to the problem being solved
Abstractions of Real-World Entities
An abstraction is a simplified representation of a real-world entity used within a computer system.
An abstraction:
- Includes only the attributes and behaviours needed for the solution
- Ignores unnecessary real-world details
- Is designed to support computation and problem solving
Key Differences
The distinction between a real-world entity and its abstraction lies in purpose and level of detail:
- A real-world entity contains all of its characteristics, whether useful or not.
- An abstraction contains only the features relevant to the specified problem.
- Abstractions are created intentionally to make systems easier to design, understand, and maintain.
Why This Distinction Matters
Understanding the difference helps programmers to:
- Avoid over-complicating solutions
- Design efficient data models and algorithms
- Ensure systems focus on what is required by the problem specification
Example Comparison
A real-world car has colour, weight, engine type, fuel level, and physical dimensions.
An abstraction of a car in a traffic simulation might only include position, speed, and direction.
Both represent the same concept, but at different levels of detail.
Summary
- A real-world entity exists outside the computer system.
- An abstraction is a simplified model used within a system.
- Abstractions remove irrelevant details while preserving essential features.
- Distinguishing between the two supports effective problem solving and system design.
Which statement correctly distinguishes between a real-world entity and its abstraction?
A real-world entity only includes data that is useful to a computer system
An abstraction represents only the relevant features of a real-world entity needed to solve a problem
An abstraction must include every physical detail of the real-world entity
There is no difference between a real-world entity and its abstraction
SECTION 8 | FLOW CHARTS
Algorithms can be represented in several ways, including pseudocode, structured English, and flow charts. A flow chart is a visual representation of an algorithm that shows the sequence of steps, decisions, and flow of control using standard symbols. Analysing an algorithm presented as a flow chart involves interpreting these symbols and understanding how the algorithm behaves.
Purpose of a Flow ChartA flow chart is designed to:
Common Flow Chart Symbols
When analysing a flow chart, it is important to recognise the meaning of standard symbols:
How to Analyse a Flow Chart
To analyse an algorithm presented as a flow chart, a student should:
Using Flow Charts to Detect Errors
Analysing a flow chart can help identify:
Summary
Purpose of a Flow ChartA flow chart is designed to:
- Show the logical structure of an algorithm clearly
- Make decision points and loops easy to identify
- Help programmers and users understand how an algorithm works without reading code
Common Flow Chart Symbols
When analysing a flow chart, it is important to recognise the meaning of standard symbols:
- Oval (Terminator) – Start or end of the algorithm
- Parallelogram (Input/Output) – Input from the user or output to the screen
- Rectangle (Process) – A calculation or assignment
- Diamond (Decision) – A condition that results in different paths (TRUE/FALSE)
- Arrows (Flow lines) – Show the direction of control flow
How to Analyse a Flow Chart
To analyse an algorithm presented as a flow chart, a student should:
- Trace the flow from start to end
Follow the arrows to understand the order of execution. - Identify inputs and outputs
Determine what data enters the algorithm and what results are produced. - Examine decisions carefully
For each decision, identify the condition being tested and the outcomes of each branch. - Identify loops
Look for arrows that return to earlier steps, indicating repetition. - Determine the algorithm’s purpose
Decide what problem the algorithm is solving and how it reaches its result.
Using Flow Charts to Detect Errors
Analysing a flow chart can help identify:
- Missing steps
- Incorrect or incomplete conditions
- Infinite loops
- Unreachable sections of the algorithm
Summary
- Flow charts are visual representations of algorithms.
- Analysing a flow chart involves tracing flow, interpreting symbols, and evaluating decisions.
- Flow charts help reveal logic errors and improve understanding.
- This skill supports algorithm evaluation and problem solving in IB Computer Science.
Bubble Sort Flow Chart
Tracing the Bubble Sort Flow Chart
The input list is: [4, 2, 3]
Using the flow chart, what is the first action taken after the comparison list[j] > list[j+1] evaluates to TRUE during the first pass?
Using the flow chart, what is the first action taken after the comparison list[j] > list[j+1] evaluates to TRUE during the first pass?
The two values are swapped
The value of i is increased by 1
The algorithm outputs the sorted list
The condition j < n − i − 1 is checked immediately
SECTION 8 | ALGORITHMS TO SOLVE A SPECIFIC PROBLEM
When faced with a computational problem, there is often more than one possible algorithm that could be used to produce a solution. This objective focuses on the ability to suggest an appropriate algorithm based on the requirements and constraints of a specific problem, rather than simply naming any algorithm.
Understanding the Problem FirstBefore suggesting an algorithm, the problem must be analysed carefully. This includes identifying:
Matching Algorithms to Problem Types
Different types of problems are best solved using different classes of algorithms.
Examples include:
Considering Efficiency and Simplicity
A suitable algorithm should be:
Justifying the Choice of Algorithm
In IB Computer Science, it is important not only to suggest an algorithm, but also to justify why it is suitable.
A justification might refer to:
Example
If a problem requires sorting a small list of student scores:
Summary
Understanding the Problem FirstBefore suggesting an algorithm, the problem must be analysed carefully. This includes identifying:
- The inputs and outputs
- The goal of the problem
- Any constraints, such as time limits, data size, or memory usage
- Whether the problem requires searching, sorting, counting, or decision-making
Matching Algorithms to Problem Types
Different types of problems are best solved using different classes of algorithms.
Examples include:
- Searching problems – locating an item in a collection
- Sorting problems – arranging data into a specific order
- Iteration and counting problems – processing all items in a list
- Decision-based problems – choosing actions based on conditions
Considering Efficiency and Simplicity
A suitable algorithm should be:
- Efficient enough for the expected input size
- Simple to implement and understand, where possible
- Appropriate to the context, such as educational, real-time, or resource-limited systems
Justifying the Choice of Algorithm
In IB Computer Science, it is important not only to suggest an algorithm, but also to justify why it is suitable.
A justification might refer to:
- The size of the data set
- The frequency of execution
- The need for clarity or maintainability
- The trade-off between speed and complexity
Example
If a problem requires sorting a small list of student scores:
- A simple sorting algorithm is suitable
- The clarity of the algorithm may be more important than optimal performance
- A more efficient search algorithm would be more appropriate
Summary
- Different problems require different algorithms.
- Suggesting a suitable algorithm depends on understanding the problem and its constraints.
- The most suitable algorithm is not always the most complex or fastest.
- Justification of the choice is essential.
Choosing a Suitable Algorithm
A program needs to sort a small list of exam scores that is only processed once.
Which of the following is the most suitable algorithm choice, and why?
A simple sorting algorithm, because it is easy to implement and efficient enough for small data sets
The most complex sorting algorithm available, regardless of data size
A searching algorithm, because it works faster than sorting
No algorithm is required, because the data is small
SECTION 9 | DEDUCE THE EFFICIENCY OF AN ALGORITHM
The efficiency of an algorithm describes how effectively it uses resources, most commonly time and memory. However, efficiency cannot be judged in isolation. To meet this objective, students must be able to deduce an algorithm’s efficiency in the context of its intended use, rather than relying solely on theoretical performance.
What Algorithm Efficiency Means
Algorithm efficiency usually refers to:
Considering Context When Deducing Efficiency
To deduce efficiency accurately, the following contextual factors must be considered:
Comparing Algorithms in Context
Efficiency is often deduced by comparing algorithms that solve the same problem.
For example:
Trade-offs Between Time and Simplicity
In some contexts, an algorithm that is:
Example Deduction
If an algorithm sorts 20 values once per day, its time cost is negligible, even if it is not optimal. If the same algorithm sorts millions of values every second, it becomes inefficient in that context. This demonstrates why context is essential when deducing efficiency.
Summary
What Algorithm Efficiency Means
Algorithm efficiency usually refers to:
- Time efficiency – how long an algorithm takes to complete as input size increases
- Space efficiency – how much memory an algorithm requires
Considering Context When Deducing Efficiency
To deduce efficiency accurately, the following contextual factors must be considered:
- Input size
An algorithm that is slow for large data sets may still be acceptable for small inputs. - Frequency of execution
Algorithms that run repeatedly must be more efficient than those run occasionally. - Hardware and system constraints
Available memory, processor speed, and number of users can affect suitability. - Time sensitivity
Real-time or interactive systems require faster responses than batch-processing systems.
Comparing Algorithms in Context
Efficiency is often deduced by comparing algorithms that solve the same problem.
For example:
- A simple sorting algorithm may be efficient enough for a small list sorted once.
- A more efficient sorting algorithm becomes necessary when sorting large lists repeatedly.
Trade-offs Between Time and Simplicity
In some contexts, an algorithm that is:
- Easier to understand
- Easier to maintain
- Less prone to implementation errors may be more efficient overall, even if it is not the fastest in theory.
Example Deduction
If an algorithm sorts 20 values once per day, its time cost is negligible, even if it is not optimal. If the same algorithm sorts millions of values every second, it becomes inefficient in that context. This demonstrates why context is essential when deducing efficiency.
Summary
- Algorithm efficiency refers to time and space usage.
- Efficiency must be deduced in context, not in isolation.
- Input size, frequency, and system constraints influence efficiency.
- The most theoretically efficient algorithm is not always the most appropriate.
Deducing Algorithm Efficiency
A program sorts a list of 15 values once when it is run.
Which conclusion about algorithm efficiency is most appropriate?
A simple sorting algorithm is efficient enough because the input size is small and the task is infrequent
The algorithm must be the fastest possible regardless of context
Efficiency cannot be considered without knowing the programming language
The algorithm is inefficient because it does not handle very large data sets
SECTION 10 | METHODS OF A COLLECTION
A collection stores a set of elements (for example: numbers, strings, objects). In IB Computer Science pseudocode, a collection is accessed using a standard iteration interface, meaning you do not use numeric indexes (as you would with an array). Instead, you repeatedly request the “next” item until there are no more items to access.
The IB collection access patternTo construct algorithms with collections, you are expected to use this pattern:
The IB collection access patternTo construct algorithms with collections, you are expected to use this pattern:
- resetNext() resets the internal iterator to the start of the collection.
- hasNext() returns TRUE if there is at least one item that has not yet been accessed.
- getNext() returns the next item in the iteration (and does not remove it from the collection).
PSEUDOCODE
Constructing algorithms with collection access methods
When building an algorithm, the “process ITEM” part depends on the task. Common patterns include:
When building an algorithm, the “process ITEM” part depends on the task. Common patterns include:
PSEUDOCODE: Counting items that meet a condition
PSEUDOCODE: Searching for a target value (linear search through a collection)
PSEUDOCODE: Filtering items into a new collection
PSEUDOCODE: Handling an empty collection
Collections – Access Methods (IB Pseudocode)
Which option shows the correct IB-style algorithm for accessing every item
in a collection exactly once?
COL.resetNext()
loop while COL.hasNext()
ITEM ← COL.getNext()
end loop
loop i from 0 to COL.length − 1
ITEM ← COL[i]
end loop
loop while true
ITEM ← COL.getNext()
end loop
ITEM ← COL.getNext()
if COL.hasNext() then
output ITEM
end if
Sub-procedure | A named block of code that performs a specific task and can be called from other parts of a program.
Decomposition | The process of breaking a complex problem into smaller, more manageable sub-problems.
Condition | A logical expression that evaluates to TRUE or FALSE and controls the flow of an algorithm.
Decision | A point in an algorithm where a choice is made based on the result of one or more conditions.
Exception | An unusual or unexpected situation that may disrupt normal program execution and must be anticipated in a solution.
Concurrent processing | The execution of multiple tasks during the same time period, either simultaneously or by interleaving.
Abstraction | A simplified representation of a system or situation that includes only the relevant details needed to solve a problem.
Real-world entity | An object or concept that exists outside a computer system and may have many attributes and behaviours.
Algorithm | A finite, ordered set of steps used to solve a problem or perform a task.
Flow chart | A graphical representation of an algorithm that uses standard symbols to show processes, decisions, and control flow.
Iteration | The repeated execution of a set of instructions, often implemented using loops.
Efficiency | A measure of how effectively an algorithm uses time and memory resources in a given context.
Context | The circumstances in which an algorithm is used, including input size, frequency of execution, and system constraints.
Collection | A data structure that stores a group of elements and is accessed using defined methods rather than indexes.
resetNext() | A collection method that resets the internal pointer to the start of the collection.
hasNext() | A collection method that returns TRUE if there are more items available to be accessed.
getNext() | A collection method that returns the next item in a collection without removing it.
addItem() | A collection method that adds a new element to a collection.
isEmpty() | A collection method that returns TRUE if the collection contains no elements.
Access method | A predefined operation used to retrieve or modify data in a collection.
Tracing | The process of following an algorithm step by step to determine its behaviour and output.
Suitable algorithm | An algorithm chosen because it best fits the requirements, constraints, and context of a specific problem.
Decomposition | The process of breaking a complex problem into smaller, more manageable sub-problems.
Condition | A logical expression that evaluates to TRUE or FALSE and controls the flow of an algorithm.
Decision | A point in an algorithm where a choice is made based on the result of one or more conditions.
Exception | An unusual or unexpected situation that may disrupt normal program execution and must be anticipated in a solution.
Concurrent processing | The execution of multiple tasks during the same time period, either simultaneously or by interleaving.
Abstraction | A simplified representation of a system or situation that includes only the relevant details needed to solve a problem.
Real-world entity | An object or concept that exists outside a computer system and may have many attributes and behaviours.
Algorithm | A finite, ordered set of steps used to solve a problem or perform a task.
Flow chart | A graphical representation of an algorithm that uses standard symbols to show processes, decisions, and control flow.
Iteration | The repeated execution of a set of instructions, often implemented using loops.
Efficiency | A measure of how effectively an algorithm uses time and memory resources in a given context.
Context | The circumstances in which an algorithm is used, including input size, frequency of execution, and system constraints.
Collection | A data structure that stores a group of elements and is accessed using defined methods rather than indexes.
resetNext() | A collection method that resets the internal pointer to the start of the collection.
hasNext() | A collection method that returns TRUE if there are more items available to be accessed.
getNext() | A collection method that returns the next item in a collection without removing it.
addItem() | A collection method that adds a new element to a collection.
isEmpty() | A collection method that returns TRUE if the collection contains no elements.
Access method | A predefined operation used to retrieve or modify data in a collection.
Tracing | The process of following an algorithm step by step to determine its behaviour and output.
Suitable algorithm | An algorithm chosen because it best fits the requirements, constraints, and context of a specific problem.
4.1.3 Explain the role of sub-procedures in solving a problem
Explain how sub-procedures help manage complexity when solving a large computational problem. Refer to at least two advantages in your answer.
4.1.7 Explain the relationship between the decisions and conditions of a system
Explain how conditions and decisions work together in a system to control program flow. Use an example to support your explanation.
4.1.13 Identify exceptions that need to be considered in a specified problem solution
A program calculates the average score of a class. Identify two possible exceptions that should be considered and explain why each must be handled.
4.1.15 Describe how concurrent processing can be used to solve a problem
Describe how concurrent processing could be used in a system that handles multiple users at the same time.
4.1.16 Evaluate the decision to use concurrent processing in solving a problem
Evaluate whether concurrent processing would be appropriate for a simple program that processes a small data set once. Justify your answer.
4.1.19 Construct an abstraction from a specified situation
A real-world bus booking system includes drivers, routes, tickets, passengers, and vehicles. Construct an abstraction suitable for a computer system and explain which details you would include and which you would ignore.
4.1.20 Distinguish between a real-world entity and its abstraction
Distinguish between a real-world entity and its abstraction using a real-life example. Explain why abstraction is necessary in computer systems.
4.2.4 Analyse an algorithm presented as a flow chart
Explain how you would analyse a flow chart to determine what an algorithm does. Refer to decisions, loops, and control flow in your answer.
4.2.7 Suggest suitable algorithms to solve a specific problem
A program needs to find the highest value in a list of numbers. Suggest a suitable algorithm and explain why it is appropriate for this problem.
4.2.8 Deduce the efficiency of an algorithm in the context of its use
A sorting algorithm is used to sort 20 values once per day. Deduce whether the algorithm is efficient in this context and justify your reasoning.
4.3.11 Construct algorithms using the access methods of a collection
Construct an algorithm, using IB-style pseudocode, that counts how many values in a collection are greater than 100. Use appropriate collection access methods.
Explain how sub-procedures help manage complexity when solving a large computational problem. Refer to at least two advantages in your answer.
4.1.7 Explain the relationship between the decisions and conditions of a system
Explain how conditions and decisions work together in a system to control program flow. Use an example to support your explanation.
4.1.13 Identify exceptions that need to be considered in a specified problem solution
A program calculates the average score of a class. Identify two possible exceptions that should be considered and explain why each must be handled.
4.1.15 Describe how concurrent processing can be used to solve a problem
Describe how concurrent processing could be used in a system that handles multiple users at the same time.
4.1.16 Evaluate the decision to use concurrent processing in solving a problem
Evaluate whether concurrent processing would be appropriate for a simple program that processes a small data set once. Justify your answer.
4.1.19 Construct an abstraction from a specified situation
A real-world bus booking system includes drivers, routes, tickets, passengers, and vehicles. Construct an abstraction suitable for a computer system and explain which details you would include and which you would ignore.
4.1.20 Distinguish between a real-world entity and its abstraction
Distinguish between a real-world entity and its abstraction using a real-life example. Explain why abstraction is necessary in computer systems.
4.2.4 Analyse an algorithm presented as a flow chart
Explain how you would analyse a flow chart to determine what an algorithm does. Refer to decisions, loops, and control flow in your answer.
4.2.7 Suggest suitable algorithms to solve a specific problem
A program needs to find the highest value in a list of numbers. Suggest a suitable algorithm and explain why it is appropriate for this problem.
4.2.8 Deduce the efficiency of an algorithm in the context of its use
A sorting algorithm is used to sort 20 values once per day. Deduce whether the algorithm is efficient in this context and justify your reasoning.
4.3.11 Construct algorithms using the access methods of a collection
Construct an algorithm, using IB-style pseudocode, that counts how many values in a collection are greater than 100. Use appropriate collection access methods.
Open Questions – Sample Answers
4.1.3 Explain the role of sub-procedures in solving a problem.
Sub-procedures allow a problem to be broken into smaller, manageable parts. Each sub-procedure performs a specific task, making the solution easier to understand, test, and modify. They also support code reuse and reduce repetition.
4.1.7 Explain the relationship between the decisions and conditions of a system.
Conditions evaluate to TRUE or FALSE, and decisions are made based on these results. The outcome of a condition determines which path an algorithm follows, controlling program flow.
4.1.13 Identify exceptions that need to be considered in a specified problem solution.
Exceptions include invalid input, missing data, or values outside allowed ranges. These must be identified to prevent errors and ensure the system behaves correctly in all situations.
4.1.15 Describe how concurrent processing can be used to solve a problem.
Concurrent processing allows multiple tasks to be active at the same time. This can improve efficiency and responsiveness, for example by handling multiple users or background tasks simultaneously.
4.1.16 Evaluate the decision to use concurrent processing in solving a problem.
Concurrent processing should be used when tasks are independent and performance benefits outweigh added complexity. For simple or small problems, it may be unnecessary and inefficient.
4.1.19 Construct an abstraction from a specified situation.
An abstraction is created by identifying relevant entities, attributes, and behaviours needed to solve the problem while ignoring unnecessary real-world details.
4.1.20 Distinguish between a real-world entity and its abstraction.
A real-world entity includes all characteristics, while an abstraction includes only the features relevant to the problem. Abstraction simplifies system design.
4.2.4 Analyse an algorithm presented as a flow chart.
Analysing a flow chart involves tracing control flow, identifying decisions and loops, and determining how inputs are processed to produce outputs.
4.2.7 Suggest suitable algorithms to solve a specific problem.
A suitable algorithm is chosen based on the problem type, input size, and constraints. The choice should be justified rather than arbitrary.
4.2.8 Deduce the efficiency of an algorithm in the context of its use.
Efficiency is deduced by considering input size, frequency of execution, and system constraints. An algorithm may be efficient in one context but not another.
4.3.11 Construct algorithms using the access methods of a collection.
Algorithms must use resetNext(), hasNext(), and getNext() to access each item in a collection. This ensures every element is processed exactly once.
IB Computer Science – Flashcards
COMING SOON