CSC171 - Problem Solving Techniques

This document describes four different techniques (natural-language, pseudo-code, flowchart, Nassi-Schneiderman) for developing an algorithm. Two of these techniques -- pseudo-code and flowcharts -- are widely used today. However, the Nassi-Schneiderman Notation is perhaps the easiest to convert to a procedural programming language (e.g., C++). Included within each technique description is a list of advantages and disadvantages, and two examples to illustrate the technique.

Natural-language Algorithm

This technique results in a series of numbered steps that are executed in sequence. Each step is written using your natural language (in my case, English), using the sentence structure inherent with this language.

First Example

Problem Statement: Obtain a number from the user, then display twice this number back to the user.

  1. Ask the user for a number.
  2. Get the number from the user.
  3. Multiply the number by itself.
  4. Display the result from step 3 to the user.

Advantages

Disadvantages

Second Example

Refer to the comparison of the four techniques for a second example.

Navigation: Go to top, natural-language, pseudo-code, flowchart, Nassi-Schneiderman.

Pseudo-code Algorithm

This technique results in a series of numbered steps that are executed in sequence. Each step is written using a subset of your natural language (in my case, English). This subset is based on a common set of verbs found in procedural programming languages and the common mathematical operators (+, -, *, /, =).

First Example

Problem Statement: Obtain a number from the user, then display twice this number back to the user.

  1. display prompt to user
  2. read number
  3. result = number * number
  4. display result

Advantages

Disadvantages

Second Example

Refer to the comparison of the four techniques for a second example.

Navigation: Go to top, natural-language, pseudo-code, flowchart, Nassi-Schneiderman.

Flowchart

This technique results in a series of symbols, connected by arrows that indicate the sequence in which the symbols are performed. Each symbol contains either a natural language or pseudo-code statement, and has a unique use within the flowcharting technique. These symbols and their use (purpose) are:

Flowchart Process The rectangle symbol is used to denote a process (statement) that is performed in sequence. After the statement is performed, flow continues to the next symbol in the flowchart.
Flowchart Input/Output The rhombus symbol is used to denote either input from the user or output to the user. After the input or ouptut is performed, flow continues to the next symbol in the flowchart.
Flowchart Decision The diamond symbol is used to denote a decision. After the decision is performed, flow continues in one of two paths, depending on the result of the decision. The two paths coming from the decision symbol are typically labeled as Yes/No or True/False.
Flowchart Arrow The arrow symbol is used to connect the other symbols and indicate the direction of execution (flow).
Flowchart Connector The circular symbol is used to connect different parts of a flowchart. This symbol is used when the flowchart is larger than can fit onto one page. The connector symbol is used to branch between the separate pages of the flowchart and has no signficance on the logical correctness of the flowchart.
Flowchart Terminal The oval symbol is used to start (begin) and stop (end) the flowchart. The start oval indicates where the flowchart begins execution. The stop oval ends the execution of the flowchart.

First Example

Problem Statement: Obtain a number from the user, then display twice this number back to the user.

Flowchart Example 1

Advantages

Disadvantages

Second Example

Refer to the comparison of the four techniques for a second example.

Navigation: Go to top, natural-language, pseudo-code, flowchart, Nassi-Schneiderman.

Nassi-Schneiderman chart

This technique results in a series of symbols, contained within a box. The symbols are executed starting with the first symbol at the top of the box, and continuing until the bottom of the box is reached. Each symbol contains either a natural language or pseudo-code statement, and has a unique use within the Nassi-Schneiderman Notation. These symbols and their use (purpose) are:

Nassi-Schneiderman Statement The rectangle symbol is used to denote a statement that is performed in sequence. After the statement is performed, flow continues to the next symbol in the Nassi-Schneiderman chart.
Nassi-Schneiderman Decision The decision structure contains a condition which is tested. When the condition is true, the instructions underneath the True branch are executed. When the condition is false, the instructions underneath the False branch are executed. After the appropriate instructions are performed, flow continues with the next symbol contained within the Nassi-Schneiderman chart.
Nassi-Schneiderman Loop The loop structure contains a loop statement along with instructions to execure as long as the loop statement is true. After the instructions are performed (zero or more times), flow continues with the next symbol contained within the Nassi-Schneiderman chart.

First Example

Problem Statement: Obtain a number from the user, then display twice this number back to the user.

Nass-Schneiderman Example 1

Advantages

Disadvantages

Second Example

Refer to the comparison of the four techniques for a second example.

Navigation: Go to top, natural-language, pseudo-code, flowchart, Nassi-Schneiderman.

Comparison

This section allows you to compare the four techniques by showing a similar solution for the same problem statement, written in each of the techniques.

Problem Statement: Obtain numbers from the user, then display the average of all numbers entered once the user has completed the entry of numbers.

Natural-language Algorithm Pseudo-code Algorithm
  1. Initialize sum of all numbers entered to zero.
  2. Initialize count of numbers entered to zero.
  3. Ask the user for a number.
  4. Get a number from the user.
  5. Repeat steps 5a...5d until there are no more numbers entered.
    1. Add number entered to sum of all numbers entered.
    2. Add one to the count of numbers entered.
    3. Ask the user for a number.
    4. Get a number from the user.
  6. If the count of numbers entered is zero, do step 6a:
    1. Display a message indicating unable to calculate average since no numbers were entered.
    Otherwise do steps 6b...6c:
    1. Divide the sum of all numbers entered by the count of numbers entered.
    2. Display the result from step 6b to the user.
  1. sum = 0
  2. count = 0
  3. display prompt to user
  4. read number
  5. while more numbers do
    1. sum = sum + number
    2. count = count + 1
    3. display prompt to user
    4. read number
  6. if count = 0 then
    1. display message "unable to calculate average since no numbers were entered"
    else
    1. average = sum / count
    2. display average

Flowchart

Nassi-Schneiderman chart