Archive
Google Unlocks it’s Server Design
Google revealed one of their server design. Google posses one of the most efficient, reliable and secure data centers and has revealed it’s server design to help increasing problems of huge Data Centers. For details please read the detailed article at here.
Top 10 Traits of a Rockstar Software Engineer
I came across this excellent post on ReadWriteWeb about 10 traits of a Rockstar Software Engineer and I could not agree more. In 10 traits every thing about a software engineer is sufficed. It is a true analysis of what a software engineer must equip of. The traits are,
- Loves To Code
- Gets Things Done
- Continuously Refactors Code
- Uses Design Patterns
- Writes Tests
- Leverages Existing Code
- Focuses on Usability
- Writes Maintainable Code
- Can Code in Any Language
- Knows Basic Computer Science
Read them, analyze them and if you are a software engineer find how many you have from these. For more details read the complete post with description of each trait at here.
Demo – The Sixth Sense
TED continues to prove to be the best meeting place for innovators and geniuses. Here is another brilliant video on Sixth Sense. Well though naming it sixth sense sounds a bit odd but video is superb!
Wonderful posts at TED
Today I am going to write about three wonderful talks on TED (Technology, Entertainment, Design).
Number 1: Bill Gates unplugged at here on solving biggest problems of world and these are not technical btw
.
Number 2: Barry Schwartz’ passionate plea for practical wisdom, a standing ovation talk best in 2009.
Number 3: Technological wonderous
in nature. Digital blocks with computational ability. MIT grad student David Merrill demos Siftables — cookie-sized, computerized tiles at here.
The last one is specially awesome to watch.
Find the complexity of code.
I came across measuring complexity of a piece of code, which is really tricky one. Following is the code,
void function( int n)
{
while(n > 1)
n = sqrt (n); // assume sqrt returns square root of any number and ignore the complexity of square root
}
If any one wants to try this do try
and post your answers.
World’s Largest Semantic Web announced – Web 3.0 Insight
Cognition Technologies a Semantic Web company (wow Aleem Khan just think a ‘Semantic Web’ company – for those of you who don’t know Semantic Web was our final year project) is announcing the largest Semantic Map of English language. In simple words, they will be “enabling” search engines to understand what we have typed in the search box and retrieve contextually correct results.
The company is also going to fulfill one of my ambitions (to build a Semantic Web – Web 3.0 based search engine). So this is going to be advent of Web 3.0 hopefully.
References: ReadWriteWb.com on Cognition Technologies
To view Semantic Web already in action check out: Cognitive Wikipedia
Just Another Programming Puzzle (Finding one non repeating element in list of pairs)
So here is a programming question once again,
Consider a list of unsorted positive numbers in which each number has a pair except one of the number, the problem is to find that number in minimum complexity with O(1) extra space. The complexity in this case should not be more than O(n).
For instance, in the list {5,7,4,9,5,7,4} the answer should be 9. I will post my solution in the comments some time later.
Try your coding skills !
Here is a small C/C++ code snippet,
int n = 20;
for( int i = 0; i < n ; i—) // i minus minus(in case of typo)
printf(“Hello World!”) ;
First try to find the answer to this program. It will obviously be an infinite loop or memory over flow or …
The question is to make this snippet work and print the “Hello World!” 20 times correctly as if the statement i— would have been i++.
The restriction however is to change only one ASCII character in this code. This means you can change, replace, move, introduce only one character to this program and the program still remains a valid C/C++ code.
There are three possible ways I know to do this. May be there are more. If you find two then you are good, if three you are brilliant and if more than extraordinary
Have happy time solving this.
Measuring Complexity of an Executable!
For the time being, I have an interesting question to share rather ask
When ever we do the Asymptotic Analysis, we are given the source code or algorithm of a problem and we measure the run time complexity in terms of Big O, Big Omega etc…by doing the line to line analysis of the code.
Now the question is, lets say we are given an executable containing the code of a given problem (lets assume a sorting or searching algorithm), now how will we find the complexity of the executable i.e the asymptotic complexity? means is it taking linear, quadratic or exponential time etc…
Do try to think on this, it’s small but interesting question..
C Traps and Pitfalls !
I still believe that C was/is my oldest and first love
. And when I read this paper C Traps and Pitfalls By: Andrew Koenig of AT&T Bell Laboratories, this love was even consolidated
. Specially the function call (*(void(*)())0)(); really made me believe that, “C makes it easy to shoot yourself in the foot. C++ makes it harder, but when you do, it blows your whole leg”.
For the curious readers the hint is enough that this is the function call to a function whose address is stored at 0(zero) location, rest of the details can be read in the beautiful article that I mentioned earlier.
Difference between two strings – Levenshtein Algorithm
So now after a long time, I am going to write about an algorithm which I recently read, and found it very useful.
This algorithm is about, how different two strings are, and how many minimum operations are required to convert smaller string in length to larger (if their lengths are different). If the two string are of equal length then the number of charcaters that differ in two strings is the difference of strings. For example, in ‘computer’ and ‘computes’ the difference is 1 and in ‘test’ and ‘goat’ the difference is 3. Such distance is called as Hamming distance or edit distance simply put.
However if the strings are different in length then we use Levenshtein Algorithm or edit distance. Which works as follows.
For the two strings s1(cat) and s2(cots) of lengths m(3) and n(4), make an array of n*m and fill the each cell in 0th row with it’s corresponding column number and each cell in 0th column with it’s corresponding row number so our array ‘D’ will look like,
0 1 2 3
1
2
3
4
After this we compute a value in ‘temp’ which is 0 if s1[i] = s1[j] and 1 otherwise. And then find the minimum of D[i-1][j] + 1, D[i][j-1] +1 and D[i-1][j-1] + cost and assign it to D[i][j], where ‘i’ and ‘j’ are indeces while we compute. When we fill this array the last value in D[n][m] will give you the minimum number of moves required to convert str1(smaller) into str2(larger).
Here D[i-1][j] + 1, tell us if it is selected that we have to insert value in str1, if we select D[i][j-1] + 1 then we have to delete from str2 and if D[i-1][j-1] + cost is selected then we have to substitue in str1.
This is an interesting algorithm to try and then code, and is useful to find closest matches for a string and then can be used in many applications.
Interop – Managed C++ and C#
I mentioned about writing some basic stuff for Managed C++ so here I am writing it.
I had to send C# strings to Managed C++ dll(class library). In MC++ the managed reference is represented by ‘^’, in MC++ function’s prototype will be;
String^ foo(String ^ pInputString);
and call from C# will be normal like, Console.WriteLine(foo(str));
for sending array of strings;
void foo(array<String ^>^ pInputAStrings); // yeah looks weird
for sending a string as reference;
void foo(String ^ % pInputRString);
Similarly XmlDocument xdoc = new XmlDocument(); in C# is equivalent to
XmlDocument ^ xdoc = gcnew XmlDocument(); when we initiliaze with ‘gcnew’ the garbage collector will run even if we have enabled mixed types option in Managed C++ in .NET 2005.
The magical API that helped me through out is,
Marshal.Copy Method (IntPtr, Byte[], Int32, Int32) which have a total of 16 overloads and is in,
Namespace: System.Runtime.InteropServices
Assembly: mscorlib (in mscorlib.dll)
So using this method I convert a Base 64 Encoded string in bytes to native char * as follows.
array<Byte> ^ byteConvertedFromBase64 = nullptr;
String ^ string64bit = String::Empty;
byteConvertedFromBase64 = Convert::FromBase64String( string64bit );
char * bData = 0;
bData = new char[length];
Marshal::Copy(byteConvertedFromBase64, 0, IntPtr(bData), length);
It is a magical API which always worked when ever I needed to convert types from native char * to strings and vice versa and with other types.
Besides that I had to suppress the security checks that are incurred when calling native dlls from managed code, to save performance losses using PInvoke or COM Interop. This is done by SuppressUnmanagedCodeSecurityAttribute Class and applying /CLRUNMANAGEDCODECHECK in the linker settings. You can view MSDN for specific details.
Finding or detecting a loop/cycle in Link List.
One of famous questions asked in programming technical interviews is “Finding a loop in a linear linked list”. Apparently this problem is easy, but if one has interest in Algorithms and Complexity Theory this is a very interesting problem also related to number theory.
The most famous method to solve this problem is to use Floyd’s algorithm to find cycle in lists also known as “The Hare and the Tortoise Algorithm”, intersting
. If a list has a cycle in it, it can be detected using this algorithm. This algorithm can also be used to find cycles in “Pseudo-Random Sequences”. The algorithm to find the cycle in linked list is as follows.
Take two pointers pointing to head. Now advance one pointer to one node and other pointer to two nodes each time while iterating. This is the simple algorithm, and that’s it. If the first pointer enters the loop (cycle part of algorithm) it is guaranteed that the second pointer will be at some node in the loop at the same time when other pointer is pointing to same node. The result may come out by some iteration, but it’s assured. That’s because one pointer is iterating each node in loop and other is iterating alternating nodes, so at first or second iteration while in the loop it will catch the first pointer at same node. This is indeed a very good find. I tried this with moving the second pointer to three nodes at one time and it worked also though I had to iterate many times. By using this approach we can also find the number of nodes in the loop which is an interesting thing to try.
My Google Interviews.
In March and April 2006 I had good fortune to talk with Google Inc.’s folks and gave them phone interviews. I will soon write the synopsis of interviews as I have been planning to do so from a long time. I actually talked with a recruiter, had one pre-phone interview screen and 2 phone screens from USA and India. So I will write my experience with Google soon. Stay tuned.
WinFS will not be shipped seperately.
WinFS which was initially planned to be part of Windows Vista along with Avalon ( Windows Presentation Foundation) and Indigo ( Windows Communication Foundation) as the new file system, promising new innovation and taking file system architecture to extremes will now not be shipped seperately. It will be part of SQL and ADO.NET in Orcas may be. This is a very strange news from Microsoft. WinFS was the most anticipated part of Windows Vista and was considered to be a mile stone. Any ways for further details check out the WinFS official blog site.
Haroon


