A 0-1 Knapsack Problem

/*
Input two integers M and N. Find all possible ways that the sum of numbers chosen from 1, 2,3,...N equals M. Print all possible combinations.
*/

Combination of letters

// List all combinations of letters in a string. Suppose no letter is repeated.
// traverse letters from the first one to the last one.
// combination[ ] is used to save the result of each combination.
// layer indicates the number of letters in the combination, also it tells you
// the position of the newly visited letter in combination[ ]
// layer increases by one in each recursion

Sieve of Eratosthen algorithm

Sieve of Eratosthen algorithm is used to find primes.
The following codes(modified) are from Algorithms in C++ and Core Java Volume I.

Palindrome

The following program determines if a given string is a palindrome.
Another way to do this is first to copy the string to another char[] and remove the non- alphabet characters from the string. Then copy it to the third char array and  reverse the order of the string . Finally compare the two strings.

[C++] An implementation of atoi

This is an implementation of atoi function I wrote. Seems it works.

Setup MySql on Ubuntu 11.04

Install MySQL
sudo apt-get install mysql-server-5.1
sudo mysql_install_db
sudo mysql_secure_installation
Then download and install JDBC (connector/J) driver.

MySQL Programming in Java

Connecting to Database:
String url = "jdbc:mysql://hostname:portNumber/databaseName";
String username = "dbuser";
String password = "secret";
Connection conn = DriverManager.getConnection(url, 
   username, password);

Setup MySQL on Fedora 15

yum install mysql-server
Start MySQL server and autostart on boot:
/etc/init.d/mysqld start  ## use restart after update
##OR##
service mysqld start ## use restart after update
chkconfig --levels 235 mysqld on