Saturday, July 31, 2010

Program to find Maximum sum of a subset in an array

I came up with the efficient O(n) solution for this problem. If you have better solution to this problem; Please post your solution as comment. Also remember that, the largest sum could also be among all negative numbers as well, the sum is not necessarily a positive sum.
int MaxSumSubArray(int *a, int len, int *start, int *end) { int max = INT_MIN; int min = 0; int sum = 0; *start = -1; *end = -1; for (int i = 0, j = 0; i < len; i++) { sum += a[i]; if (sum > max) { *start = j; *end = i; max = sum; } if (sum < 0) { j = i + 1; sum = 0; } } return max; } we can call this api as follows: int a[]={-3, -2, -10, -4, -7, -8, -10, -10, -100, -12, -3}; int s1 = 0; int s2 = 0; int sum = MaxSumSubArray(a, sizeof(a)/sizeof(int), &s1, &s2);

Saturday, January 9, 2010

Capacitive vs Resistive touch screens

Are you confused with all this fuss on resistive and capacitive touch screens coming with the smart phones these days? Here is an article that helps you understand both the technologies.

First of all, here is the explanation as to what a Capacitive touch screen and a Resistive touch screen is, in scientific terms.

Capacitive touch screen:

The capacitive touch screen is made up of a glass panel that is coated with a material. The property of this material is that it can store electrical charge. So the capacitive touchscreens basically stores electrical charge.

But for good, Human body can also store charge. So, when you touch this screen with your finger, some of these charges on the screen gets transferred to your finger. The oscillator circuits located at the corner of your system will then sense this decrease in the charge on screen and spot the exact location where touch occurred, and then transfers this specified information to the touchscreen driver software.

Example: Apple iPhone uses a Capacitive touch screen

    * Multi-touch support available
    * Visibility good even in sunlight
    * Highly sensitive to finger touch leading to ease of use
    * Not prone to dust particles
    * Glossy look and feel


    * Need to have at least 5% humidity to achieve capacitive effect
    * More expensive than Resistive touch screen
    * Doesn't work with inanimate objects/fingernails/gloved fingers
    * Latest technology, may need to evolve a bit more!

Resistive touch screen:

Resistive touch screen, on the other hand is again made up of normal glass panel. However, this glass panel in this case is coated with three layers.

Two of these layers being conductive and resistive are kept apart using spacers while the third scratch-resistant layer covers the whole setup.

When the resistive touch screen system is running, current flows through these layers. On a finger touch, the two layers get connected and change in electrical field occurs. The system calculates the coordinates of point of contact and passes them to touch screen driver software.

Example: Nokia N97, Nokia 5800 Express Music uses Resistive touch screen


    * Relatively cheaper
    * Can operate with any pointing devices like stylus, pen, nail etc
    * Can operate at any level of humidity
    * Ease of use, as it could be used even with your winter gloves on!
    * Very useful for people using handwriting recognition system, due to ease of use with a stylus!
    * More accurate than capacitive touch screen!
    * Old technology and hence more reliable!


    * Multi-touch support not available. Though technology did evolve after some modifications with the existing resistive touch screen circuitry, its still not 100% developed yet!
    * Highly sensitive. As it can operate with almost any sort of pointing devices, can be more vulnerable with dust particles!
    * Poor visibility in sunlight, mostly due to multiple layers reflecting light!
    * Screen, being sensitive at the upper layer, can be more vulnerable to scratches!