954,506 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Pseudocode

Flowcharting
Pseudocode can almost be classified as half-code, half-text. Even as its name implies, it is semi-code. It is used by a programmer to outline the algorithms he or she has written, before they are actually translated into code. It is almost a high-level abstraction of code. For the most part, an algorithm to perform the same task in multiple programming languages is the same. The following is an example of pseudocode to ask the computer to input two numbers, and then print out their sum:
[indent]input A
input B
C = A + B
print C

[/indent]Using Functions
Pseudocode can also be used to interact between functions. By writing our your algorithm in such a way, not only can you easily convert it to any language you choose. It is also much easier to debug (fix) logic errors. Logic errors are those where the entire process being used from point A to point B is not rational or it doesn't work. Using pseudocode to pass variables in and out of functions can enormously help you, especially by using it as a reference guide when writing the code, itself.

cscgal
The Queen of DaniWeb
Administrator
19,424 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 230
 

thats not pseudocode, looks more like BASIC to me!

Phaelax
Practically a Posting Shark
858 posts since Mar 2004
Reputation Points: 92
Solved Threads: 51
 

Yea that pseudocode is just like BASIC statements.
I would suggest:

start
get the value of a
get the value of b
assign c to the value of (a+b)
print c
end

a more compact way to follow is:

get a
get b
c <-- a+b
(most programmers use <--- as the assignment operator, they keep = sign for conditional statements)
print c
end

I think every programmer has the liberty to choose his or her own style of pseudo coding--as long as it is clear to him/her. Pseudocode has no strict rules and can or should be modified according to his or her own liking. Dani's pseudocode might look like BASIC instructions, yet it could be her very own style.

Asif_NSU
Posting Whiz
353 posts since Apr 2004
Reputation Points: 113
Solved Threads: 3
 

pls i am a novice in programming i didnot understand what your mean by pseudocode.

de_lily
Newbie Poster
4 posts since Oct 2004
Reputation Points: 10
Solved Threads: 0
 
pls i am a novice in programming i didnot understand what your mean by pseudocode.

It tells you what the code should be, but in plain english, not in any programming language in particular :)

inko9nito
Newbie Poster
3 posts since Nov 2004
Reputation Points: 10
Solved Threads: 0
 

it could be argued that the original intent of BASIC was to have a language that could more or less work on pseudocode.

As to conditional and assignment operators, it's all what you're used to.
I've been using C and Java for so long I find myself using == outside sourcecode to indicate comparison as well.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

Hey i have some questions on pseudocode can anybody answer me please

Nice guy
Newbie Poster
3 posts since Nov 2006
Reputation Points: 10
Solved Threads: 0
 

Flowcharting Pseudocode can almost be classified as half-code, half-text. Even as its name implies, it is semi-code. It is used by a programmer to outline the algorithms he or she has written, before they are actually translated into code. It is almost a high-level abstraction of code. For the most part, an algorithm to perform the same task in multiple programming languages is the same. The following is an example of pseudocode to ask the computer to input two numbers, and then print out their sum: [indent]input A input B C = A + B print C

[/indent]Using Functions Pseudocode can also be used to interact between functions. By writing our your algorithm in such a way, not only can you easily convert it to any language you choose. It is also much easier to debug (fix) logic errors. Logic errors are those where the entire process being used from point A to point B is not rational or it doesn't work. Using pseudocode to pass variables in and out of functions can enormously help you, especially by using it as a reference guide when writing the code, itself.

Yes, pseudo code seems to be quite easy looking at them, but I see myself making errors anyway. My question is for you: What can I do to learn and understand them better without making it hard for me? I'm in a course now where I have to make a pseudo code, and the book makes it so easy but when put on paper. I have to ask myself what is this?

balinda_wilson
Newbie Poster
7 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

Well, pseudocode is just any arbitrary description of a computational procedure not meant for interpretation by a computing machine in its initial form. I agree with a previous poster that there aren't rules of pseudocode, except what an instructor or you impose.

Always - whether doing pseudocode or real code - start by talking yourself through the problem in plain English. This probably won't work as real code, but depending on the problem, it might pass as pseudocode. If so, write that down and you're done.

How can you tell if your description is "good" pseudocode? Well, it should encode the solution to your problem in a way that you can understand it. Preferably, others should be able to understand it as well. English is a good start.

But English can be ambiguous and lack some of the precision of a more mathematical/computational notation. Go ahead and express common mathematical expressions and functions by some common symbolic representation (for instance, "add a to b and put the answer in c" becomes a c <- a + b) and identify operations which you assume have solutions and consider these as external functions (for instance, "find the number of occurrences of pattern in string and put the answer in repcount" could be repcout <- countall(pattern, string)). Anything else that has an obvious shorthand or symbolic representation should be transformed, simply because it reduces ambiguity to use the symbolism.

Now, to make sure you have really tight, coherent pseudocode - and useful pseudocode - you should recursively do the same for all non-trivial functions you assume in your pseudocode. Either give the representation yourself, describe very convincingly how one would go about making such a function, or refer to a version in an external source. The point is that your pseudocode should be well-defined enough that somebody could pick it up and implement the procedure in a language of his or her choosing; you don't want them to be scratching their heads wondering "how the heck do you count the number of occurrences of pattern in string?". Be explicit.

Don't worry too much about syntax. If you need to introduce new syntax, or you mix syntax, fine, just so long as your meaning is clear. Leave English phrases in the thing as appropriate... you can certainly be more explicit if you want, but that is a decision. For instance, if you want to say "increment each element of the array by one" instead of "for i from 1 to n do array[i] <- array[i] + 1", that can be appropriate. It may not always be, but it's a judgment thing.

AuburnMathTutor
Junior Poster
125 posts since Jun 2010
Reputation Points: 48
Solved Threads: 12
 

I want algorithm for sorting 10 no's in pseudo-code

rizwan iqbal
Newbie Poster
1 post since Dec 2010
Reputation Points: 10
Solved Threads: 0
 

You forgot to include your spam-link.

Nick Evan
Not a Llama
Moderator
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
 
I want algorithm for sorting 10 no's in pseudo-code

Then figure out how to get those numbers, how would you sort them (the key property to sort by, the order of sorting, the actual way you sort), what results would you handle as output (the amount of time the sorting takes, the sorted values, some specific values only from the sorted list, etc.) and what kind of output would you do (printing on screen or paper, beeping, etc.)? Take those step-by-step and write down your decisions using short and brief keywords. You'll end up having a pseudocode suitable just right for your problem.

-Powerslave-
Newbie Poster
8 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You