Tuesday, March 7, 2017

Algorithms: What's the difference between an Algorithm and Psuedo-code?

This blog is based off of a question from one of my subscribers, Debojit Acharjee:
“Hi! I want to know how to write an algorithm and is there any syntax for writing algorithm? What is the difference between algorithm and pseudocode?”
Debojit, in order to understand the clear difference, how to write algorithms, and whether or not we have the syntax available to write those algorithms, we need to understand these terms first. If you look up “algorithm” in the Oxford dictionary, you will find the definition “a process or set of rules to be followed in calculations or other problem-solving operations, especially by a computer”.
This definition does not bind you to use a particular syntax when writing an algorithm. But, it does mention some phrases, like “rules to be followed”, “calculations”, “problem-solving operations”, and “especially by a computer”, which can’t be imagined without some formal discipline. Therefore, you don’t have to follow a specific strict grammar (syntax) to write an algorithm, per se, as long as you are able to communicate “the process” or “the set of rules” to do a particular task or solve a problem, and of course, doing it in a finite number of steps, optimally.
Next, let’s say you want to write an algorithm to arrange three distinct random numbers in ascending order. You can do so in plain English, using block diagrams, pseudocode, or you could create a flowchart. “Algorithm” is a term used mostly in Mathematics and Computing. Therefore, you write algorithms to communicate with other people in fields like Mathematics and Computing. You wouldn’t write an algorithm for preparing a cup of tea for your breakfast, but you would certainly write an algorithm to sort 10 random numbers in ascending or descending order.
“Algorithm” is a formal term. One example of an algorithm you could write is to find the biggest of three distinct integers, and here’s an example:
Example of a flowchart showing an algorithm to find the biggest of 3 distinct integers.

Let’s get back to the Oxford dictionary again: it defines
pseudo-code as “a notation resembling a simplified programming language, used in program design”.
Analyzing this word, you see it consists of two separate words, “pseudo”, and “code”. Let’s break this down:
The word “pseudo” loosely means “false”, or “not actual”. When read with the second word, it’s “pseudo-code”, which should lead you to its meaning - which is false (close to) code. Pseudo-code is the English-y representation of code, but it’s not actual code. It’s written as if you are actually writing code, but the programming language and hardware specifics have been taken away from it for two main reasons:
  1. Universally Understandable. One of the main goals of pseudo-code is to be understandable by all coders - universally.
  2. Universally Translatable. Once all coders are able to understand the pseudo-code, just like someone who knows 2 different languages and is able to translate between them, the coders can then implement the solutions that the pseudo-code is providing in their choice of programming language.
Pseudo-code to display the biggest of the three distinct integers would look like:
START
var: n1, n2, n3, BiggestInt
READ n1, n2, n3
BiggestInt = n1
IF BiggestInt < n2
   BiggestInt = n2
ENDIF
IF BiggestInt < n3
   BiggestInt = n3
ENDIF
DISPLAY “The biggest integer is:”, BiggestInt
END
I hope this helps, Debojit!

5 comments:

  1. Hi Tanmay,I wanted to buy your's Hello Swift book,but it is unavailable on India's Amazon website.Will you you please help me out?

    ReplyDelete
  2. Hi tanmay i want to be like u help me in creating app

    ReplyDelete
  3. Quickbooks enterprise support Phone number Contact QuickBooks Enterprise Support Phone Number for 24 hour support for Enterprise Quickbooks. The QuickBooks Business Support Group is ready to solve the QuickBooks Business Solutions. To contact our certified QuickBooks + 1 (833) 400-1001 specialist, contact the Quick Books support team.

    ReplyDelete
  4. HP Printer Support Phone Number provides a wide range of comprehensive online technical support for its users 24/7 and not in any means we are

    associated with the product manufacturer. For any instance, if you are in need of any technical support we deal in all HP computer, laptop, printer,

    and troubleshooting errors Feel free to contact us on our toll-free number +1 (855)-924-8222 at any time we offer versatile 24/7 assistance.
    HP Printer Technical Support Number

    ReplyDelete
  5. To keep your printer working and running, you need external customer support. Such issues require expert technical solutions to get rid of them in time. With our helpline services, Brother Printer support is now availed with at door services.

    Brother Printer toll free number
    Brother printer support number

    ReplyDelete