What is a problem?

A problem is defined as the “difference between the current state of things and a desired future state in an information processing system”

Example


CURRENT STATE:

A score taker for a football game could be using a paper based information processing system consisting of

Hardware:

  • A notebook
  • Pencil

Data management:

  • Ruled lines forming a table in the notebook,
  • Columns for scores, fouls, Events etc
  • Calculations such as cumulative minutes or penalties in the game (these are calculated mentally by the score taker and recorded during the progression of the game.)

Inputs :

  • Goals scored,
  • Scorer’s name
  • Team scoring


  • Fouls
  •  Attacking player name , victim name
  • Minute of foul

Outputs (to officials and score board operator):

  • Scores
  • Fouls
  • Minutes

Desired future state:

Input:

  • Scores along with player’s Number entered manually
  • Fouls with attacker and victim names number manually via keyboard

Processing:

  • Store player’s names from looking up numbers
  • Automatically timestamp goals and fouls

Output:

  • Statistics directly to website and scoreboard.

© 2019  Vedesh Kungebeharry. All rights reserved.

The Importance of algorithms

In our discussion, we consider well defined precise algorithms (in flowcharts or pseudocode) as compared with narrative algorithms.

Some of the reasons why algorithms are beneficial or important to the problem solving process are:

  1. Algorithms serve as a blueprint for other programmers to follow

  2. When problems are complex, an algorithm’s precise structure allows for an accurate development of a solution in parts.  This documentation (the algorithm itself) is useful since it is difficult for  the problem solver to remember many sub-processes , procedures and inputs/outputs to the problem.

  3. Because algorithms are intended for a computer system and programming language, it allows us to design for that particular programming language’s structure and for efficiency ,given    the limitations of system resources.

    For example, an algorithm which processes DNA sequence information for matching DNA strands together (see Longest common sub sequence) can be developed strictly for solving the problem without considering system resources.   In this case the algorithm still resembles programming language. 

    Usually in this type of general solution, array sizes are allowed to be very large or of infinite size. If memory becomes a constraint, we can now modify the algorithm to use say, array sizes at a maximum of  1000 to allow for the intended program to run within the limitation of our system resources.

  4. Algorithms are easily testable when using dry runs and trace tables.

© 2019  Vedesh Kungebeharry. All rights reserved.

Decimal to binary

Task: Create an algorithm which accepts a decimal integer and outputs it’s binary equivalent.

This algorithm was designed and implemented in Flowgorithm:

See the video below for an explanation of how the algorithm works:

Decimal to binary algorithm explained

The code in C is shown below:



Copy and paste from here:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>//library needed for string operations

int main()
{
    //declare and identify integers
    int number, remainder;

    //declare, identify and initialize all strings
    char  result[20]="";
    char  remainderString[20]="";


    //initialize all other variables
    number=-1;
    remainder=-1;

    //get input
    printf("Enter a number in decimal\n");
    scanf("%d", &number);
    printf("\n");

    while (number!=0)
    {
        remainder=number%2;

            /* #Implementation_Result

                Here we implement the following:

                    result=remainder + result
            */

            //first convert the remainder to a string,
            //and store the converted data in "remainderString"
            itoa(remainder,remainderString,10);

            //add "remainderString" to "result" in that order.
            //the result of the concatenation is stored in "remainderString"
            strcat(remainderString,result);

            //now copy our data so far back to "result"
            strcpy(result,remainderString);
            /*End #Implementation_Result*/


        number=number/2;

    }

    printf("The binary Result is %s \n",result);
    return 0;
}

© 2019  Vedesh Kungebeharry. All rights reserved. 

Spreadsheet Functions

Functions

A function is a predefined formula provided by a spreadsheet application.

Functions are written in the following format:

                =FunctionName(parameter1, parameter2, …, parameterN) 

e.g

=sum(e3, d4, r5),

=max(a5,a27,b44)

=SUM(D3,D4,D5,F3:F4)

a function with a single parameter is shown below:

                =FunctionName(parameter)

e.g.

=SUM(F3:F4)  (note this is 1 parameter, a range)

=ABS(-44)

Note that a function’s  actions can be accomplished with a formula:

e.g =SUM(D3:F3) becomes =D3+E3+F3

Absolute addressing – prevents a cell’s row number or column letter from being updated when a formula is copied to another cell.

e.g          $C4        – prevents the column letter from being updated

                C$4        – prevents the Row number from being updated

                $C$4      – prevents both column letter and row number from being updated.

Secret tip!!!!!!!!  – use F4 to set a cell’s address to absolute addressing.

Class Demo

Download the excel file here:

https://drive.google.com/file/d/1NNSBoalQj278kbyctaYaaw5M1OII8tto/view?usp=sharing

StudentRoll NoMathFrenchSpanishTotalsAverageBonus ScorePass/Fail?
Jim1105520710Work harder
Mary2752051003350Good Job
Tobias Reiper3125 17913Work harder
Mario4135523812Work harder
Bonus50%
Student Number4
  
Max Average33
Min Average7
  
# Marks < 303
Number of spanish marks entered3
Number of spanish marks Missing1

Sheet with formulas

StudentRoll NoMathFrenchSpanishTotalsAverageBonus ScorePass/Fail?
Jim11055=SUM(C3:E3)=AVERAGE(C3:E3)=(1+$B$10)*G3=IF(G3<30, “Work harder”, “Good Job”)
Mary275205=SUM(C4:E4)=AVERAGE(C4:E4)=(1+$B$10)*G4=IF(G4<30, “Work harder”, “Good Job”)
Tobias Reiper3125 =SUM(C5:E5)=AVERAGE(C5:E5)=(1+$B$10)*G5=IF(G5<30, “Work harder”, “Good Job”)
Mario41355=SUM(C6:E6)=AVERAGE(C6:E6)=(1+$B$10)*G6=IF(G6<30, “Work harder”, “Good Job”)
Bonus0.5
Student Number=COUNT(B3:B6)
  
Max Average=MAX(G3:G6)
Min Average=MIN(G3:G6)
  
# Marks < 30=COUNTIF(G3:G6, “<30”)
Number of spanish marks entered=COUNTA(E3:E6)
Number of spanish marks Missing=COUNTBLANK(E3:E6)

Homework:

Give examples of the following functions:

Sum, average, max, min , count, counta, countif , date , if 

© 2019  Vedesh Kungebeharry. All rights reserved.