Friday, January 25, 2008

Non-recursive algorithms Vs recursive algorithm

Do non-recursive algorithm are more efficient in most computers than recursive algorithms??

I would say yes...

Non-recursive algorithms are executed only once to solve the problem and Recursive algorithms self invokes itself repeatedly until a certain condition is met regarding the algorithm.

When a function is called a stack frame is created for that. Creating a stack frame takes lot of resource allocation in memory. Activation of a function takes a stack frame pushed in to stack. So until a specific condition for the function meet stack frames are pushed to stack. After the condition has been met they will be popped out from the stack. Stack frames are space consuming and pushing and popping of stack frames is an overhead.

Almost all recursive algorithms can be written as non-recursive algorithms. Following is an example of non recursive algorithm for counting factorial.

public static long factorial (int n) {

long result = 1;

for (int i = 1; i <= n; i++) {

result *= i;

}

return result;
}


Most of the recursion can be eliminated by using looping. In some programming languages they convert intermediate code to machine code when they execute such loop. So it is very efficient to use such non recursive algorithm. This is more efficient than executing byte code.

In languages like C++, C we can declare the loop counting variable using keyword “register”, so that the looping is efficiently done.

Considering these facts I can say a non-recursive algorithm can be more efficient in most computers than a recursive algorithm of same theoretical complexity.


Thursday, January 17, 2008

Open source

What I think about Copyleft is?

I consider copyleft as a form of licensing software , documents and music. It is the reverse of the word copyright. (Symbol that used for copyleft proves that) If copyleft is used then it removes the restrictions of using copyright law and remove the restrictions on distributing copies and modified versions of a work of others. For modified work of others the same freedoms has to be preserved.

Quantum Physics

Why we need Quantum physics?
Quantum physics is the physics that explains things like motion of the incredibly small matter. This is different when compared to Newtonian physics, which describe motion,velocity, acceleration and energy transformations during collisions. But quantum physics describes how the electrons are surrounding the nucleus of the atom and many other subatomic actions.
Both explains how the matter is interacts with other matters but there is a big difference since general laws of physics will not be fully applicable when it comes to small scales. So we need quantum physics when we deal with small particles.

Quantum model of an Atom
The quantum model of the atom is very complex than the traditional model we have learned in school. This is definitely due to the fact that it needs very complex math to explain the behaviors and properties of small particles in the atom. It is even more difficult when it comes to subatomic particles. To find the exact position and velocity of an electron is very hard to find because that involves bouncing of other particles with it. These collisions changes the electron's velocity. The quantum physics find the location of the electron at any time using the statistical probability.