Friday, October 14, 2011

70 Years, programmed the world.


"C is quirky, flawed, and an enormous success."
-Dennis MacAlistair Ritchie (September 9, 1941 – October 8, 2011)


He developed see programming language, though which I was saw possibilities through programming.


#include <stdio.h>
int main(int argc, char *argv[])
{
printf("Hello Heaven\n");
return 0;
}


Sir Dennis's World...

Tuesday, July 5, 2011

Top scorer.

Original Newspaper Article.










Publication:The Economic Times Delhi; Date: Jul 4, 2011; Section: Corporate; Page: 5


TechGig to Launch Season 2 of Indian Programming League

OUR BUREAU NEW DELHI

Technology community site TechGig.com, developed by TimesJobs, will launch the second season of the Great Indian Programming League (GIPL), an innovative method of hiring talented software developers from across the country. TechGig created GIPL to connect with coding buffs who normally work behind the scenes and provide a recruitment platform for companies looking for quality talent.

TechGig.com product head Amit Gupta said: “The IPL is a great way of benchmarking one’s coding skills with some of the best software developers in India. We are now launching Season 2 of the IPL, so there is a lot more action in store.” At GIPL, recruiters looking for high quality technical talent get an objective benchmark to automatically measure the competence of people.

The contest attracts passive candidates to participate even if they aren’t looking for a job. Moreover, the scores are easy to measure, making it easy to find the best people at the top. This renders the contest a great platform to sort and hire. During its first season last month, GIPL got more than 11,000 entries from over 2,700 programmers from across India.

The second contest is coming up due to popular demand from techies and tech firms. In the last season, a large number of coders, programmers and software developers from Delhi NCR, Pune, Bangalore, Hyderabad and Chennai battled it out for iPods, daily movie tickets but more importantly recognition among peers.

Omnitech Infosolutions COO and head of global operations Anurag Shah said: “The Great Indian Programming League is an aspiring initiative taken by techgig.com to not just recognize the talented coders but also provide them a platform to achieve global recognition, which will surely motivate them to feature their best practices in the industry.”

Coding as a field is indeed as promising as other professional fields which require technical as well as domain expertise. Coders play a vital role in the software development and act as a bloodline of the projects. The initiative would bring required awareness and change in perception to help coding attain the deserving limelight, Shah added.

The contest involves writing actual code across five to seven different programming languages, including C #, Java, C and C++, to solve a problem live. The software automatically compiles the code to assess its quality and comprehensiveness in solving the problem.

The second season expects to be more promising going by the reaction of programmers who came from across the country in the first season, just for their love for coding. “Just coding, am mad on coding,” said TCS software developer Vishnu Priya Subramanian while Sameer Namdeo said his motivation was a passion for coding, and chance to evaluate him among peers.

Dotsquares

team lead Deepak Tanwar said GIPL was all about personal enhancement, profile upgrade and opportunity to compete with programmers of different languages.

Users complimented Tech-Gig on the range and complexity of the problems set. Uniprose India product manager Vijendra Kumar pointed out the best part of the contest was that the code could not be seen by other programmers and online instant verification of code.

Winning for software developer Jagdesh from Infosys Technologies Limited was overwhelming while Mahindra Satyam Computer Services Limited project leader Amit Kantilal said: “I feel very proud that I have demonstrated my programming skills. I successfully completed the program to solve the sudoku puzzle which has been on my cards since quite some time.”




Monday, January 10, 2011

Finding Diameter of a Binary Tree.

Diameter Of A Binary Tree:

[1] calculate shortest paths between all possible pairs of nodes in the tree.

[2] the path which is longest among all the shortest paths found in step [1] is the Diameter of Tree.



Sample Binary Tree.




Method 1 (Using Recursive functions.)





Table to be used for reference with the code.


Source code


#include <iostream>
#include <map>
using namespace std;


struct Node
{
    Node()
    {
        pLeft = NULL;
        pRight = NULL;
        cData = 0;
        iMaxLeftWeight = 0;
        iMaxRightWeight = 0;
        iMax = 0;
        iTotalWeight = 0;
    }

    Node *pLeft;
    Node *pRight;
    char cData;

    //max possbile length of left subtree
    int iMaxLeftWeight;

    //max possbile length of right subtree
    int iMaxRightWeight;

    //max possible length of path that can be obtained from
    //traversing either left or right subtree.
    int iMax;

    //iTotalWeight = iMaxLeftWeight + iMaxRightWeight;
    //used to determine center of whole tree.
    //node with max iTotalWeight will be center.
    int iTotalWeight;
};

//structure to store all Node::iTotalWeight of tree.
//MaxWeightNodes stores elements in desending order of iTotalWeight.
//So, its first element corresponds to center of tree.
//definition : MaxWeightNodes[INDEX] = DATA
//here INDEX = Node::iTotalWeight and DATA = pointer to Node itself.
multimap<int, Node*, greater<int> > MaxWeightNodes;

//instead of using map we can keep track of node with max
//iTotalWeight and afterwards this node can be considered as center



int GetMaxWeight(Node *pNode)
{
    if(pNode->pLeft)
        pNode->iMaxLeftWeight = 1 + GetMaxWeight(pNode->pLeft);

    if(pNode->pRight)
        pNode->iMaxRightWeight = 1 + GetMaxWeight(pNode->pRight);

    pNode->iTotalWeight = pNode->iMaxLeftWeight + pNode->iMaxRightWeight;

    MaxWeightNodes.insert(make_pair(pNode->iTotalWeight, pNode));

    pNode->iMax = max(pNode->iMaxLeftWeight, pNode->iMaxRightWeight);

    return pNode->iMax;
}


Node* Traverse(Node *pNode)
{
    Node *pTempNode = NULL;

    if( (pNode->iMaxLeftWeight == 0) && (pNode->iMaxRightWeight == 0) )
        return pNode;

    if(pNode->iMaxLeftWeight > pNode->iMaxRightWeight)
        pTempNode = pNode->pLeft;
    else
    if(pNode->iMaxLeftWeight < pNode->iMaxRightWeight)
        pTempNode = pNode->pRight;
    else
        pTempNode = pNode->pRight;
        //pTempNode = pNode->pLeft;(anything will do)

    return Traverse(pTempNode);
}


void FindEndPointsOfDiameter(Node *pNode, Node **ppLeftEndPoint, Node **ppRightEndPoint)
{
    if(pNode->pLeft)
        (*ppLeftEndPoint) = Traverse(pNode->pLeft);
    else
        (*ppLeftEndPoint) = pNode;

    if(pNode->pRight)
        (*ppRightEndPoint) = Traverse(pNode->pRight);
    else
        (*ppRightEndPoint) = pNode;

    return;
}

void main()
{
/**
Node *pRoot = NULL;

//fill the tree
//assign pRoot to root of tree
//now pRoot points to the root of tree.

//GetMaxWeight() function will traverse every node of tree and fill
//following members (iMaxLeftWeight iMaxRightWeight iTotalWeight iMax)
//of traversed nodes.
GetMaxWeight(pRoot);

//first element of map 'MaxWeightNodes' corresponds to center of tree.
Node *pCenter = MaxWeightNodes.begin()->second;

//finding length of diameter of tree
//diameter can be obtained from center of tree.
//diameter = iTotalWeight = (max length of left subtree + max length of Right subtree)
int iDiameterOfTree = pCenter->iTotalWeight;

//finding endpoints of diameter of tree
Node *pLeftEndPoint = NULL;
Node *pRightEndPoint = NULL;
FindEndPointsOfDiameter(pCenter, &pLeftEndPoint, &pRightEndPoint);

//in similar manner we can find diameter(and its endpoints) correspoding
//to other centers of tree. Other center can be found from map MaxWeightNodes
//by fetching starting elements having max iTotalWeight.
/**/


    Node a1, a2, a3, a4, a5, a6, a7, a8, a9;

    a1.pLeft = &a2;
    a1.pRight = &a3;
    a1.cData = 1;

    a2.pLeft = &a4;
    a2.pRight = &a5;
    a2.cData = 2;

    a3.pLeft = NULL;
    a3.pRight = NULL;
    a3.cData = 3;

    a4.pLeft = &a6;
    a4.pRight = &a7;
    a4.cData = 4;

    a5.pLeft = NULL;
    a5.pRight = &a8;
    a5.cData = 5;

    a6.pLeft = &a9;
    a6.pRight = NULL;
    a6.cData = 6;

    a7.pLeft = NULL;
    a7.pRight = NULL;
    a7.cData = 7;

    a8.pLeft = NULL;
    a8.pRight = NULL;
    a8.cData = 8;

    a9.pLeft = NULL;
    a9.pRight = NULL;
    a9.cData = 9;


    Node *pRoot = &a1;

    GetMaxWeight(pRoot);

    Node *pCenter = MaxWeightNodes.begin()->second;

    int iDiameterOfTree = pCenter->iTotalWeight;

    Node *pLeftEndPoint = NULL;
    Node *pRightEndPoint = NULL;
    FindEndPointsOfDiameter(pCenter, &pLeftEndPoint, &pRightEndPoint);

}