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.

## Friday, October 24, 2008

## Thursday, October 23, 2008

### Non recursive algorithm for Post Order Traversal

For Pre,Post and In order traversals of a Binary tree,

(Pre-order Non Recursive Algorithm)

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

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)

(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 A

Then number of rabbits born in (n+1)th month is : A

A

= 2*number of rabbits in nth month + number of rabbits born in (n+1)th month.

= 2*A

= A

= Fibonacci sequence

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 A

_{n}rabbits after n months.Then number of rabbits born in (n+1)th month is : A

_{n+1}- A_{n}.A

_{n+2}= 2*number of rabbits in nth month + number of rabbits born in (n+1)th month.

= 2*A

_{n}+ A_{n+1}- A_{n}= A

_{n}+ A_{n+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 A

Then number of rabbits born in (n+1)th month is : A

A

= 2*number of rabbits in nth month + number of rabbits born in (n+1)th month.

= 2*A

= A

= Fibonacci sequence

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 A

_{n}rabbits after n months.Then number of rabbits born in (n+1)th month is : A

_{n+1}- A_{n}.A

_{n+2}= 2*number of rabbits in nth month + number of rabbits born in (n+1)th month.

= 2*A

_{n}+ A_{n+1}- A_{n}= A

_{n}+ A_{n+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 :

**main(){**

void

void

**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.

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.

(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.

Subscribe to:
Posts (Atom)