top of page

COMPUTATIONAL THINKING | THINKING AHEAD

SECTION 1 | IDENTIFY THE INPUTS AND OUTPUTS REQUIRED IN A SOLUTION​

 

In the realm of computing and problem-solving, understanding the flow of information is crucial. The process typically involves taking specific inputs, processing them, and producing outputs. This guide will help you recognize and distinguish between inputs and outputs in various solutions.

 

Inputs refer to the data or information provided to a system, process, or program to achieve a specific result. They are the starting point for any computational task and can come from various sources: user input, sensors, databases, etc.

Some examples include; Typing text into a word processor, temperature reading from a thermostat, or product details entered into an inventory system.

 

Outputs are the results or information produced by a system, process, or program after processing the inputs. They are the end product of the computational task and can be presented in various forms: on-screen display, printed document, control signals, etc. Some examples include: A printed report, a temperature setting adjustment, or an alert notification.

 

Steps to Identify Inputs and Outputs

  • Determine the Goal: Before recognizing inputs and outputs, understand the main objective of the process or solution.

  • List All Information Sources: Identify where the information is coming from. These sources typically provide the inputs.

  • Determine Results: What does the system or process produce once it has processed the information? These are your outputs.

  • Check for Intermediates: Sometimes, systems have intermediate inputs or outputs that serve as both. These can often be steps in a multi-stage process.

 

Example scenario: Online Shopping System

  • Objective: Allow users to select products, pay, and have them delivered.

  • Inputs: User account information, product selection, payment details, delivery address.

  • Outputs: Confirmation receipt, order status updates, delivery tracking information.

 

SECTION 2 | IDENTIFY PRE-PLANNING IN A SUGGESTED PROBLEM AND SOLUTION

 

Effective problem-solving in the computing domain often involves anticipation. By pre-planning certain aspects of a solution, systems can respond faster, be more efficient, and provide a smoother user experience. Recognizing such pre-planning elements with a focus on concepts like caching, pre-fetching, and building libraries.

 

Pre-planning involves foreseeing future needs or challenges in a problem scenario and making advanced preparations or decisions to address those anticipated issues efficiently.

  • Enables a system to respond promptly and effectively.

  • Can often be recognized by resources or processes set up "in advance" or "just before they're needed".

  • Improves system efficiency and user satisfaction


 

CACHING AND PRE-FETCHING

Caching is the process of storing frequently accessed data in a 'cache' so that future requests for the same data can be served faster. Pre-fetching proactively loading data or content before it is explicitly requested, anticipating future needs.

  • Caching reduces redundant operations and decreases data retrieval times.

  • Pre-fetching ensures that data is readily available when a user or system requires it, offering a seamless experience.

 

For example a web browser might cache frequently visited web pages. Similarly, a streaming service might pre-fetch the next episode of a series while you're watching the current one, ensuring an uninterrupted viewing experience.

 

BUILDING LIBRARIES AND PRE-FORMED ELEMENTS

Creating and storing collections of pre-defined code, functions, or design elements that can be quickly integrated into future projects or solutions help to save development time by avoiding "reinventing the wheel" and provides consistency and can enhance system reliability and performance.

 

For example a graphic designer might have a library of frequently used design elements, or a software developer might use a math library for complex calculations without writing each function from scratch. This helps save a significant amount of time and reduce the risk of errors.

 

​Recognising pre-planning in problem-solving provides insights into the foresight and efficiency aspects of a solution. Such techniques not only make systems more responsive but also ensure they're prepared for future challenges.

 

SECTION 3 | EXPLAIN THE NEED FOR PRE-CONDITIONS WHEN EXECUTING AN ALGORITHM

 

Pre-conditions are the set of conditions or criteria that must be true or satisfied before an algorithm is executed. A simple example of this is a WHILE loop. A WHILE loop will only run if a pre-condition is met, take the code below as an example:

 

correct_password = ("****")

enter_password = FALSE

WHILE enter_password == FALSE

    password = INPUT("Please enter your password")

    IF password == correct_password THEN

        enter_password = TRUE

    ELSE

        PRINT ("Incorrect Password")

    END IF

END WHILE

 

In the above example the pre-condition to start the WHILE loop is that enter_password must be FALSE. Remember one of the differences between a FOR loop and a WHILE loop is that a FOR loop will always iterate at least ones where-as a WHILE loop may never iterate if the precondition is not met.

 

Using Pre-conditions in an algorithm helps to:

  • Serve as a form of contract between the algorithm and its user or calling function.

  • Ensure that the algorithm receives valid and appropriate input.

  • Help prevent unintended behavior, errors, or failures during execution

  • Improved Data Integrity by ensuring that the data or inputs provided to the algorithm are of the correct type, format, and within acceptable ranges.

  • Improve efficiency by preventing the algorithm from wasting computational resources on processing invalid data.

  • Reduces the risk of unexpected errors or issues, which might arise due to inappropriate data or circumstances.

  • Ensures that the algorithm can reliably produce expected results under given conditions

 

EXAMPLE OF PRE-CONDITIONS

  • For a Sorting Algorithm: The input must be a list of numbers (or other sortable elements).

  • For a Database Lookup: The database must be initialized and accessible; the query should be in a specific format.

  • For a Login Algorithm: The input credentials must be non-empty strings.

 

SECTION 4 | OUTLINE THE PRE- AND POST-CONDITIONS TO A SPECIFIED PROBLEM

 

When designing algorithms and functions, it is important to establish the environment or state both before (pre-conditions) and after (post-conditions) the operation. This provides clarity on the algorithm's requirements and expected outcomes.

  • Pre-conditions: These are the conditions or requirements that must be satisfied before the execution of an algorithm or function.

  • Post-conditions: These describe the state of the system or the expected outcomes after the algorithm or function has successfully executed.

 

EXAMPLE ALGORITHM | CALCULATE THE SQUARE ROOT OF A NUMBER

 

Pre-conditions

  • The input must not be a negative number (since the square root of a negative number isn't real in standard arithmetic).

  • The input number should not exceed a specified range(if applicable).

  • The input must be a number.

 

Post-conditions

  • The output will be a number equal to the square root of the input or an error message indicating an invalid input.

  • The output number, when squared, should be close to the input (considering rounding errors)

 

When learning to code we first look at ensuring inputs and pre-conditions are as expected and often neglect to set algorithms to check outputs are as expected. By clearly stating the initial requirements and expected outcomes, developers can create more reliable and effective solutions. 

 

SECTION 5 | IDENTIFY EXCEPTIONS THAT NEED TO BE CONSIDERED IN A SPECIFIED PROBLEM SOLUTION

 

Exceptions are unanticipated events or conditions that deviate from the normal flow of an algorithm or process, potentially leading to errors or unintended outcomes. When designing solutions or algorithms for problems, it's crucial to anticipate and handle exceptions – unusual or unforeseen circumstances that might disrupt standard operations to help the robustness of your program to provide more reliable systems and enhance user experience.

 

Using the calculation of end-of-year bonuses as an illustrative example.

 

Case Study Scenario: End-of-Year Bonus Calculation

Typically, companies might have a straightforward formula to calculate bonuses, such as a fixed percentage of the annual salary for all employees who've worked for the entire year.

 

STEP 1 | Identify potential exceptions

  • Partial Year Employment: Employees who have not worked the entire year, perhaps due to joining mid-year or leaving before the year ends.

  • Leave Without Pay: Employees who took extended leaves without pay might not qualify for a full bonus.

  • Different Contractual Agreements: Some employees might have different bonus stipulations in their contracts.

  • Performance-based Variations: Bonuses might vary based on individual or departmental performance metrics.

 

STEP 2 | Identify Pre-conditions for the Problem

  • For the bonus calculation to be executed correctly, several pre-conditions must be met:

  • Employee Data Availability: Accurate records of when employees joined, if they took any extended leaves, and their salary details.

  • Contract Details: Information on any special bonus arrangements or variations from the standard agreement.

  • Performance Metrics (if applicable): Data on employee or department performance to adjust bonuses accordingly.

 

STEP 3 | Handling Identified Exceptions:

 

  • Partial Year Employment: Prorate the bonus based on the fraction of the year the employee worked.

  • Leave Without Pay: Adjust the bonus to account for the period of unpaid leave.

  • Different Contractual Agreements: Override standard calculations with the stipulated bonus percentages of amounts from individual contracts.

  • Performance-based Variations: Incorporate performance metrics into the calculation, possibly using a weighted formula.

Identifying and handling exceptions is a cornerstone of robust problem-solving in computational scenarios. By foreseeing potential disruptions and ensuring that pre-conditions are met, developers can design solutions that are both effective and reliable.

Teacher don't teach me nonsense  

                                       

                     - Fela Kuti

bottom of page