Text  |   7 September 11 | 7 notes
So long Pal!
One of the most discussed examples in Computer Science classes is the palindrome. Wikipedia defines palindrome as a word, phrase, number, or other sequence of units that can be read the same way in either direction, with general allowances for adjustments to punctuation and word dividers.
According to one article, palindromes were discovered as early as the 79AD where the latin phrase “Sator Arepo Tenet Opera Rotas” was found as a graffito at Herculaneum. However, it was found out that palindromes of considerable complexity were explored in the ancient Sanskrit poetry.
Palindromes are usually discussed in computer science classes because it poses a rather easy problem for students to tinker with. The most common example of a problem involving palindromes is checking whether a given string is a palindrome or not. Here are 3 different ways to check if a string is a palindrome(NOTE: The methods posted assumes that the string be a one-word string and does not include punctuation and word dividers.)
Code #1
public boolean isPalindrome(String word){
boolean isPal = true;
for(int i=0; i<Math.floor(word.length()/2); i++){
if(word.charAt(i) != word.charAt(word.length()-1-i)){
isPal = false;
break;
}
}
return isPal;
}
Explanation:
The method loops until the middle of the string and compares the character found at the value of i and compares it to the character with the same index if the string is reversed. If all characters are equal, then the string is said to be a palindrome
Code #2
public boolean isPalindrome(String word){
boolean isPal = true;
String rev = “”;
for(int i=0; i<word.length(); i++){
rev = word.charAt(word.length()-1-i) + “”;
}
if(!word.equals(rev))
isPal = false;
return isPal;
}
Explanation:
The method reverses the string and stores it in another variable. The method then compare the original string and the reversed string. If the two string are equal, then the string is said to be a palindrome.
Code #3
public boolean isPalindrome(String word){ boolean isPal = true; Stack<Character> stack = new Stack<Character>(); for(int i=0; i<Math.floor(word.length()/2); i++) stack.push(word.charAt(i)); for(int i=Math.ceiling(word.length()/2); i<word.length(); i++){ if(word.charAt(i) stack.pop()){ isPal = false; break; } } return isPal; } Explanation: The method uses a stack, a Last In First Out data structure, and stores all the characters until the middle of the string. The method then pop each character from the stack and compare it to the character corresponding to it on the 2nd half of the string. DISCLAIMER: I didn’t test if the Java codes are working. It may cause some syntax errors but the algorithm will definitely work.
Text  |   10 August 11 | 17 notes
Wise words
“If you want to be a good programmer, you just program every day for two years.
If you want to be a world class programmer, you just program every day for 10 years, or take the “Analysis of Algorithms” class and program for two years.”
By Prof. Erik Demaine at M.I.T.
Text  |   7 June 11 | 5 notes
Bounding Summations
- Mathematical Induction
We can easily verify this for n = 1, so we make the inductive assumption that it holds for n and prove that it holds for n + 1.
- Bounding the Terms
A good upper bound on a series by bounding each term of the series, and it often suffices to use the largest term to bound the others.
- Splitting Summations
Express the series as the sum of two or more series by partitioning the range of the index and then to bound each of the resulting series. Generally, this technique applies when each term in a summation is independent of n.
- Approximation by Integrals
Text  |   30 April 11 | 2 notes
django-endless-pagination: Taking Pagination to the Next Level
Twitter, Google, Facebook, Tumblr, and many other modern websites have many things in common - but none of these as useful as pagination. In some cases, users might not even see this feature as pagination, as there are no explicit pages actually being displayed - rather, the results are being loaded separate from the rest of the page - such as Tumblr and Facebook feeds, or Google Images results.
Photo  |   18 April 11 | 166 notes
fyeahcomputersciencemajorpenguin:
[Picture: Background: 6 piece pie style color split with images of a c++ editor, a terminal installing python, and the blue Microsoft error screen alternating. Foreground: a photo of the penguin which represents Linux. Top text: “declare a long double, name it penetration ” Bottom text: “//ouch”]
Yes, I’ve seen it before and to my sleep deprived mind it was the funniest thing I’ve ever seen.
LOL! :))
Photo  |   15 April 11 | 580 notes
Likes



RSS
Archive
Random

The Social Networks