Writing Pseudocode

Some problems ask you to give an algorithm to solve a problem. Unless the assignment specifically tells you to implement the code and run it, pseudocode is acceptable. Pseudocode is a kind of structured English for describing algorithms. It allows the designer to focus on the logic of the algorithm without being distracted by details of language syntax. At the same time, the pseudocode needs to be complete. It describe the entire logic of the algorithm so that implementation becomes a rote mechanical task of translating line by line into source code. Note that the general rule you should follow is that you can substitute English for any O(1) operation, but not for more complex steps. Thus, the following would not be acceptable:

scan the list and count all elements greater than x

However, the following would be OK:

int counter    // keeps track of total num > 0
for each element in the list:
    if current element is greater than x
        increment counter

The idea is that you don't have to give all the nitty-gritty coding details, but you should demonstrate a clear understanding of what your algorithm does and where those nitty-gritty details would have to go.

One of the most common mistakes when writing psuedocode is thinking a particular step in an algorithm is simple or obvious and not "unpacking it" to an acceptable level of detail. So, for the purposes of our homework, when in doubt, MORE detail is probably better than less detail. Another way of thinking of this is to say you should write your answer in code, but we won't be taking off any points for syntax. In the example above, actually defining a pseudo-variable is one way of being sure the grader can tell what you are incrementing - AND that your algorithm will compute the correct result!