Toh Challenge: Overview
Toh Challenge: Overview
OVERVIEW :
We did analyse the Towers of Hanoi problem in the class mathematically and
ended with the efficiency of 2^n – 1.We had taken ‘Disc Movement’ (printf statements) as
our basic operation and each recursion calls contribute to one basic operation. However,
when we implemented the same in the lab, the practical results were in no relation to
established theory.
WHY ?
As we know Towers of Hanoi’s problem includes recursion and it doesn’t include
any prominent operations other than printf statements . So we considered this as the basic
operation of the program . And it has efficiency of 2^n -1 which belongs to exponential
order of growth . During theoretical calculations we don’t consider the time taken by printf
statements or stdout But in practical these statements take more time than we expect
because it is library function . However these don’t disturb the practical value of time
efficiency because we multiply time taken by each operations to no. of operations(n) in
order to get the total time taken .
Actual reason for the difference between theoretical and practical values of time is the
value ‘n’. Even though we say computation time of a code varies as the exponential
function of n , it behaves differently depending on the value of n. Fact is that Time
complexity won't give you an estimate of the real running time.
Even if you have a different O(2^n) algorithm, depending on the coefficient in front of
the 2^1 for the real number of calculations, it could take shorter than an O(n) algorithm for
all useful inputs. During calculations we often neglect coefficients or added ,subtracted
element , but in real time they also play a role in actual running time . In our case , we
neglect -1 term from the efficiency which may contribute some amount to real time .
For some values of n it relates to derived theory. However , we have many software or
programs running background during ‘real time’ calculation.
Another reason :
As I mentioned above , running programs like mp3 player ,video player in background
might be one of the reason for change in the practical time taken. The processor
constantly jumps between the different processing "threads" or "instruction streams" to run
several concurrent programs under a real-time illusion called concurrency. The computer
ends up wasting processor cycles while switching between jobs and doesn't run at optimal
efficiency when multitasking.[1]
The problem with big-O notation is that the hidden constant can easily vary several
orders of magnitude. For example, accessing memory from RAM is about a hundred times
slower than multiplying two floating point numbers, but with big-O they are counted the
same.[2]
Even when we are calculating time practically , it gives different ‘time taken’ for the
same input if we have other programs running in background.
The asymptotic complexity doesn’t tell us anything about absolute running time. It
tells us how will that running time grow, when the input size grows. Because when
we use asymptotic notation, we only care about the running time asymptotically with
respect to the input size.