“To write a program which gives correct output is not the acme of skill but to write a program which gives correct output efficiently and elegantly is.”
The objective of this blog is to share my thoughts on how students should approach programming problems. The idea is to inculcate algorithmic thinking in students, so that they can write programs which not only gives correct output but do so efficiently and elegantly. Students must understand that writing a program which gives correct result is the minimum requirement for any program. I have noticed that mostly computer teachers emphasize on correctness of the program and efficiency sometimes doesn’t even comes in the picture, even for simple things.
I will illustrate my point with the help of a simple example: If I ask someone whether 1,000 is a prime number or not, is that person going to divide 1,000 by all numbers from 2 to 999! Definitely not, Then why should the computer be made to count from 2 to all the way up to 999 one at time to determine if 1,000 is a prime number or not. Why not just check for 2 separately as it is the only even prime number ?!. Why not eliminate all even numbers other than 2 ?!
The above example is mostly common sense and some basic mathematics. I have experienced that if we initiate and encourage students to think for a while before jumping on code directly, think in terms of efficiency becomes a second nature after sometime. The number of websites and blogs giving solved problems without any explanation or regards to efficiency are as numerous as the quills on a porcupine. This blog is my attempt to address the problem of scarcity of quality programming related content. I will be posting problems along with programs accompanied by proper explanation. The programs I intend to post would be efficient and will incorporate best practices like proper use of function and mnemonic variable names.