Tuesday, February 12, 2008

Let's Celebrate For A Little - 1K Visitors!

This is a special day for the Developer On Line-DOL- blog. Today the number of unique visitors on this blog reached more or less the astronomical amount of 1024! Before making a little fun a sincere thanks to everybody that has visited this page and specially to anybody that is subscribed on the blog's feeds. Now I think it is time to introduce better, but in short, the story behind this blog and prove why it should keep ...existing!

It started in early September with the first 'Hello World' post. Initially I planned to keep it strictly technical but it is not easy to resist broadening the subjects (sticking your nose everywhere is the right expression!). One thing I have kept is the blog being ad-free and I plan to keep it that way. It is nice to have a clean place for me to write and for you to read.

Trying to post original material is also in the 'routine'. The book stacking problem post is a good example on that. I won't say that everything here is 100% 'cotton' (this is your job!) but I confess having canceled posts that I found that had nothing new to add compared to other web sites. There is no meaning in reposting news, or republishing articles or code that is already there and is freely accessible.

Despite being around for almost 6 months, it is true that I have not been so productive. There are a total of 20 posts in this period that equal to less than 1 post per week. DOL promises to intensify the posting process and has already masterminded and executed the perfect business plan for that. I only have to wait for today's lottery and these six numbers to come up and I will be devoted in this blog for the rest of my life...!

Some statistics now. You may have noticed that this blog is using Google Analytics to measure blog traffic. It is an easy and nice way to keep track of how people find our page and how they navigate inside it. By understanding how people get to your page, you can increase blog traffic and although I do not earn money from this, it helps me in asserting the quality of the content. Here is some statistics of the countries that have visited this blog. US and Greece stands out, much ahead than other countries(UK, India etc) The main sources come from search engines in which DOL generally ranks pretty well.
DOL visitors in six months


Once again, thanks to everybody.

IMPORTANT:
PS. Now that DOL has this enormous influence, it officially endorses Barack Obama for President of the US!

If he loses, DOL invites him to Greece; we urgently need a Prime Minister and we desperately need change...

Tuesday, February 5, 2008

Google Interviews Part IV

This is the 3rd interview I had with Google. You can find the previous and the questions asked here:
* First Google interview
* Second interview

Update: Fourth Google Interview

In the 3rd interview I talked with a woman software engineer from Mountain View. As usually it lasted for about 45 minutes but there was a surprise waiting at the last question..But let's take things from the beginning.

The first question was a hard test for my memory: "How do you test your code?" This is a fair one for software engineers. But not for my style. I personally like things that are quick and dirty. For larger projects I use some of my own class libraries that employ some kind of logging, measure method execution time and so on. But saying "Well, I use my own class libraries." I thought would not be a good answer. Nor a professional one.

So talking about Java, I made the mistake of mentioning the JUnit framework. I had used for some time (long ago) but the time had passed so I had forgotten even the basics. And of course the interviewer started the questions (How the JUnit handles exception and others) To tell you a secret I had already opened in my browser a JUnit site (some kind of tutorial I guess) but this didn't help at all. So, don't do it. It will only make things worse. Trying to think logically didn't help either. The interviewer kept pushing, until I 'broke' and admitted that I couldn't answer. That was it. We moved to the next question.

All next questions were really typical, the kind you find in tech interview sites:
* "What is a Unix kernel?"
* "What is the difference between interfaces and abstractt classes?"
* "What is the difference between threads and processes?"
* "What is inheritance, polymorphism and encapsulation?"
* "What is overriding and what is overloading?"

I think there is no need to elaborate further on that. You most probably have come across these concepts and have your own mind.

Which brings us to the last question. Actually it was a puzzle including programming with handicaps, i.e. with small processor, low memory etc. The puzzle was this:
"You have 1000 integers. All are less than 1000 and greater or equal to 1. Among them, 999 are distinct and there is one that is found twice. How can you find the duplicate?" To this I gave an answer I think is optimal. The idea is simple. If you denote the duplicate number by d and the sum of all the integers by S then the following equation holds:
S-d= 499500 since S-d is the sum 1+2+3...+999 which is equal to 499500 by applying the formula 1+2+3...+n = n*(n+1)/2
Now the good thing is that we can be able to find the duplicate even we have capacity for one integer, or when reading from a stream and so on. We can optimize even if we apply modulus to the first equation: d = (S-500) (mod 1000) Now if d is equal to a positive number mod1000 then this is the duplicate, otherwise the duplicate is the negative part plus 1000. For example is 1 was the duplicate, then d=1(mod 1000) and the duplicate had to be the 1. If the duplicate was 600, then d=-400(mod 1000) so the duplicate had to be -400+1000=600. This means we do not need to have storage for integer (int type) but only the byte type is enough.

While fairly easy to grasp the interviewer had difficulties in understanding how this would work, so she asked for an example when we have 10 integers. I replied this would transform the equation to d =S-45 but then the counter question was disappointing: "How did you compute 45?" It is quite obvious however that I had to compute 1+2...+9 which is equal to 45 when applying the formula that Gauss found when he was 8. But the interviewer started computed 'by hand' the sum, adding the numbers from 1 up to 9, which left me speechless for some seconds. I mentioned that there was a formula for that but she didn't listen, still being concentrating on her computations. I didn't bother elaborating on the modulus idea since obviously would not give me any more credit.

After that, the interview had finished. I didn't ask anything, saying something like 'I have many questions but I do not wish to spend any more of your time' and we ended the conversation. In overall the last incident was really awkward. To that time I believed that all Google engineers had a good mathematical background. The engineer that I spoke with, did lack elementary skills. So in my eyes, the myth had been destroyed and it is a good advice to anybody, not bother berating himself more than he should. If you already knew the formula for the sum of consecutive integers, you have a good reason to feel more confident.

Update: Go to the last Google phone interview

Sunday, January 20, 2008

Google Interviews Part III

This continues from my first Google interview described here In overall, the second one was harder in terms of questions and expectations. I was called again from Mountain View sharply at the time we had arranged.

The conversation began with an interesting question: "What would you change in the Java programming language?" This has more than one questions embedded and it is educating listening to all possible answers. For example, one of my suggestions was having 'mechanisms' much like the properties fields in C# to ease development (programming get/set methods seems very tiring to me)Since the question was referring to the language and not to the Virtual Machine anything you find tiring or absent in Java is probably a valid answer.

We next proceeded to a C programming question. My interviewer knew that I was not a C-guru so he was gentle on that. The question was something like this. What is the output of this C program?
main() {
char X[500] = "Hello World";
printf("%s",X+5);
}

I knew it had to do something with memory allocation but I was not succinct on that. I said that the output would be blank and I guess I was right (the interviewers never tell you directly if you are right or wrong) So we said OK and moved on.

The 3rd question was about creating random functions. It is the type of questions where given a function randX that provides uniformly numbers from 1 to X, to generate a another randY. The actual question was about making rand8 from rand6. It is easy to establish how to get a rand2 from rand6. Then you can get rand8 from rand2.

This was a straightforward case. However, this problem appears very often in such situations and deserves some attention. You may find unlimited nonsense by searching for 'create rand7 from rand5' which is also a frequent question. Trying these forums/blogs etc you will get endless efforts of shifting from one rand to another using common arithmetic functions (addition, mod etc). This is nonsense. You will have to shift to elementary analysis for a while to get some good results.

In the general case consider you have to generate randX from randY where Y > X. Now consider that this yields the division: Y = n*X+r So, you can one group of Y elements into X groups of n elements and one more group with r elements. Now number the X groups as 1,2,3..X Then, create a 'machine' that uses the algorithm:
m = randY();
IF m belongs to one of the X groups return its number
ELSE restart the machine

The probability in every run of the algorithm to return one specific value from 1 to X is a =n/Y and the probability that the algorithm restarts is b = r/Y. So, the overall probability that the machine will output one number from 1 to X is :
P = a+a*b+a*b*b+a*b*b*b+... = a*(1+b+b*b+...) = a/(1-b).
By substitution we get, P = 1/X

In other words, we have generated the function randX
Now, if we wish to increase the rand range, for example get rand7 from rand5 you can create rand25 from rand5 (two rand5 calls) and then use the above method. Shifting to infinity is inevitable in some cases and all other efforts are in vain.

Back to the interviews, the final question had to do with designing and analyzing an algorithm. This had to calculate all representations of an integer as a sum of cubes. You can find many similar examples in algorithms textbooks so presenting this story here is trivial. What is interesting is that, we started a discussion on an incident that was directly related to the problem. This is usually called as the 'cab number story'. Back in the days when Ramanujan was in Cambridge and was working with G.H. Hardy, he had frequent health problems. One day, Hardy visited Ramanujan to the hospital and to start a discussion he mentioned the number of the taxi cab that brought him there. He said something like "..The cab number was 1729. I think this number is not interesting at all." A few seconds Ramanujan (which was extremely competent with numbers and calculations) replied: "You are not right Mr.Hardy. 1729 is very interesting. It is the smallest number that can be written as a sum of cubes in two different ways."

This was a nice way to close the interview. We didn't have much time left, so we said some relaxing things and then ended the interview conversation. All in all, it went well and my interviewer was a really nice person. Our discussion was interesting and I soon got the news that I was to pass to the next level. Having acquaintance with math and generally science history certainly helps!

Jump to the next Google interview.

Friday, January 18, 2008

Robert James Fischer-The King Is Dead (1943-2008)

I heard it a couple of minutes ago. Bobby Fischer died in a hospital of Reykjavik, Iceland, the very place where he became the king of chess players beating Spassky in the final match. This leaves a bitter taste to all chess fans, and more to Fischer fans like myself.

Child of divorced parents, he lived with his mom and older sister, which introduced Bobby to the game. He quickly left school and decided to be a professional chess player. At the age of 13 he played the 'Game of the Century' against D.Byrne, still considered as a masterpiece among chess enthusiasts (you don't see queen sacrifices very often)This was just the beginning and among other things Fischer became the holder of many best performance records in tournaments and matches escalating to being the World Chess Champion in 1972, at the heart of of Cold War, outperforming all Soviet chess stars. He was notorious for his passion to play each game to win.

Bobby Fischer disappeared soon after FIDE denied to accept his suggestions for changing World Chess Championship rules and refused to defend his title against Anatoly Karpov. This has been a mystery around the chess world until 1992 when Fischer re-appeared to the public and played against Spassky in Serbia (Former Yugoslavia). This had political interest since Serbia was under embargo from the US at the time. After that Fischer had to find a political asylum which he finally found in Iceland.

Bobby Fischer had early established the habit of dressing well and it is rumored he had a massive collection of shoes. Fischer himself describes that one comment after a chess tournament ('He may play well but he dresses like a homeless') is what triggered his behavior. All this have led many to call him 'arrogant' and 'self-centric'. At the last years of his life he has been accused of being racist and anti-semitic, things that he triggered himself after expressing strong anti-semitic opinions over the 9/11 incident on the radio.

One could write for days about Fischer's bad behavior but all this have little significance now. This has been a small tribute to Bobby Fischer who died today. His ingenuity has inspired a whole generation of chess players and his plays are of unmatchable beauty. In my eyes, he is the best chess player of all times. and beyond chess mastery one can discover lessons of life in his strategies: The first that comes to my mind: "No draws. Win or lose."

Monday, January 7, 2008

The Importance of Being Elegant

This is the solution to the the problem of the perfect logicians. You might find 'solutions' for this problem in the web that in essence by listing a large set of numbers and wiping out the 'impossible' ones to arrive at the desired result. Even this relevant Stanford page on the problem, refers to solutions you can hardly bear to look..

The beauty of the problem and of the solution, resides in the elegant modeling. To find the exact solution all you have to do is to feed it to a computer in a form of a computer program and collect the results. My own perspective of elegance is given below:



Making the software for this model is really straightforward. You will find out that the only solution is 4 and 13. You may even try an even larger numbers and find out that 4 and 13 are the only solutions for a large set.

I hope you enjoy this elegance in this as much as I have!

Thursday, January 3, 2008

Google Interviews Part II

The first Google interview is most likely the easiest one.
I have the feeling that they normally ask general questions, just to ensure that you have some knowledge of computers and you are not just the guy who believes he deserves a place in Google because he can make nice Powerpoint presentations. At least happened in my case.

A guy from Mountain View called me sharply at the time we had arranged. He called on my mobile. I had everything arranged: From the bluetooth hands-free to nice and clean desk in front of me. At first, he asked me some questions about my CV, my age and my education. He didn't seem so interested in that and my impression was that his questions were somewhat mechanical.

After a couple of minutes, he started asking technical questions. The first one was easy: If we would like to index the entire earth population, how long should the index size be? Although a piece of cake, I felt like I was asked to prove that P=NP. Soon, I panicked but I asked for some time to 'warm up'. The Google Engineer was kind enough to understand and gave me all the time I needed in order to finally realize that I was talking to Google and that I had to control myself.

After recovering and answering to this question, I was put in front of a puzzle involving buckets and I was asked to find an algorithm that would end up in a situation that one bucket would be empty, as soon as some conditions were met. Excuse me for this vague description but I am still not able to remember exactly what the problem was all about. Instead of trying to find some exact solution to a problem that I couldn't understand (perhaps I was very nervous or I didn't understand the language), I followed an old Harry Truman's quote: "If you cannot convince them, confuse them". This seemed to work extremely well. I soon said something about modelling the problem as a Diophantine equation, where the solutions in integers would mean filling if positive or emptying if negative. Of course I had no idea what I was talking about, but the Google Engineer fell into it. He was not familiar with the idea, we soon started talking until we had switched to a more theoretical conversation. This gave me time to think over the solution and present with a backtracking-type of algorithm. During all this, I was asked some algorithmic-theoretical questions, for example about hashing space and time complexity.

We spent a lot of time on this problem. The last one was around his own domain of expertise. It turned out that this guy was working on Google Book Search and asked what I would if I had to find duplicates in book catalogs with entries with different titles but with the same content.. I had no idea of the format, Google was using to index book entries, I asked some questions that clarified the problem to me and then I presented my solution. My idea was to use some basic format properties of book text, for example number of paragraphs, size of paragraphs and so on. This way a book named "Albert Camus-The Stranger" would match a book "Famous Authors-L'etranger" (the example might not be realistic but it gives the idea)

The 45 minute had finished and it was time to ask my own questions. I asked a couple of things (one being if book search is still beta to which the engineer falsely responded that it is not!)and some other lame how-wonderful-is-Google questions and we said goodbye.

The next day I was informed by my recruiter that I had done well we had to proceed to the next stage. Overall, the guy I talked was very kind and showed a lot of understanding when I was stuck in the first and simplest question. But now I had to prepare for the 2nd interview which my recruiter had informed me that would be much more technical...

Continue to the second interview

Wednesday, January 2, 2008

Netscape Navigator (1994-2008)

Netscape Navigator or simply Navigator is DEAD.
On December 28th 2007, AOL announced that will no longer support Navigator.
You can find the original announcement here. It has already been filled with comments.

Indeed, this is huge news. I mean, ok, we already knew that Netscape did have a tiny percent of Internet users, but it cannot be doubted that Netscape has been one if the most innovative software companies and that the Navigator is 'responsible' for the massive explosion of the Web. An amazing variety of technologies were first explored by Netscape: SSL and Javascript are some of them. One clue, it is top in the PC World's List of 50 best Tech Programs. In an era when only a few people were actually aware of the so-called World Wide Web, in a period during which even Microsoft was too busy with productivity software, actually overlooking Internet opportunities and considering it a 'fad', it was Netscape Communications that created the definition of the "killer app".

The actual story of Netscape is also fascinating (The great browser battle, Navigator vs. Explorer is now history), including stock gain records, mythical quarterly revenues, innovations, trials and many other leading to the decadence and death. You can find a very nice article here.