Skip to content

Main Algorithm and Refinements

The main algorithm is also known as the top-level design.

The example on the previous page is the main algorithm, it shows the main steps of the program, but not the detail of how each step works.

We could list the same algorithm as numbered lines of pseudocode. This is the main algorithm.

1.0 Read song data from text file

2.0 Count number of downloads for each song

3.0 Find song with most downloads

4.0 Display song info

Important

Write your main algorithm first when implementing, then you can fill in the details for each step.

These details are known as refinements.

Step 3 from the algorithm above tells us to find the song with the most downloads.

We can assume that, by this point, we have an array of songs, telling us how many downloads each song has.

We can refine step 3 to write detailed pseudocode that says how to do this:

3.1 Set most popular to first song in the list
3.2 Loop for the number of songs
3.3        If popularity of song is > popularity of most popular
3.4              Set most popular to current song
3.5        End if
3.6 End loop
Don’t worry too much about how the algorithm above works, the important thing is that it refines step 3 by adding the detail of how this module will work.

Example Question

Q1 - Read the main algorithm below

Main Algorithm:

1.0 Load password data from file
2.0 Ask user to enter a valid password
3.0 Check if user password is in the file data
4.0 Output whether password has been changed
Step 2 could be refined further.

Refine step 2 below.

2.1 Ask user to enter password
2.2 While password is not valid 
2.3        Display error message
2.4        Ask user to enter password again
2.5 End while loop