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;
}
}

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