19

Technically, Is there a difference between these two words or can we use them interchangeably? Both of them more or less describe the logical sequence of steps that follow in solving a problem. ain't it? SO why do we actually use two such words if they are meant to talk of the same?

Or, In case if they aren't synonymous words, What is it that differentiates them? In what contexts are we supposed to use the word pseudo code vs the word algorithm?

4
  • 4
    An algorithm is quicksort. Pseudocode is "Make me a sandwich, then once it's made, bring it to me."
    – Neil
    May 20, 2011 at 9:58
  • See this answer to another question. There I described a relation between an algorithm and pseudocode. May 21, 2011 at 13:15
  • 4
    The short version: 'Pseudo code is one of the ways to represent an algorithm' May 21, 2011 at 13:16
  • 3
    @Neil or even SUDO make me a sandwich xkcd.com/149
    – StuperUser
    Mar 27, 2012 at 19:38

13 Answers 13

40

Wikipedia's definition of an Algorithm:

In mathematics and computer science, an algorithm is an effective method expressed as a finite list of well-defined instructions for calculating a function. Algorithms are used for calculation, data processing, and automated reasoning.

Algorithms can be described in various ways, from pure mathematical formulas to complex graphs, more times than not, without pseudocode.

Pseudocode describes how you would implement an algorithm without getting into syntactical details.

So no, they're not really synonymous.

9

An algorithm is an idea about how to write the code. Pseudo code is the written text you need to communicate that idea.

1
  • Nice! Short and straight. But I'd say "a written text" than "the written text". What do you think?
    – Luciano
    Feb 20, 2019 at 19:15
8

"Pseudocode" is to "algorithm" as "English" is to "knock-knock joke".

An algorithm is a formal structure for something that might be expressed in pseudocode, or in actual code.

A knock-knock joke is a formal structure for something that might be expressed in English, or in some other language. (Do other cultures do knock-knock jokes? I don't even know.)

1
  • I don't think so. At least there isn't anything similar in Portuguese about that knock-knock game. So, I'd say that there isn't also in other Romance languages like Spanish and Italian. I won't include French because it had a long affair with English in British islands centuries ago, and I don't know other Romance languages like Romanian and others.
    – Luciano
    Feb 20, 2019 at 19:27
4

There is only one quicksort algorithm, which is the kind of thing that would exist in Plato's world of pure ideas. There could be any number of different pseudo-code descriptions of it. I think I would define pseudo-code as text that looks roughly like computer code, and could be translated by an experienced programmer into actual computer code without having to make any creative leaps.

So no, I wouldn't use the terms interchangeably.

3

An algorithm is a systematic logical approach used to solve problems in a computer while Pseudocode is the statement in plain English which may be translated later into a programming language (program).

3

An algorithm is the semantic while the pseudo-code is just a syntax of the communication about solving a problem. This means that the algorithm is an actual way a problem is solved while the pseudo-code is just a way of expressing that way.

An algorithm has the same meaning (semantic) if you express it in any way (syntax) be it C programming language, pseudo-code or English language.

2

Pseudo code as i understand is an intermediary between an algorithm and implemented program. You can base your pseudo code on an algorithm. This contains transferable steps to implement.

Algorithm on the other hand implies the overall logic. in sequential steps to solve a problem. if it is represented diagrammatically it is called a flow chart.

Some might refer this to this as pseudo code being a common term in business software development where the client-side Business object developers write pseudo code based on requirements. This is given to a programmer/developer to implement.

Algorithm you would find more common in programing terminology like systems programming,searching,sorting, basically any where there is a complex logic to be implemented.

2

Even though pseudo-code seems closer to code than an algorithm, in practice, pseudo code is less formal and it is a more high level description. For instance you can describe a chess playing computer as a pseudo code like this:

  • place initial pieces in their locations
  • show board
  • while game is not over
    • make move and display board
    • prompt user for move
    • make users move

Yes, this is pseudocode, it is helpful as a good starting point but glosses over lots of details. It does not account for implementation difficulties and variations, but the biggest benefit is that it allows you to conceptualize the whole situation without having to solve all the details.

You can revise it, adding one more level like so:

  • place initial pieces in their locations
  • show board
  • while board is not checkmate or draw
    • make a list of white's legal moves
    • choose the best according to some criteria
    • make that move and compute resulting board
    • see if checkmate or draw has occurred
    • display board
    • make a list of black's legal moves
    • prompt user for legal move for input
    • make that move and compute resulting board
    • see if checkmate or draw has occurred
    • display board

Now you can write pseudocode for each of the major steps like "make a list of black's legal moves", like so:

  • for each black piece
    • for piece type in a given location
      • make a list of next possible locations

Now you can see the power of pseudocode is really in its ability to show the whole situation in one go and then allowing you to address details piece by piece. The weakness is that any step is not a definite simple step.

An algorithm typically picks up one of these steps and details out various data structures in a symbolic language so that you can efficiently meet the goal of the step.

For example, get_legal_moves(board, color) is worthy of an algorithm design:

get_legal_moves(board, color):
    for i,j in board_dimensions
        if piece_at i,j is of color
            if piece type is KNIGHT
                add the following to the next moves list:
                    location i+1 j+2, i-1 j+2... etc
            if piece type is rook
                add locations:....

You can see that the algorithm has to be very precise to be useful.

It ensures several things: that the goals will be met without errors, first and foremost. The steps are very detailed and executable in a mechanized way and that the steps are small enough that you can reorder them to increase the efficiency (speed) with which you finish the task.

1
  • This appears to be top-down algorithm decomposition expressed in pseudocode at every step. Jan 16, 2016 at 22:01
0

From my experience Pseudo-code has always been written by functional personell (people who own the process) as a way to express the business rules that apply to a process, module or sub-system.

An Algorithm is a difinitive set of logic statements for solving as specific a task as possible.

0

Algorithm is something which is represented in mathematical terms. It includes, analysis, basic implementation (even that's expressed in pseudo code), complexity considerations(best, average and worstcase analysis etc.).

Pseudo code is a human readable representation of a program. Even that can be used to describe an algorithm.

0

Algorithms by definition cover a process, pseudo code can be, and frequently is, of a much smaller area.

If we are discussing quicksort, and I say the key is that it has two recursive calls, like so

qs partition1 
qs partition2

The above is two lines of pseudo code. I haven’t defined the full algorithm, my pseudo code is woefully inadequate even on the line level as it doesn’t include the parameters, nevertheless, I have conveyed useful information.

Pseudo code, because it is part of a larger conversation doesn’t need to make sense outside of that conversation. I have written pseudo code for part of an expression.

Here’s some c# code:

var sqlStr = GetSqlString() + GetWhereClause();

In a chat, I might tell someone that they need to modify that by changing it to GetSql + add additional join tables + WhereClause

Using pseudo code to convey the basic idea of what needs to change, without worrying about the exact syntax or details.

With an algorithm on the other hand, if you leave out part of the process, then the algorithm is wrong, whether it is expressed in an actual language or pseudo code. If my description of the quicksort algorithm only includes a recursive call for the lower partition, it won’t work.

0

A physical "combination lock" is an implementation of "an algorithm," although said implementation uses "slotted metal disks on a spindle," not software code.

-2

Pseudo means single & code may be an instruction..here Pseudo-code means an statement which is used to understand the computer programing language easily...it helps in Analise the programing code.. . . where as algorithm is an finite logical step of instructions to solve a problem.

1
  • 1
    this doesn't seem to offer anything substantial over points made and explained in prior 10 answers
    – gnat
    Jun 30, 2017 at 11:42

Not the answer you're looking for? Browse other questions tagged or ask your own question.