DEV Community

Cover image for Pseudo Code - build program in your own language.
Anwar Sadat Ayub
Anwar Sadat Ayub

Posted on

Pseudo Code - build program in your own language.

Hi everyone๐Ÿ˜Ž,

From the last post, Programming Concept - #Algorithm, I discussed what algorithm is and also gave an example. Now this post is not about Data Structure and Algorithm, yet!. The idea behind this series is to take you from the beginner level to advanced level in programming so make sure you stay tuned ๐Ÿ“ป.

Pseudo code as mentioned early is basically a false code. Computers understand only two vocabularies i.e. 0 and 1. For every programming language, there is a syntactic rule to follow but with pseudo code, you can write the code in your own language and that is the beauty of it.

Algorithm is all about performing a task and before doing any task, you must first understand what the task is. Every task has it's own requirements and there can be multiple ways to perform the same task.

Let's take look at an example;

Pick-up location map

The bus driver has this map to pick up the school kids from their home labeled A, B, C. Can you guess the shortest route to use from point A, B and C?

  1. School -> A -> B -> C -> School
  2. School -> C -> A -> B -> School
  3. School -> B -> A -> C -> School

Above are 3 possible options to visit all points. Can you pick out the "best" option? Of course, it will be the second option. Why? Because the driver might consider the using less fuel and shortest time. Though we have multiple options, we will always consider the most efficient one. Efficiency is one of the key characteristics of a good algorithm.

Let's write down the pseudo code for the first option:

  • Start the bus ๐ŸšŒ
  • Move from School ๐ŸšŒ๐Ÿซ
  • Go to Point A ๐Ÿ ๐ŸšŒ
  • Move from Point A ๐ŸšŒ๐Ÿ 
  • Go to Point B๐Ÿก๐ŸšŒ
  • Move from Point B ๐ŸšŒ๐Ÿก
  • Go to Point C ๐Ÿ˜๐ŸšŒ
  • Move from Point C ๐ŸšŒ๐Ÿ˜
  • Go to School ๐Ÿซ๐ŸšŒ
  • Stop bus engine ๐ŸšŒ

....and that's it. See how simple you can write down the pseudo code? And this can be used as a blueprint to write code in different programming language.

It's always good to write down the steps when solving a problem in the form of a pseudo code. You can then further break it down into smaller modules making your program easy to manage.

Key characteristics to note about pseudo code:

  • All actions for each step must be doable.
  • Each step must be precisely define with no ambiguity
  • Each step of the algorithm must be finite i.e. it must have an end

Note that your algorithm must also have a starting point and the end point just as every program cannot run infinitely.

In the next article, I will discuss how to write the algorithm graphically using flow chart.

Have a great day ๐Ÿ‘‹ and see you on the next one.

Top comments (0)