Friday, October 24, 2008

Ubuntu forgot password

If you don't remember any of your Ubuntu passwords while logging in,
then,
from the boot menu,
select -> Recovery Mode(Ubuntu, not Windows),
then select -> drop root shell
You will get a shell where you would be logged in as root.
There type :
passwd <username>
and change the password.
Reboot.
done.

Thursday, October 23, 2008

Non recursive algorithm for Post Order Traversal

For Pre,Post and In order traversals of a Binary tree,
it is very easy to write recursive programs/algorithms.
But when it comes to a non-recursive solution, it becomes
rather difficult. Though pre-order and in-order traversals
have non-recursive algorithms, which are slightly easier
to implement/understand, post-order is a tough nut to
crack.

Not any more.
Here is an easy to understand non-recursive algorithm
for post-order traversal :
Fact I : Post order traversal(Left-Right-Root) is the exact opposite
of Root-Right-Left traversal(RoRiL)(Prove it!).
Fact II : And a non-recursive algo for Pre-order(RoLRi) is equally good
for RoRiL.

So, just use the non-recursive algo for RoRiL(which is similar to Pre-order)
and traverse it backwards.(that's the post order traversal)

(Pre-order Non Recursive Algorithm)

Monday, October 20, 2008

Rabbit poupulation Fibonacci sequence

Question :
A young pair of rabbits (one of each sex) is placed on an island. A pair
of rabbits does not breed until they are 2 months old. After they are
2 months old, each pair of rabbits produces another pair each month.
Find a recurrence relation for the number of rabbits on the island
after n months, assuming that no rabbits ever die.

Solution :
Suppose there are An rabbits after n months.
Then number of rabbits born in (n+1)th month is : An+1 - An.
An+2
= 2*number of rabbits in nth month + number of rabbits born in (n+1)th month.
= 2*An + An+1 - An
= An + An+1
= Fibonacci sequence

Fibonacci sequence, rabbit population

Question :
A young pair of rabbits (one of each sex) is placed on an island. A pair
of rabbits does not breed until they are 2 months old. After they are
2 months old, each pair of rabbits produces another pair each month.
Find a recurrence relation for the number of rabbits on the island
after n months, assuming that no rabbits ever die.

Solution :
Suppose there are An rabbits after n months.
Then number of rabbits born in (n+1)th month is : An+1 - An.
An+2
= 2*number of rabbits in nth month + number of rabbits born in (n+1)th month.
= 2*An + An+1 - An
= An + An+1
= Fibonacci sequence

Thursday, October 16, 2008

0 is same as '\0'

void main(){
char check[10];
check[0] = 'a';
check[1] = 'b';
check[2] = 0;
printf("%s\n",check);
}
will produce the same output as :

void
main(){
char check[10];
check[0] = 'a';
check[1] = 'b';
check[2] = '\0';
printf("%s\n",check);
}

since ascii code of '\0' is 0,
whereas ascii code of '0' is 48.

Sunday, October 12, 2008

php dom xml problem

Problem :
Warning: domdocument::domdocument() [domdocument.domdocument]: Entity: line 1: parser error : Start tag expected, '<' not found in C:\xampp\htdocs\xyz.php on line 8.

solution :
php_domxml.dll extension has to be commented in the php.ini file under apache/bin.(or
whatever php.ini file is loaded for you, find out through phpinfo()).

source.

Wednesday, October 1, 2008

Vim : stop making a tilda/tilde file

I came across two ways to do it:
(i) :set nobackup and :set nowritebackup
but it didn't work for me.

(ii) :set backupdir=$VIMRUNTIME/vim_backup
it worked for me. Bascially create a directory, where the backup files(tilda files)
will be created. Surprisingly, the backup files are not being created here.
And nowhere else.

I am using gvim on Windows btw.

A software for theorem proving

http://isabelle.in.tum.de/

Blog Archive