Wednesday, October 31, 2012

Content!!?


Content
 
Long road, pitch black night, walking alone, vulnerable
Not even shadow for company, forlorn
The winding road, every corner raising hopes of reaching the end
The so called fate making you walk to its tune
 
The Euphoria of taking the less-travelled road, long gone
Uncertainty in the mind leading to doubts about the path taken
Only the will and self-belief to guard against giving up
All the profound lessons in life helping you keep calm
 
Fear seeps through the mind, with every passing second
A real test of will, want and desire
With the last surge of energy to see it to culmination
The end comes, slowly, snail pace or so you feel
 
Content that the destination is reached
Feeling the worth of the struggle and pain
All the pieces of the jigsaw in place
We fly away happily having lived a life devoid of crassitude

GT

Saturday, October 13, 2012

LCA - My attempt in deconstructing the recursive solution

Have given enough comments to explain the solution step by step.

/*LCA in a binary tree

Karumanchi Solution : Recursion (Found in http://www.flipkart.com/data-structures-algorithms-made-easy-java-1466304162/p/itmd34fz5jzb599u
Data Structures and Algorithms Made easy in Java
)

*/

//a, b -> parameters - nodes for which LCA is to be found out, they should remain unchanged throughout
BTNode LCA (BTNode root, BTNode a, BTNode b) {
BTNode left, right;

/*
Base Condition 1: if the root pointer is null - do nothing - return null
*/
if ( root == null ) return null;

/*
Base Condition 2: root pointer in this program is searching for a or b;
  so once we reach a or b, no more search is required.
*/
if ( root == a || root == b ) {
//Pointer comparison is enough here
return root;
}

/*
traverse left and right subtrees
*/

left  = LCA(root.getLeftChild(), a, b);
right = LCA(root.getRightChild(), a , b);

/*
Condition 1:

When nodes a and b are on either side (left and right) of a node,
we know that we have arrived at the LCA
*/
if ( !left && !right ) {
return root;
}

/*
Condition 2:

Condition that is required when both a and b are in the same subtree

        eg: 1
        2
        3

Here let a = 2 and b = 3; LCA of a and b in this case will be 1. 2 and 3 are in the same subtree

*/
return ( left ? left : right);

}

OAuth vs OpenId

Last week when I was in my home-town, I was having a conversation with my brother about OAuth and OpenId. When he asked me the difference between the 2 and asked me to give one line for each protocol I was not able to do so. That is when I realized that I was not clear about both the protocols myself.

As usual, went to the drawing board to figure out what each protocol is for.

Found the following presentation extremely helpful :
http://www.slideshare.net/rmetzler/identity-on-the-web-openid-vs-oauth

Summarizing the content here :

OpenId - is meant for identifying the user in the web-world. Only for identification. (as the name says)

OAuth - is required when a 3rd party is looking to access a user's data present in another server.
               Data access.

OpenId - Identification
OAuth  - Data access

Period.