TCP/IP Stack Work: Connection But No Internet

Has it sometimes happened to you that you try to connect to a site, get an unable-to-load message and after checking everything, still end up with the same problem?

If the ans is yes, then welcome to the club! 🙂 The above particular problem happened to me when I had gone to Noida for Formula 1 and was staying over at my cousin’s place.

Now they have amazing net! My uncle is an engineer by profession and a Techno-freak by obsession. That’s what led him to install an unlimited 4 Mbps plan in his house, just so he could enjoy the full freedom of  the World Wide Web (He’s also a Mac user, if you were wondering).

So there I am, trying in vain to connect to the net so I can get some work done, but pages are unable to load. My connection status is showing connected, net is working on my cousin’s machine, Chrome AND Firefox have the same problem, rebooting doesn’t do a darn thing! What in the world is going on??

And so I did what any self-respecting computer engineer would do: I asked Google.

Turns out, my TCP/IP stack was garbled up and resetting it would be the ideal solution. Thankfully, there is no data loss of any kind in this process as you are just resetting the protocols that deal with Computer Networks rather than the data being transmitted. 😀

These are the commands I used: netsh int ip reset C:\netsh.log.txt
                                                                   netsh winsock reset 

This uses a tool called Network Shell available in Windows (if this was Linux, I wouldn’t be having this problem in the first place :-P) and it simply resets the TCP/IP stack using the netsh.log file as a reference and then resets the WinSock API so that the Windows Programs continue working normally with the reset. Consider the second line as telling Windows that “Hey, I just reset the TCP/IP stack, so you better make sure you are compatible as well”.

And there you go! Problem solved. A similar trick in Linux is to use the following command in a terminal: service networking restart

Eviva!

Probabilistic Analysis of Algorithms

Probability Theory has always been one area of study that has made more than its fair share of students cringe. However, its importance in the field of Computer Science, especially Algorithm Design and Artificial Intelligence cannot be emphasized enough.

Here’s a question I recently encountered as part of my selection process as an Intern for Microsoft: Consider Randomized QuickSort for a set of ‘n’ numbers. What is the probability that we always get the worst-case scenario for this algorithm?

Now you may want to try this on your own first as it is deceptively simple.

Here’s the solution: By the analysis and design of QuickSort, we get the worst-case scenario when we select either the least or greatest element in the array of n numbers, as the pivot. Thus the probability for n numbers is 2/n. Now we take the remaining n-1 numbers (Divide and Conquer) and similarly the worst-case is obtained when we select the first or last element. Thus the new probability is 2/(n-1). This continues on until we have just 2 elements left, which then gives the probability of 2/2.

Here’s the smart part: When we analyze Randomized QuickSort, we notice that the selection of the pivot in the recurrence is independent of the pivot selection in the outer equation. Thus, since the probabilities are independent, we can multiply all our earlier probabilities to give us [ 2/n * 2/(n-1) * 2/(n-2) *…* 2/2 ] = [ 2^(n-1)/n! ] (The n-1 as we have n-1 2s in the numerator) .

And thus we have the answer!! Pretty simple, huh? All we needed to know was what is the worst-case criteria for QuickSort and that pivot selection is independent of the pivot selection in the recurrence.

Similarly, probability theory plays a big part in Bayes Networks, which are essentially Probability Distributions in a graph, which is a core topic in AI. Knowing about total probability, Joint Probability and Bayes Rule really helps in the inference of Bayes Nets. Combine that with Variable Independence, Explaining Away Effect and Enumeration and you’ve got yourself a Smart System.

Just because all this seems simple, doesn’t necessarily mean Probability theory is simple. It does tend to get a tad bit confusing at times, but with ample practice, one should find himself/herself being able to predict the future!

Eviva!