Google may say “Failure is always an option at Google”, but from the recent developments and the kind of closures of businesses/developments coming out of Google, looks like its got a tough road ahead for not only just innovating, but getting profits out of it too! Closure of online Google Nexus store, stoppage of development of Wave, a weak attempt to tackle Twitter with low intensity ‘Buzz’, on-course project to challenge the social networking giants ‘Facebook’ with already a fading app ‘Orkut’ in arsenal! All these don’t look like Google, the one who still reigns in the domain of search! Maybe its because of ever-growing competitors or delay by Google to enter into a particular field. It may be doing huge profits in Search field, but from technology and innovation perspective, it long time due for Google to come out with something big, eye-catching and off-course profitable! Can look out for Google Apps and Android!
"I Read, I Get, I Share, You Read, You Get" It doesn't get any simpler...
Monday, August 9, 2010
Wednesday, August 4, 2010
Monday, April 5, 2010
The Sieve to detect Primes
Literally, Sieve is “A utensil for separating the finer and coarser parts of a pulverized or granulated substance from each other”. Eratosthenes, a Greek Mathematician, came up with such a sieve to filter out Prime numbers from a given set of integers. The process/algorithm came to be known as Sieve of Eratosthenes!
The Algo is pretty simple, start with number 2, cross all its multiples (till MAX_NUMBER), proceed with the next number 3 and cross all its multiples too and so on. The remaining numbers in the set will be primes. The algo itself brings in some optimizations!
1. All even numbers get cancelled in first iteration for 2. Next number (3) onwards, start directly checking for multiples starting with the square of the number.
2. The multiples need to be crossed for numbers < square root (MAX_NUMBER), because rest of the multiples would have got crossed earlier itself.
The code in Java for the Sieve of Eratosthenes is as follows:
public class SieveEratosthenes {private static final int MAX_NUMBER = 1000;public static void main(String[] args) {boolean[] arr = new boolean[MAX_NUMBER];int i, j;//Initialize the Boolean array to TRUE (i.e. Prime)for (i = 0; i < arr.length; i++)arr[i] = Boolean.TRUE;//Finish with all divisors of 2 to optimize code for the remainingfor (i = 2; 2 * i < MAX_NUMBER; i++)arr[2 * i] = Boolean.FALSE;//Only odd numbers need to be considered in both loops, since// Odd * Even = Even//And all evens are covered as multiples of 2for (i = 3; i < (Math.sqrt(MAX_NUMBER)); i += 2) {for (j = i; j * i < MAX_NUMBER; j += 2)arr[j * i] = Boolean.FALSE;}System.out.println("The primes below " + MAX_NUMBER + " are : ");int count = 0;for (i = 2; i < arr.length; i++)if (arr[i]) {System.out.println(i);count++;}System.out.println("The total no of primes till " + MAX_NUMBER + " are : " + count);}}
Sunday, March 28, 2010
Java Books
1. JLS : Java Language Specification, the blue-print of Java. This book gives an in-depth understanding of Java architecture.
2. SCJP : Almost all concepts cleared, from programming point of view.
3. Effective Java and Java Puzzlers : These two are mind-boggling books. If you feel you are a Java-Guru, do give these a try and verify it out for yourself! :)
Please feel free to add-on and share any other master-pieces!
Java Puzzlers
Guess the output of the two programs below:
1.
public class SetTest {
public static final String[] URLNAMES = {
"http://javapuzzlers.com",
"http://apache2-snort.skybar.dreamhost.com",
"http://www.google.com",
"http://javapuzzlers.com",
"http://findbugs.sourceforge.net",
"http://cs.umd.edu"
};
public static void main(String[] args) throws MalformedURLException {
Set
for (String names : URLNAMES) {
favourites.add(new URL(names));
}
System.out.println("Size is : " + favourites.size());
}
}
2.
public class Elvis {
public static final Elvis INSTANCE = new Elvis();
private final int beltSize;
private static final int CURRENT_YEAR =
Calendar.getInstance().get(Calendar.YEAR);
private Elvis() {
beltSize = CURRENT_YEAR - 1930;
}
public int beltSize() {
return beltSize;
}
public static void main(String[] args) {
System.out.println("Elvis wears a size " +
INSTANCE.beltSize() + " belt.");
}
}
Output 2:
-1930
Initializing sequence when an object is created. First, static fields get default values, so INSTANCE defaulted to null and CURRENT_YEAR defaulted to 0. Then static initializers get called, accordingly, new Elvis() gets executed and beltsize gets initialized to 0-1930 = -1930!!!! Hence, the output..
Monday, February 8, 2010
Wonders of HTML5
Though HTML5 is still in draft phase, the support for the tags and API's are already available in the latest releases of Chrome, Firefox, Opera and IE! Looks revolutionary, apps have to be re-written to make HTML self-sufficient to render pages and remove dependency on third-party apps to render elements.
Thursday, January 21, 2010
The World is a Matrix
1 0 0 1
0 0 1 0
0 0 0 0
1 1 1 1
1 1 1 1
1 0 1 1
use the first column to record rows needed to be set as all 1's
2. scan through the matrix again, for a[x][y], if (a[0][y]==1 || a[x][0]==1) a[x][y] = 1; time O(m*n)
auxiliary space O(1)
- Imagine there is a square matrix with n x n cells. Each cell is either filled with a black pixel or a white pixel. Design an algorithm to find the maximum sub-square such that all four borders are filled with black pixel.
- Given an n X n array with rows sorted and cols sorted; find the number of negative elements in most efficient way.
- Each cell of an N x N grid is either a 0 or a 1. You are given two such N x N grids, the initial grid and the final grid. There is a button against each row and each column of the initial N x N grid. Pressing a row-button toggles the values of all the cells in that row, and pressing a column-button toggles the values of all the cells in that column. You are required to find the minimum number of button presses required to transform the grid from the initial configuration to the final configuration, and the buttons that must be pressed in order to make this transformation.
- You are given a two dimensional array (say 5*5) in which all the rows as well as the columns are sorted. Describe an efficient algorithm to discover if an element is present or not.
- Give the algorithm to multiply large matrix on system with very less memory which can not hold even one column or one row.
- Write a program to rotate a matrix by 90 degrees.
- Write a code to calculate kth power of a matrix of size NxN. You can assume that matrix multiplication is O(n^3).
- Print a given matrix in a spiral manner.
- Suppose you have a NxN matrix of positive and negative integers. Find the submatrix with the maximum sum of its elements.
- Multiply two given matrices.
- Given a M x N matrix with 0's and 1's, find the largest square matrix consisting on 1's and also find the largest rectangular matrix consisting of 0's