Logout

## Instructions and Advice - Algorithms & Pseudocode

Intro

Recall that this is one of the four Code Planning Documents you can do, out of:

• Flowcharts
• Algorithms
• Pseudocode
• Chronological Development Plan
Of the four, arguably, these two are the most involved, but also, the most useful. They are much easier to do after some initial brainstorming, hen scratching on the white-board, and flowchart work.

- Algorithm: a step-by-step solution to a particular problem (written out in English or another spoken language).

- Pseudocode: pseudocode is "false" code, i.e. not actual programming code that can compile, but a simpler version typed anyway you want, but resembling the language and structure of a particular programming language.

Algorithms/Pseudocode Approach

Generally, the order in which you use all of these code development tools is flowcharts --> algorithms --> pseudocode. Flowcharts can cover just about all aspects of planning your program, but algorithms and pseudocode are more often targeted toward the more "schmantzy", "ingenious" cool parts of your program that do some sort of neat or original calculations.

Algorithms are written out, and pseudocode developed, like flowcharts, to help you think through how such calculations etc. should work. But compared to flowcharts, they help you think in much more detail. And in the case of pseudocode, this thinking takes into consideration the actual programming tools and techniques at your disposal.

* Keep in mind that some students may have trouble "seeing ahead" enough to be able to do a really good job of this. In which case, keeping their code planning to flowcharts and a chronological development plan, which includes a limited amount only of algorithms/pseudocode, may be enough.

### Algorithms

Algorithms are going to look like step-by-step English etc. instructions. Like a recipe. "Do this, then do that, then do this other thing; step 1, step 2, step 3, step 4..."

Example 1.

• ....
• loop through the array of clients
• find all the teachers
• add them to another list, which operates as a queue
• sort that list by priority (based on doctor referral)
• save that list to another class
• ....

Example 2.

Flight scheduler GUI program's display

(And here, linked, is the Netbeans project upon which the above algorithm, and below pseudocode are from.)

### Pseudocode

Pseudocode is "pseudo", i.e. false, code. So it's not real code, but it's pretty close. Compared to English-like algorithms, with pseudocode, the style moves a lot more toward Java (or the programming language of choice).

Note that it's still kind of a mis-mash of English and code, and it's still, one way or the other a way to think through things. But you are now keeping in mind the tools and techniques available to you , along with the opportunities and limitations that come from your choice of programming language.

Writing pseudocode allows you to anticipate and play around with the kind of coding that may work to solve your problem, but at a "lower stakes" level than actual programming. With pseudocode, you don't have to worry about perfect syntax, or red squiggles - you can focus more on the general putting together of the code.

Example 1 (the examples are the same situations as above, where they were written out in algorithmic form)

• ....
• for(int i = 0; i < clients.size( ); i++){
• if(client.getAge( ) > 18)
• aSortClass.sortByPriority(teacherQueue)
• FileWriter fw = new FileWriter(teachers.txt)
• for(int i = 0; i < teacherQueue.size( ); i++){
• fw.write(teacherQueue.getNext( )
• ....

Final Points

There's only so much you can see ahead in the future, so do your best to come up with what you can. But just like with flowcharts, the secret is to just start, and see where your thoughts take you.

Also note, that would be a good idea to partner up to share/discuss this with someone else. Talking things through always seems to help you get things organized in your head a bit better.

One More Example

This example is going back to a more preliminary "back of an envelope" approach again. But it also demonstrates a "beta - alpha" process.

Remember, the whole point of all of this code planning, whether very formal, or very scribbly, is to sort things out in your head any way you can before you start to code.