Tuesday, October 23, 2012

Printing India's Map using C !

I found this piece of code on stackoverflow. This prints the map of India in '!'. Have a look here http://codepad.org/UKwPb77f


#include "stdio.h"

main()
{
    int a,b,c;
    int count = 1;

    for (b = c = 10; 
    a = "- FIGURE?, UMKC,XYZHello Folks,\
    TFy!QJu ROo TNn(ROo)SLq SLq ULo+\
    UHs UJq TNn*RPn/QPbEWS_JSWQAIJO^\
    NBELPeHBFHT}TnALVlBLOFAkHFOuFETp\
    HCStHAUFAgcEAelclcn^r^r\\tZvYxXy\
    T|S~Pn SPm SOn TNn ULo0ULo#ULo-W\
    Hq!WFs XDt!"[b+++21]; )
      for(; a-- > 64 ; )
        putchar ( ++c=='Z' ? 
                             c = c / 9 : 
                             33 ^ b & 1  );

    return 0;
}

         !!!!!!                                                     
                    !!!!!!!!!!                                                 
                     !!!!!!!!!!!!!!!                                           
                       !!!!!!!!!!!!!!                                          
                     !!!!!!!!!!!!!!!                                           
                      !!!!!!!!!!!!                                             
                      !!!!!!!!!!!!                                             
                        !!!!!!!!!!!!                                           
                        !!!!!!!!                                               
                        !!!!!!!!!!                                             
                       !!!!!!!!!!!!!!                                          
                     !!!!!!!!!!!!!!!!                                          
                    !!!!!!!!!!!!!!!!                                  !!!!!    
                  !!!!!!!!!!!!!!!!!!!                               !!!!!!!!!! 
                 !!!!!!!!!!!!!!!!!!!!!!!                 !         !!!!!!!!!!  
            !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!              !!     !!!!!!!!!!!!    
           !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!        !!      !!!!!!!!       
            !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!      
             !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!       
              !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!  !!!!!!!!!!!!       
       !!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!        !!!!!!        
      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!      !!!!!         
          !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!        !!!          
        !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!        !          
          !!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!                       
           !!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!                         
                  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!                          
                 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!                           
                  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!                               
                  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!                               
                  !!!!!!!!!!!!!!!!!!!!!!!!!!!!                                 
                  !!!!!!!!!!!!!!!!!!!!!!!!!!                                   
                  !!!!!!!!!!!!!!!!!!!!!!!!!                                    
                   !!!!!!!!!!!!!!!!!!!!!!!!                                    
                    !!!!!!!!!!!!!!!!!!!!                                       
                    !!!!!!!!!!!!!!!!!!!                                        
                     !!!!!!!!!!!!!!!!                                          
                      !!!!!!!!!!!!!!!!                                         
                      !!!!!!!!!!!!!!!                                          
                       !!!!!!!!!!!!!!                                          
                        !!!!!!!!!!!!                                           
                        !!!!!!!!!!!!                                           
                        !!!!!!!!!!!!                                           
                          !!!!!!!!                                             
                          !!!!!!                                               
                           !!!!    

Sunday, September 9, 2012

Is Business Analytics the next BOOM ?


Wikipedia refers business analytics to the skills, technologies, applications and practices for continuous iterative exploration and investigation of past business performance to gain insight and drive business planning. Well and rightly said so, now what does it mean to me, you or anyone who wishes to be a part of the next boom after IT. This time there is room for making mistakes as there is no shortage of skilled labour and availability of training. There is a huge corpus of unemployed and ready to graduate job-seekers who will at one signal jump into the vast ocean of this field of analytics.


We are producing around 2328306436 GB of data each day. Now we can't just simply generate this data, we have to make meaning and sense out of it, and build something useful that helps us improve our lives. The previously relied upon "gut feeling" to make decisions, is no longer highly reliable in this technological world.Today VPs' and CEOs' are trying trying to get the best out of their massive data and IT alone can't just help them. Keeping a real-time tab on customer's demands and fulfilling them is what they desire today.
In this uncertain world, how does analytics promises powerful insights, reduced costs and increased profits ?
Analytics converts extensive data, stats and quants into insights that can drive efficient decisions and derive strategies.For every buck spent on analytics, companies reportedly get a return value of almost 1000%. Leave alone the industries, just imagine how much could governments save in terms of operational costs if they were to adopt analytics to analyse their earnings and expenditures. 
 Needless to say but my gut feeling says that business analytics is ready to take the world by storm, and we might be lucky (intelligent) enough to swing a ride with it into the future.

Wednesday, August 15, 2012

Change in the definition of growth ? Not just number of employees or revenue, but also quality !!!

(Please don't think I am biased to favour the Indian IT industry, I am a part of the bandwagon so I include references to it)
Recently while talking to a senior executive at a company I came across this question written in the blog title, he mentioned that companies have recently started to realize that while growth is important, but increasing number of employees into the firm is no good way to achieve it.
In the last decade companies hired lots of graduates and staffed them into various projects outsourced from abroad. The resources were shown to the clients as resources waiting to start executing the projects. More the resources more chances of getting newer projects. 
One good thing which the recession brought in was growth of analysts and consultants.
10-12 years down the line HR analysts realized that companies have grown to fat sizes and that this is no good way to grow. By simple high school math one can figure out that by increasing resources and doing the same amount of work reduces productivity per resource !
This meant improvising the existing talent so that productivity and revenue both could be increased.
This doesn't mean that we need to stop hiring at the entry levels in the future but we need to definitely get the best people at entry levels itself. By hiring quality people at the entry level, companies will get better people at higher levels in the future. Better people means more quality work is done, ensuring client satisfaction and finally growth in terms of revenue.
So it seems, gone are the days of rampant and blind hiring at colleges during final/pre-final years of graduation. If you are reading this and if you are looking for a job then its time to be not only talented, but also to do your work in a qualitative manner rather than just quantitatively. To tell you the truth, if you are good, people will like to stay with you and companies will make efforts to retain you (in cash or in kind). But if you ain't good nobody cares, there is a huge ocean of people waiting to showcase their skills and talent.

Wednesday, August 8, 2012

Reasons why IT industry isn't the same anymore

Back in time 10 years back, being a part of the IT industry in India was considered uber-cool and elite. The profession commanded respect and even the mention of the word computer science engineer sent bells ringing in the ears of neighborhood aunties looking for grooms for their daughters. Onsite trips for a few months or sometimes years were the norm and people got richer and richer. Property prices zoomed up in cities and suburbs and property brokers thought of different techniques to fleece the buyers in the name of IT boom.

But what happened to the once elite considered profession ? Why isn't it the same anymore ?
Why has it become a dharamshala for all kinds of people ? Why doesn't it come back to it normal self (pre-2007 era) ? Where are the phenomenal salaries that were offered to employees earlier ?

Reason #1 : ( There is no IT in IT ! )
IT work involves insignificant amount of knowledge related to computer science or information technology for that matter. Anybody who knows how to click and type with decent amount of common-sense can come over and start working.

Reason #2: ( IT work is nearly complete )
Most of the IT work has already been completed and optimized in these last 12-15 years of IT boom, which leaves behind little to be done. Clients can today just order a solution over the internet, just like you order a book from amazon.com. The little configuration or customization that needs to be done doesn't need to be outsourced , it can done by hiring a few more members into the IT team of the client themselves.

Reason #3: ( Privacy Issues )
People are today concerned about their privacy and hence are the companies handling the common people's data also concerned about data security and privacy. This has led to companies forming their teams which does the IT work at their own location with lesser issues of data privacy and theft. Specially banks and investment firms.

Reason #4: ( Supply >>> Demand )
The industry is today over-saturated with employees. There is no need for much head-hunting. Thousands of employees are sitting idle today having no work to do at all (read bench). Now, how can one expect that one will be offered a envious hike when he switches companies ?

Reason 5: (Reason#1 + Reason#4)
Finally, the job is such that it doesn't require any heroic programming or analytic skills. On the floor (the workstation where you work) everybody is alike.So this leaves little for the supervisor to differentiate on the basis of your academic background/skills. So you might find a science graduate doing the same work as a electrical engineer. Companies have been seen promoting schemes for bachelor of science graduates to complete their masters along with a job at their offices. It helps them to save costs and get trained bonded resources to work for peanuts.

Sunday, August 5, 2012

Why a QA makes a better BA !

Some people asked me to write more about how does a test engineer gains an advantage over developers when it comes to being a good business analyst. Here's it.
As a tester, you get access to certain integration and pipe diagrams which are often not given to developers, maybe due to contractual obligations and often because projects are so large that a developer would not like to waste his time understanding the different flows across modules but instead focus on understanding his own module. (Keeping in mind number of modules run into four or five digits)
The understanding of key business flows help build and gain knowledge of systems and also the domain of the project. And a business analyst does just the same !
So if you are looking for a future in analyst or consultant roles, then quality analyst is the role to play in your early  years. Yes there are other ways to go about that also, such as doing a MBA or some management related course, but it then it compromises on your work experience for that period of time.
Take your call carefully buddy :)

Saturday, August 4, 2012

Life as a test engineer (to make it look sophisticated a quality analyst)

Yes, I know the title of this post is a bit strange.
Anyways leaving the title to its own condition, let me write more about what is all the fuss about being tester or developer. To begin the with, the (Indian) IT industry having a glorious past, today has less projects which relate to development of new products or services. Support and maintenance is the flavor of the projects being executed today. For those development guys who I know are clenching their fists, would accept that today instead of development from scratch, there is more of customization work. Platforms have been built, the benchmarks have been set and the pseudo-code is already in place. Definitely this saves time but it can't be called development, rather I would call it customization.

Coming back to the title, the clients or users of products and services of these IT giants today are not only concerned with what technology or platform is being used to develop their products. They want reliable services, defect free products and failure-proof systems. This brings into picture the poor long-forgotten test engineer. Once a looked down upon member of the  team, the test engineer suddenly becomes an all-important member. The test team now works upon a test approach, makes estimates and writes all permutations and combinations of test cases to somehow make the product fail (and win brownie points from the management). But alas testing can never be complete. There is no 100% defect free product nor is their a 100% failure-proof service. More on about the job-profiles later on someday.

There are some benefits of being a test engineer/quality analyst. Firstly, you get to learn a lot in a shorter period of time. A analyst has a complete holistic overview as well as a deep understanding of the product/service (or as you might call it the project). Secondly, it is a bit more relaxed job as compared to developers. Yes, no need to read it the third time, it is more relaxed [PERIOD]. Thirdly, it opens up options for you to become a business analyst sooner than you developer friends :)

Yeah, this is not a complete post. I will be adding on more follow-up posts for this one. Take care.

Wednesday, June 27, 2012

What is missing in our computer science curriculum?

This is a nice article, i have abridged it from an existing blog I read somewhere else. I have added the link in this article.


It seems that universities fail to train students who can build good software. Most graduates know what inheritance and interface are, but few of them can properly choose and defend which to use. Most graduates have taken classes in “Operating Systems” and thus can talk a lot about threads and scheduling, but few actually have read books like the one from Doug Lea. They cannot be entrusted to write multi-threaded code. Most graduates memorize the visited nodes when writing a function to detect cycle in a linked list, but few of them are aware of Floyd’s cycle-finding algorithm. The funniest thing is that a lot of them think that they are writing object-oriented code because they have replaced ‘struct’ in C with ‘class’ in C++. They are yet to read a book on design pattern.
In other words, these graduates cannot use the programming languages effectively (ineffective). They cannot communicate their ideas to colleagues in their code (incomprehensible). They do not evaluate the space and time complexities of their algorithms (inefficient). They produce spaghetti code that is so difficult to modify (unmaintainable) so we have this motto in the industry: if it ain’t broke, don’t fix it. It is next to impossible to add new requirements without rewriting it from scratch (inextensible). Often when I do code review, the code looks like scribble to me. I have no way to tell whether it is right or wrong (incorrect).
I would like to point out that computer programming is a real professional that requires more than merely reading “C++/Java/C# for Dummies”. We need the programmers to know more than just the programming constructs and some irrelevant theories they never use on the job. Given a project, a competent programmer should be able to understand the problem, design efficient algorithms in terms of space and time complexities, evaluate different implementations, type in legible code, and provide systematic evidences that the code work. It is very unfortunate that universities fail to deliver students that qualify.
Why don’t universities produce good programmers? The major problem lies in the curriculum. Somehow the schools assume everyone can read the book such as “C++/Java/C# for Dummies” on their own. Consequently, most fresh graduates write dummy code.
Yes, we do programming projects for courses like Data structure, Operating System, Artificial Intelligence and etc. But these assignments aim to enhance the students’ knowledge in the particular topics. The code is never graded based on how professional it is written. Take Operating System as an example, the assignments aim to enhance the students’ knowledge on the concepts of thread and the OS scheduling algorithms but they are never designed to train students on writing good multi-threaded programs. The textbooks used in class teach about mutex and semaphore but they do not teach how to use them effectively. How many students, after taking an OS class, can design a thread-safe stack? I bet that most of them know what threads are and what a stack is, but few can design an efficient and effective thread-safe stack class.
The second problem is faculty. As a university the undergraduate courses are usually taught by newly graduated students. These students are trained to publish journal papers. Many never deliver any industrial applications in their life time (not hands-on anyway). Not only do they not know how to write good code, but they cannot appreciate how important it is to produce good code. For instance, in a Data Structure course, a professor teaches about stack, but he is unlikely to implement a thread-safe stack class for professional use. Without ever working in the industries, it is very difficult for a professor to understand the details and issues associated with using a thread-safe stack. It would even be more difficult for him to appreciate how important it is to provide systematic evidences to show that his class works and is ready for a third-party to use.
One may argue that “Computer Science” is about science so we study Artificial Intelligence, Operating System, etc. Science is about research and innovation. It is not about programming. My dilemma is that if we cannot go to computer science schools to seek qualified programmers, where should we turn to? Also, what exactly is the use of these university trained computer science graduates if they cannot write good code? After all, not everyone becomes a scientist. Most of them are engineers that code the science ideas into real products that benefit our societies.


Original Here:
http://numericalmethod.com/blog/2010/11/03/what-is-missing-in-our-computer-science-curriculum/

Sunday, June 24, 2012

Swapping the odd and even position in a linked list

A simple and intuitive solution to the problem !! It might not be very efficient but it does certainly work.


node* swap(node *head)
{
    node dummy;
    node *prev, *curr, *u, *tmp;

    if (head==NULL) return head;

    prev=&dummy;
    for(curr=head; curr!=NULL && curr->next!=NULL; ) {
        u = curr->next;
        tmp = u->next;
        prev->next = u;
        u->next = curr;
        prev = curr;
        curr = tmp;
    }
    prev->next = curr;
    return dummy.next;
}

void print(const node *head)
{
    for(const node *p=head; p; p=p->next)
        printf("%d ", p->val);
    putchar('\n');
}

Friday, June 22, 2012

Linked List Insert nth problem

A linked list problem for inserting a node after the nth index !!

InsertNth() Solution


void InsertNth(struct node** headRef, int index, int data)
if (index == 0)
   Push(headRef, data);                       // position 0 is a special case...
else {
  struct node* current = *headRef;
   int i;
     for (i=0; i<index-1; i++) {
     assert(current != NULL); // if this fails, index was too big
     current = current->next;
      }
Push(&(current->next), data);
}
}
Its been nearly 2 months now that I have shifted to Pune, and  I have pretty much enjoyed my stay till now. Accenture's a nice company to work for, and after few days of initial glitches all is well now. Although my work doesn't leave any free time during the day for me to blog, I'll try to keep this going on. BTW drop in queries if you have any about Accenture or IT industry or start ups ;)

Wednesday, December 7, 2011

Problem on Bit Manipulation


Write a function to determine the number of bits required to convert integer X to integer Y.
Input: 31, 14
Output: 2


This problem seems to be quite complex, however is actually rather simple. Think about finding out which bits in two numbers are different. Simple: with an XOR.
Each 1 in the XOR will represent one different bit between X and Y. Then we can simply count the number of bits that are 1.

 public static int swapRequired(int x, int y)
{
 int counter = 0;
 for (int z = x ^ y; z!= 0; z= z>>1) {
 counter += c & 1;
 }
 return counter;
 }

Monday, December 5, 2011

Reverse a Linked List

This question is one of the most repeated ones across Google, Microsoft, Amazon and a few more. The thing which makes it a good question is that after you scratch your head and give them an algorithm they either ask you to optimize it for the boundary cases (which is fine for most of the candidates) or they ask you to do it the other way round.

I am going to give you both, recursive as well as an iterative solution. For both the techniques :

Initially call the method as : head = reverseList(head,NULL)


Iterative :

Node *Reverse (Node *p)
{
   Node *pr = NULL;
   while (p != NULL)
   {
      Node *tmp = p->next;
      p->next = pr;
      pr = p;
      p = tmp;
   }
   return pr;
}
-----------------------------------------------------------------------
Recursive:

Node *reverseList(Node *current, Node *parent)
{
        Node *revHead;
   if(current == null)
      revHead = parent;
   else
   {
      revHead = reverseList(current->next,current);
      current->next = parent;      
   }
   return revHead;
}

Saturday, December 3, 2011

Easy-4


void main()
{
int *mptr, *cptr;
mptr = (int*)malloc(sizeof(int));                               //Output: some garbage values
printf(“%d”,*mptr);
int *cptr = (int*)calloc(sizeof(int),1);                      // Output=0
printf(“%d”,*cptr);
}

The above statements return garbage values and a zero in the next.
So much for understanding a small difference between malloc() and calloc().
See the differences in arguments and the returned values.

Friday, December 2, 2011

A few simple logical questions !


1.) 

Multiplying a number by 7 without using * and + operators.

NewNum = Num << 3;                      // multiplied by 2^3 = 8

NewNum = NewNum - Num;             // 8 – 1 = 7

2.)

Finding the last character of any String.
                              (OR)

Write a function that finds the last instance of a character in a string


char *lastChar(char *String, char ch)
{
char *cStr = NULL;


// traverse the entire string


while(*String ++ != NULL ) 
{
if(*String==ch) 
cStr = String;
}
return cStr;


Wednesday, November 30, 2011

C Output Type Question


main( )
{
static int a[ ] = {0,1,2,3,4};
int *p[ ] = {a,a+1,a+2,a+3,a+4};
int **ptr = p;
ptr++;
printf(“\n %d  %d  %d”, ptr-p, *ptr-a, **ptr);
*ptr++;
printf(“\n %d  %d  %d”, ptr-p, *ptr-a, **ptr);
*++ptr;
printf(“\n %d  %d  %d”, ptr-p, *ptr-a, **ptr);
++*ptr;
printf(“\n %d  %d  %d”, ptr-p, *ptr-a, **ptr);
}

Try to find the output !!
This question is seemingly quite unconventional, but try it out without using a compiler, and then compare your results with:


1 1 1
2 2 2
3 3 3
3 4 4

Tuesday, November 29, 2011

Brain-Teaser


Try this without googling the answer.. also please try to justify your assumptions if any ?

A party of four travelers comes to a rickety bridge at night. The bridge can hold the weight of at most two of the travelers at a time, and it cannot be crossed without using a flashlight. The travelers have one flashlight among them. Each traveler walks at a different speed: The first can cross the bridge in 1 minute, the second in 2 minutes, the third in 5 minutes, and the fourth takes 10 minutes to cross the bridge. If two travelers cross together, they walk at the speed of the slower traveler.

What is the least amount of time in which all the travelers can cross from one side of the bridge to the other?


Sunday, November 27, 2011

Acyclic Linked-List Detection Algorithm

Write a function that takes a pointer to the head of a list and determines whether the list is cyclic or acyclic. Your function should return false if the list is acyclic and true if it is cyclic. You may not modify the list in any way.

int determineTermination( node *head )
        { 
           node *fast, *slow;
           fast = slow = head; 
                  while( true )
                       {
                           if( !fast || !fast->next ) 
                              return false; 
                           else if( fast == slow || fast->next == slow ) 
                              return true; 
                           else 
                              {
                                 slow = slow->next; 
                                 fast = fast->next->next; 
                              }
                        }
        }


Leave your comments below the post.
Happy coding :)

Microsoft Moderate Programming Question

An important interview as well as optimised solution for finding the largest sub array sum in an array which may contain 0, positive and negative integers.


#include<stdio.h>
main()
{
int sumtillnow=0,sum=0,i=0;
int a[7]={-1,11,13,12,-90,23,5};
for(i=0;i<7;i++)
{
sumtillnow+=a[i];
if(sumtillnow>sum)
 sum=sumtillnow;
if(sumtillnow<0)
 sumtillnow=0;
 }
printf("%d",sum);
}

Saturday, November 26, 2011

One line of code for finding out whether a number is power of 2 or not

(An obnoxious looking piece of code) 

If the following LOC returns true, find out what is x here ?


if((x&&!(x&(x-1))==1)) 


Study the Bit-wise operators well, many problems and contests have questions which become quite easy if these are used !!
 The above code is a simple one line test for testing if a variable entered or passed is a power of 2.

Amazon easy simple output question


Another of internet giant Amazon's technical written test question. This question tries to make filter out candidates who have come to attend the examination after reading refreshers of C language. Delve into your K&R's to figure it out.

main()
{
printf("\nab");
printf("\bsi");
printf("\rha");
}

Hints:
\n - newline
\b - backspace
\r - linefeed
.
.
.
.
Solution coming soon !!

Strange are the ways of C


Have look at the following snippet, you can see 4 values that which will be printed for each iteration of the loop when you run it. Actually they all are just different ways of representing the same idea !! Try it out on www.codepad.org to see and believe !!

main()
{
char s[ ]="man";
int i;
for(i=0;s[i];i++)
printf("\n %c %c %c %c ", s[ i ] , *(s+i) , *(i+s) , i[s] );
}

So do you also want to become a good programmer someday ??

It is no secret that every programmer cherishes a dream of hitting the headlines of the for doing something really great. Although there are not many world famous programmers in this world, and the best ones rarely opt for a life in public. In most cases it is because of the nature of the work which forces them to hit their machines harder each passing day.
Believe me its no joke and neither it is a cakewalk to be successful as a programmer, because programming in the first place is not about learning programming languages, instead it is about the machine, logic and semantics. The code is just something which comes on in after the three have been developed. Choice of a particular language is purely something that is your own and u needn't be advised by anyone. Lastly, expecting overnight success just because you completed that Complete Reference or Bible of XYZ language is called stupidity and i pray to God that such people get some brains soon enough. Dear Reader, after reading the book you need to implement the constructs and syntax on your machine and some problems. Open up a few websites and blogs (like this one) and start to think about the solutions to them, and if you have done enough then start optimizing them or finding new methods to solve the same problem.
There are a few really great articles i would like you to refer :

1.  How to be a good programmer.
2.  How to be come a good programmer in.....

Print your Name without the semicolon in a C program

Okay.. this question used to be quite a favorite at coding championships 4-5 years back. The question seemed tough as all programming books start with the statement that "All statements in ' XYZ ' language end with a ( ; ) semicolon, except for a few conditional, looping and other control structure constructs. Actually the problem lies in the fact that we try to use standalone printf() statements in our solutions.
Here's a solution for it :

main()
{
 if(printf("MY NAME")) {}
 else {}
}

Ad Space