Basics of Computer Programming

By Fadhel Habeeb, Engineer, VLSI department, NIELIT, Calicut. His interests include Algorithm development and implementation, Linux based system development.

6
1484

Digital computers have enhanced human capability in major walks of life and are still penetrating to diverse areas of human endeavor. Their pervasiveness is due to their ability to solve problems with ease and precision, which otherwise would take considerable amount of time for humans alone. One of its main characteristics is programmability (i.e. ability to instruct what to do), have made the wonders we see at present. The programs that run on them routes our communications world-wide, defeated Gary Kasparov (Russian Chess Master), guides our space shuttles into deep space, implement sophisticated medical procedures …etc.

The computing power available for us today is so enormous, that we don’t utilize it to its full extend, other than for frequent mail checks, play games, browse YouTube videos, Documentation etc. There is a wide gap in the technology available to us and its utilization. Computer Scientists and Technologists World-wide are ambitiously designing computing systems to be handled with ease for different background of people. We’ll focus onto see, what are the core skills needed by anyone to create the next Facebook, YouTube … And be part of this digital revolution.

These are the basics…

Firstly, one needs to develop Algorithm for the problem.

Secondly, Translate the Algorithm to executable codes using a suitable language.

Computers at a conceptual level basically do the following;

  1. Fetch data and instructions from memory (Input data for processing from keyboard, sensors…),
  2. Compare or check the data to a value (if, if-else…).
  3. Loop through a set of operations(for, while loops)
  4. Place the modified/unmodified data back to memory (Output data for display, actuation…).

As computers execute instructions sequentially, one needs to develop step by step procedure (Algorithm) for the problem at hand. An e.g. hypothetical Algorithm for Air-conditioning system would be

  • STEP1: Input the desired Room Temperature (t) from the user.
  • STEP2: Measure the room temperature (T)
  • STEP3: if (T > t), then lower the actuation.
  • STEP4: else if (T < t), then increase the actuation.
  • STEP5: else, maintain the actuation.
  • STEP6: Repeat STEP2.

The above hypothetical algorithm, typically describes series of steps a computer controlling an AC to follow. From the above one can deduce that the Algorithm,

  1. Gives provision to input data from the user.
  2. Senses the present Temperature.
  3. Checks the present Temperature to the input value and does the required actuation and
  4. Repeats (Loops) through the process.

Thus, when developing Algorithm, one has to break down the problem, into a series of steps containing the 4 constructs.

  1. Input
  2. Conditionals like if, if-else.
  3. Loops like while(), for()
  4. Output

Once you have broken down and described your problem using the above 4 constructs, then such problems are solvable by computers and you would need just to translate them to computer executable using a suitable language. Computer languages are being designed to be simple, such than once you have developed your Algorithm using the 4 constructs, it’s a direct job to code your Algorithm. Computer languages are designed in such a way that the programmer need to worry of every detail of the system (Like how should the data move from memory to processor or vice versa) and need only concentrate on developing and implementing Algorithms.

Understanding Computer Algorithms

For the case of simplicity, one can classify most of the Algorithms being executed by computers as Forward and Inverse. Forward Algorithms are similar to Hypothetical AC system. They have an input, a set of operations and an output. Examples of similar algorithms are billing system seen in supermarkets, ticketing systems seen in Transportations, Device driver codes, Encryption and Decryption algorithms … Forward Algorithms have a direct input-output relation.

Inverse Algorithms, unlike Forward Algorithms, there is no direct input – output relation. These Algorithms make computers play chess, checkers, gives the best possible route between two places considering Traffic, weather…etc. They assist in Cryptanalysis (breaking Ciphers). These Algorithms are used for industrial and medical tomography, locating oil, natural gas and other resources interior of the earth, reconstructing Astronomical images from telescope data …etc. They are often categorized under the realm of ‘Artificial Intelligence ‘.

We shall see a simple implementation of both kinds of Algorithms using a Mind game known as ‘MASTERMIND‘.

Python files for the game are available for download here.

6 COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here