SBA-How to Approach a Dry run using test data and trace tables to uncover errors in your algorithm

( this content is AKA: SBA Guidance – Trace Tables And Dry Runs )

Choosing test data

Generally , we use the following as a guide when generating data for use with trace tables:

  1. The user quits the program without entering data.
  2. The user enters normal data (ensure that all branches of code are tested)
    1. Data that allows to enter loops
    2. Different sets of data that allows for conditions in selection statements (if..then..) to be tested when true and false
  3. Data that test “Divide by zero errors if possible”
  4. Optional: Data that tests for real numbers.  If numbers are to be processed, supply real test data (e.g 1.0 , 99.01) to uncover data type errors

Task/Exercise

Download the files here: https://drive.google.com/drive/folders/1kKuCWbUajYe52ME_obPRSjxbyqxHEprg?usp=sharing

Use the file “Problem Solving and Programming – Demo – 04 Filled Tables” to complete

  1. Test 3 – (Hint: you may Fill in the table using the provided flowgorithm file as a guide, or you can perform a dry run by hand using the algorithm already documented above the trace tables in the document)
  2. Test 4 – (Hint: after you have created a script of data and perform this test using the trace table, it is likely that you would uncover a divide by 0 error. In this case you would have to modify the algorithm, and perform the test again using a trace table.

See the class video which offers a detailed explanation on the approach:

(Friday 17th May 2021)

Tuesday 7th October 2025

© 2021  Vedesh Kungebeharry. All rights reserved. 

Problem Solving Discussion

Task: How can you drop an egg from a height of 3 meters without breaking it?

Steps taken in solving the problem

Information gathering

What are the constraints?

The ground must be hard, no adding of sand

No use of Drones

No use of Parachutes.

Definition of problem : Drop an uncooked egg from 3m high onto hard ground without breaking it.

Brainstorming

The process of generating ideas to solve the problem

Identification of resources

Determine what is needed for EACH solution. e.g rubber bands, string , balloons etc.

Evaluation of pros and cons of multiple solutions

Compare each solution across similar criteria:

e.g. availability of resources, cost, how well each solution is expected to solve the problem, the complexity of the solution.

Determining most feasible solution.

After we have thoroughly evaluated the solutions, we choose one of them and implement it.

© 2021  Vedesh Kungebeharry. All rights reserved. 

Relational Operators – A practical Exercise

Pre-Requisite : Read (Campbell, Information Technology for CSEC – 3rd Edition, 2020, pp. 272-273)

Observe the attached flowgorithm file, or the pseudocode below:


Start 
    // Here we set up 2 numbers to experiment with our relational operators....
    FirstNum = 7
    SecondNum = 5
    
    // Comparison: First number is greater than second number
    greaterThan = FirstNum > SecondNum
    output "' " + FirstNum + " is greater than " + SecondNum + " ' evaluates to " + greaterThan
    
    // Comparison: First number is greater or equal to second number
    greaterThanOrEqualTo = FirstNum >= SecondNum
    output "' " + FirstNum + " is greater than or equal to " + SecondNum + " ' evaluates to " + greaterThanOrEqualTo
    
    // Comparison: First number is equal to second number
    equalTo = FirstNum = SecondNum
    output "' " + FirstNum + " is equal to " + SecondNum + " ' evaluates to " + equalTo
    
    // Comparison: First number is not equal to second number
    notEqualTo = FirstNum ≠ SecondNum
    output "' " + FirstNum + " is not equal to " + SecondNum + " ' evaluates to " + notEqualTo
    
    // Comparison: First number is less than second number
    lessThan = FirstNum < SecondNum
    output "' " + FirstNum + " is less than " + SecondNum + " ' evaluates to " + lessThan
    
    // Comparison: First number is less than or equal to second number
    lessThanOrEqualTo = FirstNum <= SecondNum
    output "' " + FirstNum + " is less than or equal to " + SecondNum + " ' evaluates to " + lessThanOrEqualTo
Stop

The flowgorithm file or the pseudocode above should output:

‘ 7 is greater than 5 ‘ evaluates to true
‘ 7 is greater than or equal to 5 ‘ evaluates to true
‘ 7 is equal to 5 ‘ evaluates to false
‘ 7 is not equal to 5 ‘ evaluates to true
‘ 7 is less than 5 ‘ evaluates to false
‘ 7 is less than or equal to 5 ‘ evaluates to false

Task:

In your notebook or personal notes, determine the output of the algorithm when FirstNum and SecondNum Is updated as follows:

  1. FirstNum=6 , SecondNum=7
  2. FirstNum=7 , SecondNum=7
  3. FirstNum=7 , SecondNum=6
  4. FirstNum= -6 , SecondNum= -7

© 2021  Vedesh Kungebeharry. All rights reserved. 

Scheduling Algorithms

First Come First Serve or Non-pre-emptive Scheduling.

The CPU can run processes in the process queue (in  ready state) one at a time for a  “burst” at a time in a first come first serve fashion.  This is known as non pre-emptive scheduling, since no determination is made into the most efficient order to run processes on the CPU.

It should be noted that the amount of time that a process might stay on the CPU could be very long when compared to others in the queue. This is because a “burst” might  a sequence of CPU and IO instructions the process executes without interruption form the CPU scheduling algorithm .  The process is only moved from execution on the CPU when a I/O operation occurs that causes the process to be put in wait mode, or, it terminates.

Having other processes wait exceedingly long is not desirable, and todays modern operating systems do not implement FCFS. 

FCFS scheduling does have the advantage of being easier to program and implement; but this advantage does not outweigh the performance of an efficient process scheduler.

FCFS scheduling is also prone to race conditions, where 2 processes need to read from the same section in memory and end up producing inconsistent data.  See here for a good explanation:

https://stackoverflow.com/questions/3130079/difference-between-racearound-condition-and-deadlock

Shortest Job First or Pre-Emptive scheduling

This scheduling algorithm examines each process to determine the length of time that is needed for on the CPU.  The algorithm then places processes with the shortest estimated time to be executed as priority.

Round Robin Scheduling

This is very similar to FCFS scheduling , only this time each process is given a fixed maximum time to be executed on the CPU.  If the process exceeds the time, it is put in wait mode and added to the end of the queue.

© 2021  Vedesh Kungebeharry. All rights reserved.