No. of Step Calculation in an Algorithm


There was a time when the processor were just starting to explore their potential. Then code optimization made a huge difference in the performance of the code. But, today most programmers take the optimization for granted as the compilers are smarter and the processors run like they have fire on their ass. But, to be a good programmer, one should always stick to the roots of programming. Let their be three arrays, A, B and C of equal lengths n. ...

Random Access Machine


In order to judge the performance of an algorithm, there exists a mental mathematical model. This mental mathematical model helps us to ensure the stability and high performance of algorithms. Also, one could compare two algorithms using this model. Mathematical Model: Random Access Machine. This model consists of a processor and memory. Designing algorithms for RAM:  Variable names are allowed Arrays, structures will be taken as Primitive data types Trees, lists etc are allowed. Instruction set:1. Arithmetic and Logical Operations ...

Some Terms Every Programmer Must Know


The Problem: The problem is a specification of valid input and the acceptable output for each valid input. Input Instance: The inputs which fall in the set of valid inputs according to the problem. Size of Input Instance: The memory/storage space needed to represent the input instance. e.g. In Euclidean GCD example, the size of input instance will not be just the representation of the numbers say m and n, but the total of m and n. An Algorithm: An ...

Greatest Common Divisor: Euclid Style


Euclid out of nowhere proposed this algorithm which calculates the greatest common divisor of two numbers. The simplest way of calculating the GCD is probably the simple prime factorization method. But, Euclid was no common chap. He devised a way which calculates the GCD recursively. The idea was to simplify the problem each time, preserving the GCD. Lets discuss the algorithm, in order to understand it- getGCD(n, m) {    while(n % m != 0) {        r = ...

Programming and Mathematics


The fact is that programming and mathematics go hand in hand. Working for a service company has made me lame with my programming skills. Its sad but true that, my brain now doesn’t relax enough to work for self improvement. Although late in life, but I have understood that every computer science student is supposed to know his mathematics well. And here I am not talking about just weird numeric calculations. I am going to commit myself to algorithms now. ...