Have you ever wondered where are all those brain teasing ,programming interview questions coming from? You can find them gathered and published in at least a dozen of web sites and books. You read the book before the interview and try to memorize, ideally understand the answers. Then when the interview is over, you forget them.
I was curious where are any of those problems used in practice. I mean, there must be some application. For example, take the short formula (n&(n-1)) ==0, where do you ever need to determine if a number is a power of 2? Of course, since computers are using binary arithmetics, you would think this has many application. I tried googling and I could not find any. I found out about perfect numbers http://mathforum.org/dr.math/faq/faq.perfect.html that are computed based on but I don't think you need to verify if a number is a power of 2 there.
Finding a missing integer in an array of consecutive integers has a simple solution using bit manipulation. I was able to find one application thanks to this site: http://blogs.oracle.com/malkit/entry/finding_missing_value
and after reading it, I got the idea of another application: to find a missing packet in a sequence of received packets, where each one has a sequence number (like in TCP protocol).
No comments:
Post a Comment