Friday, April 22, 2011

Bring Your Tumbler, Get Free Coffee Today - Starbucks Earth-Day Celerbration

Today, Starbucks celebrates the Earth Day. You can get free coffee, hot or cold, with your mug or tumbler. Any branch in US and Canada. 

Enjoy!


Darth Day on April 22


Message From Starbucks.
-------------------------------------------------------
Hi! I wanted to tell you about an exciting event coming up on Earth Day. On April 22 we’re inviting everyone to bring in a reusable mug or tumbler and get a free brewed coffee or tea. Your choice of brew, hot or iced – it is spring after all! This is happening at participating stores in the United States and Canada.

Why are we doing this? We recognize the impact one can make through careful, conscious choices. So we want to encourage and reward those of you who use tumblers or travel mugs in your daily routines. You’re helping to reduce our environmental impact!

If you don’t have a tumbler or travel mug, they will be available for 20% off on Earth Day, April 22. Just so you know, anytime you bring in your own tumbler or travel mug to a participating Starbucks, you get 10 cents off your drink every day.

What if you can’t bring in a mug and don’t want to buy a new one? That’s okay too. Just request your coffee or tea in one of our “for-here” cups and we’ll pick up the tab.

Last year, when we did a similar promotion on Earth Day, more than 1.2 million of you participated. Let’s see if we can beat that this year! RSVP here.

Although reusable serveware and tumbler use still only accounts for a small percentage of total beverages served, those of you who did bring in reusable mugs still made a significant impact. In 2010, people brought their own tumblers into our stores more than 32 million times, keeping nearly 1.45 million pounds of paper out of landfills.

Saturday, April 16, 2011

Computation Complexity - Double Loop

Given a sorted array in descending order, following code counts pairs of two elements with the difference d. It is easy to give an O(n2) bound for the time complexity of the function countingDifference in below codes; n times in outer for-loop and n times inner while-loop.

But a more careful analysis shows that in fact we can give an O(2n) = O(n) bound on the time complexity of this functions.  The command j++; is executed no more than n times totally, while outer for-loop is looping n times.  So, time complexity of this function is O(n+n) = O(2n) = O(n). 

The statement 'this function(algorithm) is O(n2)' is still right. 'this algorithm is O(n)' gives more information about the function.

public class CodeTest {
static int counter1 =0;
static int counter2 =0;

public static void main(String[] args) {
int input[] = {112, 39, 34, 32, 30, 27, 12, 11, 9, 8, 5, 2, 0};
int d = 2;

System.out.print("Input: ");
for(int i = 0; i<input.length;i++)
System.out.print(input[i] + "  ");
System.out.println();
System.out.println( "For " + input.length + " -length array: " + countDiffernce(input, d) + " pairs are " + d + "-differences " );
System.out.println ("Outer Loop: " + counter1 + " times, Inner Loop: " + counter2 + " times");
}

public static int countDiffernce(int input[], int d) {
int cnt =0, n = input.length;
int j = 1;
for (int i = 0; i < n && j < n; i++) {
counter1++;
while ( (j < n-1) && (input[i] - input[j] < d)) {
counter2++;
j++;
}
if(input[i] - input[j] == d) {
cnt++;
System.out.println("\t" + input[i] + " - " + input[j] + " = " + d);

}
return cnt;
}
}

Friday, April 15, 2011

Babies Make Me Laugh and Happy

Wanna be Laugh and Happy!


Thursday, April 14, 2011

Insertion Sort in Java/C of an Integer Array

Average Performance: О(n2)
Best Case Performance:О(n)
Worst Case Performance: О(n2)
Classification: stable, in-place, online
Insertion sort is a simple sorting algorithm: a comparison sort in which the sorted array (or list) is built one entry at a time. It is much less efficient on large lists than more advanced algorithms such as quicksort, heapsort, or merge sort. However, insertion sort provides several advantages: [from Wiki]

  • Simple implementation
  • Efficient for (quite) small data sets
  • Adaptive (i.e., efficient) for data sets that are already substantially sorted: the time complexity is O(n + d), where d is the number of inversions
  • More efficient in practice than most other simple quadratic (i.e., O(n2)) algorithms such as selection sort or bubble sort; the best case (nearly sorted input) is O(n)
  • Stable; i.e., does not change the relative order of elements with equal keys
  • In-place; i.e., only requires a constant amount O(1) of additional memory space
  • Online; i.e., can sort a list as it receives it

Below source code is written in Java, but you can use the function insertionSort() without any modification. Just write your main() function with input array and call insertionSort() with two parameters: array and array size.

public class CodeTest {
static int counter1 =0;
static int counter2 =0;

public static void main(String[] args) {
int input[] = {94,34,53,21,100,102, 21, 53,45, 456, 3, 32,1,5,4};

System.out.print("Before Sorting: ");
for(int i = 0; i<input.length;i++)
System.out.print(input[i] + "  ");

insertionSort(input, input.length);

System.out.print("\nAfter Sorting: ");
for(int i = 0; i<input.length;i++)
System.out.print(input[i] + "  ");

System.out.println("\n Outerfor loop: " + counter1 + " times, inner while loop: " + counter2 + " times");
}

public static void insertionSort(int input[], int length) {
int i, j, key;

for(i = 1; i<length;i++) {
counter1++;
key = input[i];
j = i - 1;

while (j>=0 && input[j] > key) {
counter2++;
input[j+1] = input[j];
j--;
}
input[j+1] = key;
}
}
}

Merge Sort in Java/C of an Integer Array

Conceptually, a merge sort works as follows [From wiki]

  1. If the list is of length 0 or 1, then it is already sorted. Otherwise:
  2. Divide the unsorted list into two sublists of about half the size.
  3. Sort each sublist recursively by re-applying the merge sort.
  4. Merge the two sublists back into one sorted list.

Merge sort incorporates two main ideas to improve its runtime:

  1. A small list will take fewer steps to sort than a large list.
  2. Fewer steps are required to construct a sorted list from two sorted lists than two unsorted lists. For example, you only have to traverse each list once if they're already sorted .

public class CodeTest {
static int counter =0;

public static void main(String[] args) {
int input[] = {94,34,53,21,100,102, 21, 53,45, 456, 3, 32,1,5,4};

System.out.print("Before Sorting: ");
for(int i = 0; i<input.length;i++)
System.out.print(input[i] + "  ");

mergeSort(input, 0, input.length-1);

System.out.print("\nAfter Sorting: ");
for(int i = 0; i<input.length;i++)
System.out.print(input[i] + "  ");

System.out.println("\nmergerSort() Function is called " + counter + " times");
}

public static void mergeSort(int input[], int left, int right) {
int center;

counter++;

if (left < right) {
center = (left + right)/2;
mergeSort(input, left, center);
mergeSort(input, center+1, right);

merge(input, left, right, center);
}
}

public static void merge(int input[], int left, int right, int center) {
int i = left, j = center + 1, idx = left;
int[] temp = new int[input.length];

while( i<=center && j<=right) {
if(input[i] < input[j])
temp[idx++] = input[i++];
else if (input[i] > input[j]) 
temp[idx++] = input[j++];
else {
temp[idx++] = input[i++];
temp[idx++] = input[j++];
}

if(i > center ) 
while(j<=right)
temp[idx++] = input[j++];
else if (j > right)
while(i<=center)
temp[idx++] = input[i++];
}

for (i = left; i <=right; i++)
input[i] = temp[i];
}
}

In-Place Quick Sort of An Integer Array

Quicksort is a divide and conquer algorithm. Quicksort first divides a large list into two smaller sub-lists: the low elements and the high elements. Quicksort can then recursively sort the sub-lists. [From wiki]
The steps are:
  1. Pick an element, called a pivot, from the list.
  2. Reorder the list so that all elements with values less than the pivot come before the pivot, while all elements with values greater than the pivot come after it (equal values can go either way). After this partitioning, the pivot is in its final position. This is called the partition operation.
  3. Recursively sort the sub-list of lesser elements and the sub-list of greater elements.
The base case of the recursion are lists of size zero or one, which never need to be sorted.

Time Complexity: for n entries,
   Θ(n log(n)) in the average case.
   Θ(n^2) in the worst case.

Space Complexity:
   Θ(log(n)) in the average case.
   Θ(n log(n)) when the input array is very large. the space is needed for storing variables like left, right and pivot. .

Java code for in-place Quick Sort here:


public void quickSort(int input[], int left, int right) {
int pivot = input[(left +right)/2];
int i = left, j = right;
int temp;


while (i <= j){
while(input[i] < pivot && i < right)
i++;
while(input[j] > pivot && j > left)
j--;

if (i <= j ) {
temp = input[j];
input[j] = input[i];
input[i] = temp;
i++; j--;
}
}

if (left <j)
quickSort(input, left, j);
if (i < right)
quickSort(input, i, right);
}

Pregnant Fighter Takes Down Opponent


Cyndi Dandois is an MMA fighter with a 5-1 record is a yet more telling clue. And if for some reason you need more proof, here she is winning her latest bout, which took place last month against Jorina Baars. She was two months pregnant when she fought last month against Jorina Baars.

She said about after the fight.


I did tests before because my weight was more difficult to reach, but they were all negative so I didn't realize it.

Ariel Helwani of Versus.com has more;
Interestingly enough, Dandois' last fight was on March 19, so if she really is three and a half months pregnant, that means she competed in a fight (which she won, by the way) while she was over two months pregnant.
She was over two months pregnant when she entered the ring. Luckily she avoided any serious damage that could have harmed her unborn child.


Female fighters must take pregnancy tests in order to be cleared to fight in the U.S. whereas in Europe, most of the time they only need to sign a declaration stating they are not pregnant. Hard to believe this could have slipped past someone, no pun intended, but it looks like it did.

Dandois was actually scheduled to fight again in June, but obviously the pregnancy put an end to that plan. Strikeforce CEO Scott Coker, in an interview with MMAFighting.com Ariel Helwani, stated he offered the fight to Dandois, but she had to back out because she’s 3 and half months pregnant.

Binary Search of an Integer Array

Binary Search Program. It's written in Java, but it's almost same as C program. All you need is just use 'sizeOf()' macro (fuction) to get the length of array.


public static void main(String[] args) {
int input[] = {1,3,5,6,7,8,9,10,11};
                int query = 3;
System.out.println(query + " is in input[" + binarySearch(input, query) + "].");
}

public static int binarySearch(int tree[], int query) {
int beg = 0;
int end = tree.length-1;
int mid = (beg+end)/2;

for(int i=1; mid >=0 ;i++) {
System.out.println(i+ "th try - index:" + (mid + 1) + "/" + tree.length);
if(tree[mid] == query)
break;
else if(tree[mid] > query)
end = mid - 1;
else
beg = mid +1;

mid = (beg + end)/2;
   if (beg >= med)
      mid = -1;
}
return mid;
}

Wednesday, April 13, 2011

Converting Alphabet to Decimal

Question: Convert Alphabet to Decimal Number. For example, numbering column numbers  in MS Excel;
   A → 1,
   Z → 26,
   AA → 27,
   ZBC → 17631.


When considering only capitals, following Java function converts alphabet to decimal.

public int alphaToDecimal(char input[]) {
int ret = 0;
int a, b;
int i, j;
for (i=0; i<input.length; i++) {
a = input[i] - 'A' + 1;
b = 1;
                // you can use Math.pow(); 
for(j=0; j<input.length-i-1;j++)
b *= 'Z'-'A' + 1;
ret += a*b;
}
return ret;
}

Why are manhole covers round?

It's a famous interview question considered anywhere from thought provoking to downright stupid by people on the receiving end. In fact, during Google or MS software engineer interview, the question occasionally asked. What's the best?

I think it's not REAL question. Interviewers don't wanna get a answer, instead they wanna to get a sense for an interview candidate's ability to think on his or her feet outside of their area of expertise. know how candidates

Well... it's sqaure.
Possible Answers here. Don't make it simple. Show your ability.

1. The cover can’t actually fall into the manhole.

2. The hole is just round.

3. Animals dig round holes, so it feels natural to humans too.

4. A circle offsets the straight lines of a city.

5. It is easier to roll the cover some distance than carry it

6. It is easier to pour hot metal into a circular mold than one with sharp corners

7. Its the most efficient use of space in consideration of the types of elements entering the hole. One could imagine reducing the circumference to a point where there is no room to move but up or down, whereas with a square there would be some air space.

8. Round manhole covers are easier to manufacture.

Sunday, April 10, 2011

48÷2(9+3) Problem. Answers from Calculators

The problem of 48÷2(9+3) becomes an issue again over the world. What's yours? 2 or 288?

First, parenthesis implicates 'multiply', so
48÷2(9+3) = 48÷2*(9+3) = 48÷2*12 = 24*12 = 288.
Second, by the distributive law,
48÷2(9+3) = 48÷(2*9+2*3) = 48÷(18+6) = 48÷24 = 2.


It's still arguable. How about calculators?

Google's Answer : 288

web2.0calc: 288

Some Scientific Calculators: Invalid Input - the parenthesis can't be followed by digit directly. My cellphone calculator display same error.  Most online calculators show the error.

Calculator for Chemists: 0.22... OMG... (see the site)

MS Windows's Calculator: 12 ? I guess the calculator ignore the inputs before the parenthesis

Commercial Scientific Calculators: depending on model number. (...)


What's the answer!!!

Infiniti Essence with Racing Girls

Celebrating 20 years as a creator of performance luxury vehicles, Infiniti introduces a vision crafted to embody our core values and inspire future design: the Infiniti Essence. This dramatic styling, technology and performance statement is a 592-hp gasoline/electric hybrid coupe defined by exterior lines sculpted to express fluidity and speed. Destined to influence production models of the future, the Infiniti Essence vividly captures the balance between grace and power, and the unrestrained possibility of Inspired Performance™.

Following pics from Seoul International Motor Show 2011.









Racing Girls with Jeep Wrangler 2011

The 2011 Wrangler is a 2-door, 4-passenger sport-utility, available in 4 trims, ranging from the Sport to the Rubicon.

Upon introduction, both trims are equipped with a standard 3.8-liter, V6, 202-horsepower engine that achieves 15-mpg in the city and 19-mpg on the highway. A 6-speed manual transmission with overdrive is standard, and a 4-speed automatic transmission with overdrive is optional.

The 2011 Wrangler is freshened for 2011.

Following Pics from Seoul International Motor Show






Saturday, April 9, 2011

Comparison Between Hashtable and HashMap in Java

The HashMap class is roughly equivalent to Hashtable. Both provide key-value access to data. The Hashtable is one of the original collection classes in Java. HashMap is part of the Java 2, v1.2. The key difference between the two is that access to the Hashtable is synchronized on the table while access to the HashMap isn't. You can add it, but it isn't there by default. Another difference is that iterator in the HashMap is fail-safe while the enumerator for the Hashtable isn't. If you change the map while iterating, you'll know. And, a third difference is that HashMap permits null values in it, while Hashtable doesn't.

So, if you your process is multi-threaded, then it's good idea to select Hashtable. However there is a way of making Hashmaps thread safe using Collections.synchronizedMap(new Hashmap() ). If my Java version is 1.5 or higher, then I have the option of using ConcurrentHashMap.

One more, be careful with the class names, HashMap and Hashtable.

By the way, people tends to use HashMap rather than Hashtable. I don't know the reason, anyway, it's comfortable to use.

Friday, April 8, 2011

AIDS Infected Gunman Kills 12 Children in Brazil

A horrible school shooting occurred Thursday in Rio de Janeiro, Brazil.  According to AP, a gunman roamed the halls of an elementary school and killed 12 children, lining them up against a wall and shooting them in the head at point-blank range as he shouted, "I'm going to kill you all!"

The gunman was identified as 23-year-old Wellington Oliveira, who had once attended the Tasso da Silveira school in a working-class neighborhood in western Rio. Oliveira then took his own life after police gunfire struck his legs and sent him toppling down some stairs, but not before carrying out what crime experts are calling the worst school massacre in Brazil's history.

No motive was known, but authorities said the shooter left a rambling and mostly incoherent letter at the scene indicating he wanted to kill himself. Edmar Peixoto, the deputy mayor of western Rio, said the letter also stated the gunman was infected with the AIDS virus.

It was the worst school shooting in Brazil and would have been deadlier if the gunman had not been shot in the legs by a police officer, who said the man then fell down some stairs and shot himself in the head.

Images taken with a cell phone and posted on YouTube showed students fleeing wildly, screaming for help, many with their white and blue school shirts soaked in blood.

The dead included 10 girls and two boys, plus the gunman, according to the Health and Civil Defense department. Those killed were between the ages of 12 and 15. One of the boys died at a hospital about 12 hours after the shooting.

Hundreds of distraught parents rushed to Tasso da Silveira school for word of loved ones. Several people fainted amid the harrowing scenes / AP Source: AP
Source: AP
Source: AP

Racing Models - Seoul Motor Show 2011

"Evolution, Green Revolution on Wheels"

The 2011 Seoul Motor Show kicked off April 1 (Eastern Time) with an aim at becoming one of the world's premier car events. The bi-annual event, which was bigger than ever this time around featured the latest vehicles out now and some that we can expect to see in the future.

Overview
  • March March 24 - April 12 (Exhibition: April 1-10)
  • KINTEXT, Seoul, South Korea
  • Participants: 12 Korean (Hyundai, Kia, SSangyong, Renault Samsung, AD Motors, GM Korea, G&D wintec, Power Plaza, etc), and 23 Foreign Company (US: GM, Ford, Chrysler, Japan: Lexus, Toyota, Nissan, Honda, German: BMW, Audi,Benz, Volkswagen, Sweden: Volvo, etc)
Pics Racing Models with participating cars.



Nissan Reef
KIA K-5

Nissan 370Z

Jeep Rubicon New Wrangler

Samsung Lenault Twizy

NEW CITROËN DS3

Ssangyong Chairman

Jaguar All New XJ

Jeep New Compass

Toyota EF-86

Peugeot 508GT










 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Macys Printable Coupons