<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-20767463</id><updated>2011-11-26T22:16:45.050+05:30</updated><category term='C++'/><category term='C#'/><category term='Python'/><category term='VS 2008'/><category term='Code'/><category term='Life'/><category term='Linux'/><category term='TopCoder'/><category term='Random Thoughts'/><category term='Misc'/><category term='Syntax Highlighter'/><category term='VIM'/><category term='Bash'/><category term='Windows'/><category term='First Blog'/><category term='Algorithms'/><category term='IM'/><title type='text'>Elixir of Life</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>65</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-20767463.post-6311634028449665266</id><published>2009-09-25T20:38:00.002+05:30</published><updated>2009-09-25T20:42:14.806+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='TopCoder'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>HowEasy - Topcoder Arena</title><content type='html'>Problem Statement :&lt;br /&gt;&lt;br /&gt;Problem Statement&lt;br /&gt;    &lt;br /&gt;***Note:  Please keep programs under 7000 characters in length.  Thank you&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Class Name: HowEasy&lt;br /&gt;Method Name: pointVal&lt;br /&gt;Parameters: String&lt;br /&gt;Returns: int&lt;br /&gt; &lt;br /&gt;TopCoder has decided to automate the process of assigning problem difficulty&lt;br /&gt;levels to problems.  TopCoder developers have concluded that problem difficulty&lt;br /&gt;is related only to the Average Word Length of Words in the problem statement:&lt;br /&gt;&lt;br /&gt;If the Average Word Length is less than or equal to 3,  the problem is a 250&lt;br /&gt;point problem.&lt;br /&gt;If the Average Word Length is equal to 4 or 5, the problem is a 500 point&lt;br /&gt;problem.&lt;br /&gt;If the Average Word Length is greater than or equal to 6, the problem is a 1000&lt;br /&gt;point problem.&lt;br /&gt; &lt;br /&gt;Definitions:&lt;br /&gt;Token - a set of characters bound on either side by spaces, the beginning of&lt;br /&gt;the input String parameter or the end of the input String parameter.&lt;br /&gt;Word - a Token that contains only letters (a-z or A-Z) and may end with a&lt;br /&gt;single period. A Word must have at least one letter.&lt;br /&gt;Word Length - the number of letters in a Word. (NOTE: a period is NOT a letter)&lt;br /&gt;&lt;br /&gt;The following are Words :&lt;br /&gt;"ab",  "ab."&lt;br /&gt;&lt;br /&gt;The following are not Words :&lt;br /&gt;"ab..", "a.b", ".ab", "a.b.", "a2b.", "."&lt;br /&gt;&lt;br /&gt;Average Word Length - the sum of the Word Lengths of every Word in the problem&lt;br /&gt;statement divided by the number of Words in the problem statement.  The&lt;br /&gt;division is integer division. If the number of Words is 0, the Average Word&lt;br /&gt;Length is 0.&lt;br /&gt; &lt;br /&gt;Implement a class HowEasy, which contains a method pointVal.  The method takes&lt;br /&gt;a String as a parameter that is the problem statement and returns an int that&lt;br /&gt;is the point value of the problem (250, 500, or 1000). The problem statement&lt;br /&gt;should be processed from left to right.&lt;br /&gt; &lt;br /&gt;Here is the method signature (be sure your method is public):&lt;br /&gt;int pointVal(String problemStatement);&lt;br /&gt; &lt;br /&gt;problemStatement is a String containing between 1 and 50 letters, numbers,&lt;br /&gt;spaces, or periods.  TopCoder will ensure the input is valid.&lt;br /&gt; &lt;br /&gt;Examples:&lt;br /&gt; &lt;br /&gt;If problemStatement="This is a problem statement", the Average Word Length is&lt;br /&gt;23/5=4, so the method should return 500.&lt;br /&gt;If problemStatement="523hi.", there are no Words, so the Average Word Length is&lt;br /&gt;0, and the method should return 250.&lt;br /&gt;If problemStatement="Implement a class H5 which contains some method." the&lt;br /&gt;Average Word Length is 38/7=5 and the method should return 500.&lt;br /&gt;If problemStatement=" no9 . wor7ds he8re. hj.." the Average Word Length is 0,&lt;br /&gt;and the method should return 250.&lt;br /&gt;Definition&lt;br /&gt;    &lt;br /&gt;Class: HowEasy&lt;br /&gt;Method: pointVal&lt;br /&gt;Parameters: string&lt;br /&gt;Returns: int&lt;br /&gt;Method signature: int pointVal(string param0)&lt;br /&gt;(be sure your method is public)&lt;br /&gt;   &lt;br /&gt;&lt;pre class="c++" name="code"&gt;&lt;br /&gt;#include &lt;iostream&gt;&lt;br /&gt;#include &lt;sstream&gt;&lt;br /&gt;#include &lt;string&gt;&lt;br /&gt;&lt;br /&gt;const static &lt;br /&gt;std::string g_LegalCharacters =  "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";&lt;br /&gt;&lt;br /&gt;class HowEasy&lt;br /&gt;{&lt;br /&gt;    public:&lt;br /&gt;        int pointVal(std::string problemStmt);&lt;br /&gt;&lt;br /&gt;    private:&lt;br /&gt;        inline bool isValid(std::string &amp;token);&lt;br /&gt;        inline int problemValue (unsigned int length);&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;bool HowEasy::isValid(std::string &amp;token)&lt;br /&gt;{&lt;br /&gt;    if (token.empty()) return 0;&lt;br /&gt;&lt;br /&gt;    size_t pos = token.find_first_not_of(g_LegalCharacters);&lt;br /&gt;    return (pos == std::string::npos);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int HowEasy::pointVal(std::string problemStmt)&lt;br /&gt;{&lt;br /&gt;    std::istringstream iss;&lt;br /&gt;    iss.str( problemStmt );&lt;br /&gt;&lt;br /&gt;    std::string token;&lt;br /&gt;    unsigned int nWords = 0;&lt;br /&gt;    unsigned int lWords = 0;&lt;br /&gt;    unsigned int average = 0;&lt;br /&gt;    int points = 0;&lt;br /&gt;    std::string validString;&lt;br /&gt;    while (!iss.eof())&lt;br /&gt;    {&lt;br /&gt;        iss &gt;&gt; token;&lt;br /&gt;        if (token.length())&lt;br /&gt;        {&lt;br /&gt;            if (token[token.length() - 1] == '.')&lt;br /&gt;                token.erase(token.end() - 1);&lt;br /&gt;&lt;br /&gt;            if (isValid(token))&lt;br /&gt;            {&lt;br /&gt;                ++nWords;&lt;br /&gt;                lWords += token.length();&lt;br /&gt;                validString += token;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    if (lWords &amp;&amp; nWords)&lt;br /&gt;        average = lWords / nWords;&lt;br /&gt;        &lt;br /&gt;    points =  problemValue (average);        &lt;br /&gt; return points;    &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int HowEasy::problemValue (unsigned int length)&lt;br /&gt;{&lt;br /&gt;    if (length &lt;= 3)&lt;br /&gt;        return 250;&lt;br /&gt;    else if (length &lt;= 5)&lt;br /&gt;        return 500;&lt;br /&gt;    else&lt;br /&gt;        return 1000;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Happy Hacking  :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-6311634028449665266?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/6311634028449665266/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2009/09/howeasy-topcoder-arena.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/6311634028449665266'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/6311634028449665266'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2009/09/howeasy-topcoder-arena.html' title='HowEasy - Topcoder Arena'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-8589312443649956923</id><published>2009-09-09T09:54:00.002+05:30</published><updated>2009-09-09T10:01:07.095+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Compare Vector V1 and V2 for equality</title><content type='html'>Here are the ways to compare two vectors.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Method 1:&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="c++" name="code"&gt;&lt;br /&gt;#include &lt; iostream &gt;&lt;br /&gt;using std::cout;&lt;br /&gt;using std::endl;&lt;br /&gt;&lt;br /&gt;#include &lt; algorithm &gt;&lt;br /&gt;#include &lt; vector &gt;&lt;br /&gt;#include &lt; iterator &gt;&lt;br /&gt;&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;   int a1[ 10 ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };&lt;br /&gt;   int a2[ 10 ] = { 1, 2, 3, 4, 9, 6, 7, 8, 9, 10 };&lt;br /&gt;   std::vector&lt;&gt; v1( a1, a1 + 10 );&lt;br /&gt;   std::vector&lt;&gt; v2( a1, a1 + 10 );&lt;br /&gt;   std::vector&lt;&gt; v3( a2, a2 + 10 );&lt;br /&gt;   std::ostream_iterator&lt;&gt; output( cout, " " );&lt;br /&gt;&lt;br /&gt;   cout &lt;&lt; "Vector v1 contains: ";    &lt;br /&gt;   std::copy( v1.begin(), v1.end(), output );    &lt;br /&gt;   cout &lt;&lt; "\nVector v2 contains: ";&lt;br /&gt;   std::copy( v2.begin(), v2.end(), output );&lt;br /&gt;   cout &lt;&lt; "\nVector v3 contains: ";&lt;br /&gt;   std::copy( v3.begin(), v3.end(), output );&lt;br /&gt;&lt;br /&gt;   // compare vectors v1 and v2 for equality    &lt;br /&gt;   bool result = std::equal( v1.begin(), v1.end(), v2.begin() );    &lt;br /&gt;   cout &lt;&lt; "\n\nVector v1 " &lt;&lt; ( result ? "is" : "is not" )  &lt;&lt; " equal to vector v2.\n";     &lt;br /&gt;   return 0; &lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Method 2:&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Overload the == operator for comparision&lt;br /&gt;&lt;br /&gt;&lt;pre class="c++" name="code"&gt;&lt;br /&gt;&lt;br /&gt;inline bool operator == (const std::vector&lt; std::string &gt;, const std::vector&lt; std::string &gt;)&lt;br /&gt;{&lt;br /&gt;    if (lhs.size() != rhs.size())&lt;br /&gt;        return false;&lt;br /&gt;&lt;br /&gt;    int count = lhs.size();&lt;br /&gt;    std::vector&lt; std::string &gt;::const_iterator lhsi = lhs.begin();&lt;br /&gt;    std::vector&lt; std::string &gt;::const_iterator rhsi = rhs.begin();&lt;br /&gt;    while (count--)&lt;br /&gt;    {&lt;br /&gt;        if ( *lhsi != *rhsi)&lt;br /&gt;            return false;&lt;br /&gt;        lhsi++; rhsi++;&lt;br /&gt;    }&lt;br /&gt;    return true;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-8589312443649956923?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/8589312443649956923/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2009/09/compare-vector-v1-and-v2-for-equality.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/8589312443649956923'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/8589312443649956923'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2009/09/compare-vector-v1-and-v2-for-equality.html' title='Compare Vector V1 and V2 for equality'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-2301123040952564605</id><published>2009-07-27T20:14:00.003+05:30</published><updated>2009-07-27T20:20:28.651+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Code'/><category scheme='http://www.blogger.com/atom/ns#' term='Bash'/><title type='text'>Convert "man page" into text file</title><content type='html'>Save a man page into text file&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Option #1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="Bash"&gt;&lt;br /&gt;&lt;br /&gt;man -P cat ls &gt; man_ls.txt&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Option #2:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="Bash"&gt;&lt;br /&gt;&lt;br /&gt;man ls | col -b &gt; ls.txt&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-2301123040952564605?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/2301123040952564605/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2009/07/convert-man-page-into-text-file.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/2301123040952564605'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/2301123040952564605'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2009/07/convert-man-page-into-text-file.html' title='Convert &quot;man page&quot; into text file'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-5634689696551402273</id><published>2009-07-15T09:48:00.004+05:30</published><updated>2009-07-15T14:38:49.303+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='Code'/><title type='text'>First try in C#</title><content type='html'>Here is my first try in C#&lt;br /&gt;&lt;br /&gt;&lt;pre class="c#" name="code"&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Collections.Generic;&lt;br /&gt;using System.Linq;&lt;br /&gt;using System.Text;&lt;br /&gt;&lt;br /&gt;namespace dotNet&lt;br /&gt;{&lt;br /&gt;    class Greeting&lt;br /&gt;    {&lt;br /&gt;        public static int displayGanesh()&lt;br /&gt;        {&lt;br /&gt;            Console.WriteLine("Ganesh Here !!");&lt;br /&gt;            return 0;&lt;br /&gt;        }&lt;br /&gt;        public static int displayVishnu()&lt;br /&gt;        {&lt;br /&gt;            Console.WriteLine("Vishnu Here !!");&lt;br /&gt;            return 1;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    delegate int delGreetings();&lt;br /&gt;&lt;br /&gt;    class Program&lt;br /&gt;    {&lt;br /&gt;        static void Main(string[] args)&lt;br /&gt;        {&lt;br /&gt;            int choice = 1;&lt;br /&gt;            delGreetings[] Greetings =&lt;br /&gt;            {&lt;br /&gt;              new delGreetings(Greeting.displayGanesh),&lt;br /&gt;              new delGreetings(Greeting.displayVishnu)&lt;br /&gt;            };&lt;br /&gt;            int return_ = Greetings[choice - 1]();&lt;br /&gt;            Console.Write("Return Value ");&lt;br /&gt;            Console.WriteLine(return_);&lt;br /&gt;            return;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;delegate is basically defines the function pointer. &lt;br /&gt;In the below snippet, it defines a function pointer which&lt;br /&gt;takes no arguments and returns an int value.&lt;br /&gt;&lt;br /&gt;&lt;pre class="c#" name="code"&gt;&lt;br /&gt;delegate int delGreetings();&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Happy Hacking !!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-5634689696551402273?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/5634689696551402273/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2009/07/first-try-in-c.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/5634689696551402273'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/5634689696551402273'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2009/07/first-try-in-c.html' title='First try in C#'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-527076395509532991</id><published>2009-07-14T21:49:00.003+05:30</published><updated>2009-07-14T22:06:09.007+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Windows'/><category scheme='http://www.blogger.com/atom/ns#' term='VS 2008'/><title type='text'>Visual Studio .Net 2008 Cheat sheet</title><content type='html'>For all the C# fans out there, today I came across this excellent &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=e5f902a8-5bb5-4cc6-907e-472809749973&amp;amp;displaylang=en"&gt;keyboard cheat sheet&lt;/a&gt; and &lt;a href="http://www.codinghorror.com/blog/archives/000412.html"&gt;Jeff's Summary Macro&lt;/a&gt; to generate the full list of VS 2008 cheat sheet in HTML format.&lt;br /&gt;&lt;br /&gt;Here is the steps to generate the cheatsheet for yourself. Skip to down under if you wish to get the generated cheatsheet.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.codinghorror.com/blog/files/keyboard-shortcut-list-macro-2.zip"&gt;Download the Keyboard shortcut Summary macro&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;How to install and run the macro ??&lt;br /&gt;&lt;ol&gt;&lt;li&gt;go to Tools - Macros - IDE&lt;/li&gt;&lt;li&gt;Create a new Module named "KeyboardShortcuts" under "MyMacros"&lt;/li&gt;&lt;li&gt;Paste the above code into the module&lt;/li&gt;&lt;li&gt;Add a reference to the  System.Data.dll and System.XML.dll ; make sure it builds with no errors&lt;/li&gt;&lt;li&gt;Close the macro IDE window&lt;/li&gt;&lt;li&gt;go to Tools - Macros - Macro Explorer&lt;/li&gt;&lt;li&gt;A new macro named "List" will be under "KeyboardShortcuts." Double-click it to run the macro&lt;/li&gt;&lt;li&gt;The macro will take a moment to write the keyboard shortcuts to a HTML file, then open the HTML file in the IDE.&lt;/li&gt;&lt;/ol&gt;This is tested against VS 2008 and the macro generates the HTML file :&lt;br /&gt;&lt;br /&gt;C:\Users\mganesh\Documents\Visual Studio .NET 20xx Keyboard Shortcuts.htm&lt;br /&gt;&lt;br /&gt;This is the file location in my Win 7 OS.&lt;br /&gt;&lt;br /&gt;The cheat sheet result for the Visual Studio 2008 default C# keyboard shortcuts is posted to save people the trouble of getting the macro running. It's &lt;a href="http://nerdfortress.s3.amazonaws.com/visual-studio-2008-keyboard-shortcuts.html"&gt;here&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-527076395509532991?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/527076395509532991/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2009/07/visual-studio-net-2008-cheat-sheet.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/527076395509532991'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/527076395509532991'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2009/07/visual-studio-net-2008-cheat-sheet.html' title='Visual Studio .Net 2008 Cheat sheet'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-9155449833075477126</id><published>2009-06-29T19:51:00.003+05:30</published><updated>2009-06-29T20:53:21.125+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Building Boost Lib 1.35 with VC++ 2008</title><content type='html'>Version 1.35 of the Boost libraries was released on March 29th, 2008.&lt;br /&gt;&lt;br /&gt;Below are the steps I followed to have everything working on Win 7.&lt;br /&gt;&lt;br /&gt;If not already done, install the following development tools (in the prescribed order, please):&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.microsoft.com/express/vc/"&gt;Visual C++ 2008 Express Edition&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=E6E1C3DF-A74F-4207-8586-711EBE331CDC&amp;amp;displaylang=en"&gt;Microsoft Windows SDK&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=d8462378-2f68-409d-9cb3-02312bc23bfd&amp;amp;displaylang=en"&gt;Microsoft Compute Cluster Pack SDK&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The last one will only be needed if you plan to compile the Boost.MPI library.&lt;br /&gt;&lt;br /&gt;Download and install Python. Download Boost 1.35 and the latest Boost Jam binary (3.1.17 at the time of this writing). Copy the bjam executable to the Boost root directory. Next, disable the automatic linking features of the Microsoft Visual C++ compiler by enabling the BOOST_ALL_NO_LIB macro on the file user.hpp (boost/config/user.hpp). We’re ready to go (type all the commands inside the Visual Studio 2008 Command Prompt):&lt;br /&gt;&lt;br /&gt;“&lt;span style="color:#000099;"&gt;bjam stage&lt;/span&gt;”&lt;br /&gt;&lt;br /&gt;Boost Jam auto detects the Visual C++ 2008 compiler!&lt;br /&gt;&lt;br /&gt;If you want to compile the Boost.MPI library a couple of additional steps must be followed. Boost Jam is your friend as it prints it nicely for you:&lt;br /&gt;&lt;br /&gt;warning: skipping optional Message Passing Interface (MPI) library.&lt;br /&gt;note: to enable MPI support, add “using mpi ;” to user-config.jam.&lt;br /&gt;note: to suppress this message, pass “–without-mpi” to bjam.&lt;br /&gt;note: otherwise, you can safely ignore this message.&lt;br /&gt;&lt;br /&gt;Follow the instructions. The user-config.jam is to be created in your “current” directory ($BOOST_ROOT_DIR\tools\build\v2).&lt;br /&gt;&lt;br /&gt;Now build the Boost.MPI library by issuing:&lt;br /&gt;&lt;br /&gt;“&lt;span style="color:#000099;"&gt;bjam –with-mpi stage&lt;/span&gt;”&lt;br /&gt;&lt;br /&gt;The Microsoft MPI library is auto detected!&lt;br /&gt;&lt;br /&gt;That is it!  Happy Hacking :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-9155449833075477126?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/9155449833075477126/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2009/06/building-boost-lib-135-with-vc-2008.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/9155449833075477126'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/9155449833075477126'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2009/06/building-boost-lib-135-with-vc-2008.html' title='Building Boost Lib 1.35 with VC++ 2008'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-903631177008659320</id><published>2009-06-28T19:52:00.001+05:30</published><updated>2009-06-28T19:52:01.482+05:30</updated><title type='text'>Anbe Vaa - Vijay TV's New serial</title><content type='html'>Here you go. Me and Mani has become a big fan of this title song .. Thats a soft melody song .. Here is the lyrics for the song.&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;Guys, if u get a chance, hear this song in Vijay TV :)&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt; &lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Arial; "&gt;&lt;font face="Comic Sans MS, Times, serif" color="#0000ff" size="2"&gt;&lt;div&gt;Ah.. ah... (Female Voice)&lt;/div&gt;&lt;div&gt; &lt;/div&gt;&lt;/font&gt;&lt;div&gt;&lt;font face="Comic Sans MS, Times, serif" color="#0000ff" size="2"&gt;(Male voice)&lt;br&gt; Oru paarvai paarkirai..&lt;br&gt;pudhidhai nan pookiren..&lt;br&gt;Idhayam idam maarudhe..&lt;br&gt;Idhu kaadhala...&lt;/font&gt;&lt;/div&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 2px; padding-right: 0px; padding-bottom: 5px; padding-left: 0px; font-size: 13px; "&gt; &lt;font face="Comic Sans MS, Times, serif" color="#0000ff" size="2"&gt;Nilavodu theigiren..&lt;br&gt;Ninaivale karaigiren..&lt;br&gt;sugamana vedhanai..&lt;br&gt;Idhu kaadala...&lt;/font&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 2px; padding-right: 0px; padding-bottom: 5px; padding-left: 0px; font-size: 13px; "&gt; &lt;font face="Comic Sans MS, Times, serif" color="#0000ff" size="2"&gt;Engeyo.. engeyo.. &lt;br&gt;ennule engeyo..&lt;br&gt;vinmeengal sidharudhe&lt;br&gt;yaenadi..&lt;/font&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 2px; padding-right: 0px; padding-bottom: 5px; padding-left: 0px; font-size: 13px; "&gt; &lt;font face="Comic Sans MS, Times, serif" color="#0000ff" size="2"&gt;Anbe vaa..&lt;br&gt;Anbe vaa..&lt;br&gt;Anbe vaa&lt;br&gt;Anbe vaa.. a...&lt;/font&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 2px; padding-right: 0px; padding-bottom: 5px; padding-left: 0px; font-size: 13px; "&gt; &lt;font face="Comic Sans MS, Times, serif" color="#0000ff" size="2"&gt;Ah...&lt;/font&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 2px; padding-right: 0px; padding-bottom: 5px; padding-left: 0px; font-size: 13px; "&gt; &lt;font face="Comic Sans MS, Times, serif" color="#cc0000" size="2"&gt;(Female)&lt;br&gt;Kannukule kannukule.. kaadhal vandhu nenjai thotu povathen.. &lt;br&gt;(Male)&lt;br&gt;Enna idhu enna idhu.. vaanavillil vanam rendu koodudhe..&lt;br&gt;(Female)&lt;br&gt; Theendinal.. vaanile..&lt;br&gt;megamai alaigiren&lt;br&gt;(male)&lt;br&gt;neenginal dhoorathil..&lt;br&gt;pulliyai tholaigiren..&lt;/font&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 2px; padding-right: 0px; padding-bottom: 5px; padding-left: 0px; font-size: 13px; "&gt; &lt;font face="Comic Sans MS, Times, serif" color="#cc0000" size="2"&gt;Nillarendral nillaamal&lt;br&gt;yenendru kelaamal&lt;br&gt;edhedho seigirai..&lt;br&gt;yaenadi..&lt;/font&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 2px; padding-right: 0px; padding-bottom: 5px; padding-left: 0px; font-size: 13px; "&gt; &lt;font face="Comic Sans MS, Times, serif" color="#cc0000" size="2"&gt;Anbe vaa..&lt;br&gt;Anbe vaa..&lt;br&gt;Anbe vaa&lt;br&gt;Anbe vaa.. a...&lt;/font&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 2px; padding-right: 0px; padding-bottom: 5px; padding-left: 0px; font-size: 13px; "&gt; &lt;font face="Comic Sans MS, Times, serif" color="#006600" size="2"&gt;(F)Enna solli enna solli kaadhal adhai unnidathil kaatuven..&lt;br&gt;(m)Sathamindri sathamindri mounamai nenjukulle pootuven..&lt;br&gt;(F)kavithaigal ezhudhida vaarthaigal thedinen..&lt;br&gt; (M)un peyar  ezhudhinaal kavidhayai paadinen..&lt;/font&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 2px; padding-right: 0px; padding-bottom: 5px; padding-left: 0px; font-size: 13px; "&gt; &lt;font face="Comic Sans MS, Times, serif" color="#006600" size="2"&gt;Enn ulle en ulle..&lt;br&gt;un kannin minsaram..&lt;br&gt;edhedho seiyudhe.. &lt;br&gt;Yaenadi..&lt;/font&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 2px; padding-right: 0px; padding-bottom: 5px; padding-left: 0px; font-size: 13px; "&gt; &lt;br&gt;&lt;font face="Comic Sans MS, Times, serif"&gt;&lt;font size="2"&gt;&lt;font color="#006600"&gt;Anbe vaa..&lt;br&gt;Anbe vaa..&lt;br&gt;Anbe vaa&lt;br&gt;Anbe vaa.. a...&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;/span&gt;&lt;/div&gt; &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-903631177008659320?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/903631177008659320/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2009/06/anbe-vaa-vijay-tvs-new-serial.html#comment-form' title='16 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/903631177008659320'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/903631177008659320'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2009/06/anbe-vaa-vijay-tvs-new-serial.html' title='Anbe Vaa - Vijay TV&apos;s New serial'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>16</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-1944334989383566574</id><published>2009-06-25T08:48:00.004+05:30</published><updated>2009-06-25T14:26:11.798+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><category scheme='http://www.blogger.com/atom/ns#' term='Code'/><title type='text'>Secrets of std::map</title><content type='html'>I should admit that I'm very poor in C++ Programming. Today, me and one of colleague was trying to understand a code writter by one of a pioneer in our team. We initially thought he wrote a crabby code but indeed we were wrong and he proved his expertness :)&lt;br /&gt;&lt;br /&gt;Below is the snippet of similar case.&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="c++"&gt;&lt;br /&gt;&lt;br /&gt;#include "stdafx.h"&lt;br /&gt;#include &lt; iostream &gt;&lt;br /&gt;#include &lt; map &gt;&lt;br /&gt;&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt; // 1. define the map&lt;br /&gt; typedef std::map&lt;int, int&gt; Map;&lt;br /&gt;&lt;br /&gt; // 2. Create the object for it&lt;br /&gt; Map myMap;&lt;br /&gt;&lt;br /&gt; for (int i=0; i&lt;10; ++i)&lt;br /&gt; {&lt;br /&gt;    /**************************** &lt;br /&gt;      3. Whats going on here ???. &lt;br /&gt;         We just created the object.&lt;br /&gt;         Could this be a buggy code ?? &lt;br /&gt;&lt;br /&gt;         Nope. When we reference an item in map &lt;br /&gt;         and if the item is not available, &lt;br /&gt;         it creates the object. Great :)&lt;br /&gt;&lt;br /&gt;         I personally seen/used the creation&lt;br /&gt;         of map on the left side,&lt;br /&gt;         something like myMap[2] = 20&lt;br /&gt;         But the below is of something which&lt;br /&gt;         I am seeing new today :)&lt;br /&gt;     **********************************************/&lt;br /&gt;  &lt;br /&gt;             int &amp;ref = myMap[i];&lt;br /&gt;             ref = i;&lt;br /&gt;  &lt;br /&gt; }&lt;br /&gt; for (int i=0; i&lt;10; ++i)&lt;br /&gt; {&lt;br /&gt;             std::cout &lt;&lt; myMap[i] &lt;&lt; " ";&lt;br /&gt; }&lt;br /&gt; std::cout &lt;&lt; std::endl;&lt;br /&gt; &lt;br /&gt; return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Happy Hacking :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-1944334989383566574?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/1944334989383566574/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2009/06/secrets-of-stdmap.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/1944334989383566574'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/1944334989383566574'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2009/06/secrets-of-stdmap.html' title='Secrets of std::map'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-6574515338553025042</id><published>2009-06-22T07:41:00.006+05:30</published><updated>2009-06-25T14:29:56.199+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><category scheme='http://www.blogger.com/atom/ns#' term='Code'/><title type='text'>C++ forward declaration error</title><content type='html'>&lt;span style="font-size:85%;"&gt;&lt;u&gt;&lt;strong&gt;Problem:&lt;/strong&gt; &lt;/u&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;I am trying to declare and use a class B inside of a class A and define B outside A.I know for a fact that this is possible because Bjarne Stroustrup uses this in his book "The C++ programming language" (page 293,for example the String and Srep classes). So this is my minimal piece of code that causes problems.&lt;/span&gt;&lt;br /&gt;&lt;pre class="c" name="code"&gt;&lt;br /&gt;class A&lt;br /&gt;{&lt;br /&gt;    struct B; // forward declaration&lt;br /&gt;    B* c; A()&lt;br /&gt;    {&lt;br /&gt;        c-&gt;i;&lt;br /&gt;    }&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;struct A::B&lt;br /&gt;{&lt;br /&gt;    /** we define struct B like this&lt;br /&gt;     ** becuase it was first declared&lt;br /&gt;     ** in the namespace A */&lt;br /&gt;&lt;br /&gt;    int i;&lt;br /&gt;};&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;strong&gt;&lt;u&gt;Error: &lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;&lt;/span&gt;&lt;strong&gt;&lt;u&gt;&lt;br /&gt;&lt;/u&gt;&lt;/strong&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;This code gives the following compilation errors in g++ : tst.cpp: In constructor ‘A::A()’: tst.cpp:5: error: invalid use of undefined type ‘struct A::B’ tst.cpp:3: error: forward declaration of ‘struct A::B’&lt;br /&gt;&lt;/u&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;Solution:&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Define the constructor for A AFTER the definition of struct B.&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-6574515338553025042?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/6574515338553025042/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2009/06/c-forward-declaration-error.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/6574515338553025042'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/6574515338553025042'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2009/06/c-forward-declaration-error.html' title='C++ forward declaration error'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-7228470076090858731</id><published>2009-06-14T18:45:00.001+05:30</published><updated>2009-06-14T18:45:26.259+05:30</updated><title type='text'></title><content type='html'>Sambhar Receipe&lt;br /&gt;&lt;br /&gt;Step 1:&lt;br /&gt;Put Onions, Tomato, Chilly, Coriander leaf, 1 Spn of Turmeric Cumin powder (from Amma) in a pressure cooker and keep 3 Whistle.&lt;br /&gt;&lt;br /&gt;Step 2:&lt;br /&gt;&lt;br /&gt;Put all the needed vegetables in the same pressure cooker and add 1/5 Spn of chilly power, salt to taste. Keep for one more whistle.&lt;br /&gt;&lt;br /&gt;Sambhar is ready ;)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-7228470076090858731?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/7228470076090858731/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2009/06/sambhar-receipe-step-1-put-onions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/7228470076090858731'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/7228470076090858731'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2009/06/sambhar-receipe-step-1-put-onions.html' title=''/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-9150040246850287739</id><published>2009-02-26T09:06:00.003+05:30</published><updated>2009-02-26T09:21:39.459+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Code'/><title type='text'>How to get the elapsed time in millisecs</title><content type='html'>Finding an elapsed time of a function/API/method will help you to understand its performance and the most of our manager/management will hails u if you give them a nice performance graph/chart of an application :)&lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;strong&gt;My Approach:&lt;/strong&gt;&lt;/em&gt;&lt;br /&gt;You can use &lt;em&gt;gettimeofday&lt;/em&gt; at the start and end of your method and then the difference the two will give the elapsed time .. You'll get a structure like the one below:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="cpp"&gt;&lt;br /&gt;struct timeval {&lt;br /&gt;    time_t      tv_sec;  /* in secs */&lt;br /&gt;    suseconds_t tv_usec; /* in Microseconds */&lt;br /&gt;};&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;strong&gt;Code snippet:&lt;/strong&gt;&lt;/em&gt;&lt;br /&gt;&lt;pre name="code" class="cpp"&gt;&lt;br /&gt;&lt;br /&gt;#include &lt;sys/time.h&gt;&lt;br /&gt;#include &lt;stdio.h&gt;&lt;br /&gt;#include &lt;unistd.h&gt;&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;    struct timeval start, end;&lt;br /&gt;    long mtime, seconds, useconds;    &lt;br /&gt;&lt;br /&gt;    // Get the start time&lt;br /&gt;    gettimeofday(&amp;start, NULL);&lt;br /&gt;    &lt;br /&gt;    // Here you go with your method call&lt;br /&gt;    usleep(2000);&lt;br /&gt;&lt;br /&gt;    // note the end time&lt;br /&gt;    gettimeofday(&amp;end, NULL);&lt;br /&gt;&lt;br /&gt;    seconds  = end.tv_sec  - start.tv_sec;&lt;br /&gt;    useconds = end.tv_usec - start.tv_usec;&lt;br /&gt;&lt;br /&gt;    mtime = ((seconds) * 1000 + useconds/1000.0) + 0.5;&lt;br /&gt;&lt;br /&gt;    printf("Elapsed time: %ld milliseconds\n", mtime);&lt;br /&gt;&lt;br /&gt;    return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-9150040246850287739?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/9150040246850287739/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2009/02/how-to-get-elapsed-time-in-millisecs.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/9150040246850287739'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/9150040246850287739'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2009/02/how-to-get-elapsed-time-in-millisecs.html' title='How to get the elapsed time in millisecs'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-6266034125970878380</id><published>2009-02-25T15:37:00.003+05:30</published><updated>2009-02-25T15:46:33.285+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><title type='text'>Python: Human readable time span given total secs</title><content type='html'>&lt;em&gt;&lt;strong&gt;Problem:&lt;/strong&gt;&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;Function takes an amount of time in seconds and returns a human readable time span.&lt;br /&gt;&lt;br /&gt;Input: 14723 (in secs)&lt;br /&gt;Output : 4h 5m 23s&lt;br /&gt;&lt;br /&gt;Suffixes used:&lt;br /&gt;&lt;br /&gt;y - year&lt;br /&gt;w - week&lt;br /&gt;d - days&lt;br /&gt;h - hours&lt;br /&gt;m - min&lt;br /&gt;s - sec&lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;strong&gt;Code:&lt;/strong&gt;&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="python"&gt;&lt;br /&gt;#!/usr/bin/env python&lt;br /&gt;def elapsed_time (seconds, suffixes=['y','w','d','h','m','s'], add_s=False, separator=' '):&lt;br /&gt;    """&lt;br /&gt;    Takes an amount of seconds and turns it into a human-readable amount of time.&lt;br /&gt;    """&lt;br /&gt;    # the formatted time string to be returned&lt;br /&gt;    time = []&lt;br /&gt;&lt;br /&gt;    # the pieces of time to iterate over (days, hours, minutes, etc)&lt;br /&gt;    # - the first piece in each tuple is the suffix (d, h, w)&lt;br /&gt;    # - the second piece is the length in seconds (a day is 60s * 60m * 24h)&lt;br /&gt;    parts = [(suffixes[0], 60 * 60 * 24 * 7 * 52),&lt;br /&gt;          (suffixes[1], 60 * 60 * 24 * 7),&lt;br /&gt;          (suffixes[2], 60 * 60 * 24),&lt;br /&gt;          (suffixes[3], 60 * 60),&lt;br /&gt;          (suffixes[4], 60),&lt;br /&gt;          (suffixes[5], 1)]&lt;br /&gt;&lt;br /&gt;    # for each time piece, grab the value and remaining seconds, and add it to&lt;br /&gt;    # the time string&lt;br /&gt;    for suffix, length in parts:&lt;br /&gt;        value = seconds / length&lt;br /&gt;        if value &gt; 0:&lt;br /&gt;            seconds = seconds % length&lt;br /&gt;            time.append('%s%s' % (str(value),&lt;br /&gt;                           (suffix, (suffix, suffix + 's')[value &gt; 1])[add_s]))&lt;br /&gt;        if seconds &lt; 1:&lt;br /&gt;            break&lt;br /&gt;&lt;br /&gt;    return separator.join(time)&lt;br /&gt;&lt;br /&gt;if __name__ == '__main__':&lt;br /&gt;    # 2 years, 1 week, 6 days, 2 hours, 59 minutes, 23 seconds&lt;br /&gt;    # 2y 1w 6d 2h 59m 23s&lt;br /&gt;    seconds = (60 * 60 * 24 * 7 * 52 * 2) + (60 * 60 * 24 * 7 * 1) + (60 * 60 * 24 * 6) + (60 * 60 * 2) + (60 * 59) + (1 * 23)&lt;br /&gt;    print elapsed_time(seconds)&lt;br /&gt;    print elapsed_time(seconds, [' year',' week',' day',' hour',' minute',' second'])&lt;br /&gt;    print elapsed_time(seconds, [' year',' week',' day',' hour',' minute',' second'], add_s=True)&lt;br /&gt;    print elapsed_time(seconds, [' year',' week',' day',' hour',' minute',' second'], add_s=True, separator=', ')&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;[10:13:34 gmuniyan@lnl43a-3102] /home/gmuniyan/python&gt;./elapsedTime.py&lt;br /&gt;2y 1w 6d 2h 59m 23s&lt;br /&gt;2 year 1 week 6 day 2 hour 59 minute 23 second&lt;br /&gt;2 years 1 week 6 days 2 hours 59 minutes 23 seconds&lt;br /&gt;2 years, 1 week, 6 days, 2 hours, 59 minutes, 23 seconds&lt;br /&gt;&lt;br /&gt;Honor: &lt;a href="http://snipplr.com/view/5713/python-elapsedtime-human-readable-time-span-given-total-seconds/"&gt;Original Post&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-6266034125970878380?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/6266034125970878380/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2009/02/python-human-readable-time-span-give.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/6266034125970878380'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/6266034125970878380'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2009/02/python-human-readable-time-span-give.html' title='Python: Human readable time span given total secs'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-862682780177906473</id><published>2009-02-24T12:27:00.005+05:30</published><updated>2009-02-24T21:30:03.155+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Bash'/><title type='text'>Running a cmd from bash script</title><content type='html'>&lt;strong&gt;&lt;em&gt;Problem:&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;There are many situations in which you may want to run different command in your shell script depending on requirements and circumstances. &lt;br /&gt;&lt;br /&gt;There are two approaches we can take from here on.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Approach #1:&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Use either case statement or if..elif..else For example:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="Bash"&gt;&lt;br /&gt;&lt;br /&gt;#!/bin/bash&lt;br /&gt;if [ this -eq that ];then&lt;br /&gt;   command1&lt;br /&gt;else&lt;br /&gt;   command2&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Approach #2:&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;BASH allows you to assign/store a command in a built-in variable called CMD. Build your command in this variable and execute $CMD.&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="Bash"&gt;&lt;br /&gt;&lt;br /&gt;#!/bin/bash&lt;br /&gt;[ this -eq that ] &amp;&amp; CMD=”/bin/ls” || CMD="/bin/date";&lt;br /&gt;eval $CMD;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This is a very simple example and this approach is very much generic if you want to have a generic function to execute all the commands. For example:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="Bash"&gt;&lt;br /&gt;&lt;br /&gt;#!/bin/bash&lt;br /&gt;&lt;br /&gt;execute() {&lt;br /&gt;  # $1 holds the arg to this function&lt;br /&gt;  CMD="$1";&lt;br /&gt;  eval $CMD;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;## Here is your main function&lt;br /&gt;&lt;br /&gt;if [ this -eq that]&lt;br /&gt;then&lt;br /&gt;    execute "/bin/ls | wc -l";&lt;br /&gt;else&lt;br /&gt;    execute "/bin/ls";&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;NOTE: eval is required when you use "|" or redirection of cmd output.&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;Happy hacking :) !!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-862682780177906473?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/862682780177906473/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2009/02/running-cmd-from-bash-script.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/862682780177906473'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/862682780177906473'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2009/02/running-cmd-from-bash-script.html' title='Running a cmd from bash script'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-2231607744105029205</id><published>2009-02-23T20:34:00.003+05:30</published><updated>2009-02-23T20:50:38.090+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><title type='text'>Python: Processing cmd line args</title><content type='html'>Next thing that you might be interested to learn after the historic "Hello World" program is to know how to process the cmd line arguments.&lt;br /&gt;&lt;br /&gt;Method #1: Using sys:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="python"&gt;&lt;br /&gt;#! /usr/bin/python&lt;br /&gt;&lt;br /&gt;import sys;&lt;br /&gt;&lt;br /&gt;if __name__ == "__main__":&lt;br /&gt;   for args in sys.argv:&lt;br /&gt;       print args;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Output:&lt;br /&gt;&lt;br /&gt;# cmdLine.py 1 2 3 4&lt;br /&gt;cmdLine.py&lt;br /&gt;1&lt;br /&gt;2&lt;br /&gt;3&lt;br /&gt;4&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-2231607744105029205?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/2231607744105029205/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2009/02/python-processing-cmd-line-args.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/2231607744105029205'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/2231607744105029205'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2009/02/python-processing-cmd-line-args.html' title='Python: Processing cmd line args'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-3570567546622318947</id><published>2009-02-23T15:04:00.003+05:30</published><updated>2009-02-23T15:12:33.642+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Python'/><title type='text'>Python: Hello World</title><content type='html'>&lt;strong&gt;This is my first post against Python, watchout for more to come soon ...&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;Python way of saying "Hello world" :)&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name='code' class='python'&gt;&lt;br /&gt;#!/usr/bin/env python&lt;br /&gt;&lt;br /&gt;## In Python each module will have a name associated with it&lt;br /&gt;## And here is the main module&lt;br /&gt;&lt;br /&gt;if __name__ == "__main__":&lt;br /&gt;    print "Hello World";&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-3570567546622318947?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/3570567546622318947/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2009/02/python-hello-world.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/3570567546622318947'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/3570567546622318947'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2009/02/python-hello-world.html' title='Python: Hello World'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-7451482131735740148</id><published>2009-02-01T19:12:00.001+05:30</published><updated>2009-02-01T19:12:44.592+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Show that 2^n is O(n!)</title><content type='html'>&lt;p&gt;This is an interview question from MS. &lt;/p&gt; &lt;p&gt;&lt;strong&gt;&lt;u&gt;Answer:&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;n! = 2*3*...*n &amp;gt;= 2*2*...*2 = 2^(n-1)&lt;/p&gt; &lt;p&gt;Since 2^n &amp;lt;= 2*n! for all n, we have that 2^n = O(n!).&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-7451482131735740148?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/7451482131735740148/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2009/02/show-that-2n-is-on.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/7451482131735740148'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/7451482131735740148'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2009/02/show-that-2n-is-on.html' title='Show that 2^n is O(n!)'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-3953830422911409142</id><published>2009-01-15T20:55:00.000+05:30</published><updated>2009-01-15T20:57:14.509+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Test from Windows Live Writer</title><content type='html'>Hi all, this is a just mail. &lt;pre name='code' class='cpp'&gt;&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;	return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-3953830422911409142?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/3953830422911409142/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2009/01/test-from-windows-live-writer.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/3953830422911409142'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/3953830422911409142'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2009/01/test-from-windows-live-writer.html' title='Test from Windows Live Writer'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-2045664298202588541</id><published>2009-01-05T20:50:00.001+05:30</published><updated>2009-01-05T21:06:23.936+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Arrange 0's &amp; 1's</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;Problem Statement:&lt;br /&gt;-------------------&lt;br /&gt;&lt;br /&gt;An array of size n among which there are n/2 0s and n/2 1s arranged in random order.&lt;br /&gt;Arrange all the 1s to left and all 0s to right but it needs to be&lt;br /&gt;stable i.e., the order of 1s and 0s in the i/p array should be maintained.&lt;br /&gt;&lt;br /&gt;Expected Complexity:&lt;br /&gt;--------------------------------&lt;br /&gt;O(N) with constant space.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Pseudocode:&lt;br /&gt;--------------------&lt;br /&gt;&lt;br /&gt;1. Have two counters, count1 = 0 and count2 = (n/2)+1&lt;br /&gt;2. Traverse thru the array, if(arr[ i ] == 1) { arr[ i ] = count1++;} else { arr[ i ] = count2++ };&lt;br /&gt;3. At the end of the traversal, you have array filled with numbers 0 to n-1&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now the problem reduces to sorting and array of n numbers which has elements from 0 to&lt;br /&gt;n-1 occuring only once which can be done in O(n).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class='cpp' name='code'&gt;&lt;br /&gt;for(j = 0; j &amp;lt;= 1; j++)&lt;br /&gt;{&lt;br /&gt;        for(i = 0; i&amp;lt;n; i++)&lt;br /&gt;        {&lt;br /&gt;                if(arr[ i ] != i)&lt;br /&gt;                {&lt;br /&gt;                        swap(arr[ i ], arr[ arr[ i ] ]);&lt;br /&gt;                }&lt;br /&gt;        }&lt;br /&gt;}&lt;br /&gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Note: j loop runs only twice irrespective on 'n' and has constant complexity. The order of this whole loop is 2*n = O(n).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;4. After the array is sorted, Again traverse thru the array and make elements arr[0] to&lt;br /&gt;arr[n/2] to '1' and arr[(n/2)+1] to arr[n] as '0'.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Space complexity is constant and time complexity is O(step2) + O(step3) + O(step4) = n + 2n +n = 4*n = O(n).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Solution #1 (Stable):&lt;br /&gt;------------------------&lt;br /&gt;&lt;br /&gt;&amp;lt;pre name='code' class='cpp'&amp;gt;&lt;br /&gt;#include&amp;lt;iostream.h&amp;gt;&lt;br /&gt;&lt;br /&gt;int a[] = { 1,0,0,0,1,1,1,0,0,1};&lt;br /&gt;#define _SIZE sizeof(a)/sizeof(a[0])&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/* Helper Function */&lt;br /&gt;void printArray()&lt;br /&gt;{&lt;br /&gt;    for(int i=0;i&amp;lt;_SIZE; ++i)&lt;br /&gt;        cout&amp;lt;&amp;lt;a[i]&amp;lt;&amp;lt;" ";&lt;br /&gt;&lt;br /&gt;    cout&amp;lt;&amp;lt;endl;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;    int countOne = 0;&lt;br /&gt;    int countZero = (_SIZE)/2;&lt;br /&gt;    int i = 0;&lt;br /&gt;&lt;br /&gt;    /* Fill the array with numbers from 1 to N */&lt;br /&gt;    for(i=0; i &amp;lt; _SIZE; ++i)&lt;br /&gt;    {&lt;br /&gt;&lt;br /&gt;        if(a[i] == 1)&lt;br /&gt;        {&lt;br /&gt;            a[i] = countOne;&lt;br /&gt;            countOne++;&lt;br /&gt;        }&lt;br /&gt;        else&lt;br /&gt;        {&lt;br /&gt;            a[i] = countZero;&lt;br /&gt;            countZero++;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    printArray();&lt;br /&gt;&lt;br /&gt;    /* Swap the number and make it a sorted one */&lt;br /&gt;    for(int j = 0; j&amp;lt; 2; ++j)&lt;br /&gt;    {&lt;br /&gt;        for(i=0; i &amp;lt; _SIZE; ++i)&lt;br /&gt;        {&lt;br /&gt;                if(a[i] != i)&lt;br /&gt;                {&lt;br /&gt;                        int temp = a[i];&lt;br /&gt;                        a[i] = a[a[i]];&lt;br /&gt;                        a[temp] = temp;&lt;br /&gt;                }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    printArray();&lt;br /&gt;&lt;br /&gt;    /* Fill the 1st N/2 elements with 1 */&lt;br /&gt;    for(i=0; i&amp;lt;_SIZE/2; ++i)&lt;br /&gt;        a[i] = 1;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    /* Fill the last N/2 elements with 1 */&lt;br /&gt;    for(i=_SIZE/2; i&amp;lt;_SIZE; i++)&lt;br /&gt;        a[i] = 0;&lt;br /&gt;&lt;br /&gt;    printArray();&lt;br /&gt;&lt;br /&gt;    return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Solution #2 (UnStable):&lt;br /&gt;-----------------------------------&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Here is a small variation of the quick sort to solve the same problem but this solution is not stable. So I prefer #1.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;pre name='code' class='cpp'&amp;gt;&lt;br /&gt;#include&amp;lt;iostream.h&amp;gt;&lt;br /&gt;using namespace std;&lt;br /&gt;#define _SIZE sizeof(a)/sizeof(a[0])&lt;br /&gt;&lt;br /&gt;void swap(int *a, int l, int r)&lt;br /&gt;{&lt;br /&gt;    cout&amp;lt;&amp;lt;"Swaping "&amp;lt;&amp;lt;l&amp;lt;&amp;lt;" "&amp;lt;&amp;lt;r&amp;lt;&amp;lt;endl;&lt;br /&gt;&lt;br /&gt;    if(a[l] != a[r])&lt;br /&gt;        a[l] ^= a[r] ^= a[l] ^= a[r];&lt;br /&gt;&lt;br /&gt;    return;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;bool compare_1_upper(int *a, int u, int p)&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;    return (a[u] == p);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;bool compare_1_lower(int *a, int l, int p)&lt;br /&gt;{&lt;br /&gt;    return (a[l] &amp;lt; p);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;bool compare_0_upper(int *a, int u, int p)&lt;br /&gt;{&lt;br /&gt;    return (a[u] &amp;gt; p);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;bool compare_0_lower(int *a, int u, int p)&lt;br /&gt;{&lt;br /&gt;    return (a[u] == p);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;bool (*funcPtr_upper)(int *, int, int) = 0;&lt;br /&gt;bool (*funcPtr_lower)(int *, int, int) = 0;&lt;br /&gt;&lt;br /&gt;void qPartition(int *a, int low, int upper)&lt;br /&gt;{&lt;br /&gt;    int pivot = a[low];&lt;br /&gt;    int l = low - 1;&lt;br /&gt;    int u = upper + 1;&lt;br /&gt;    if(a[low])&lt;br /&gt;    {&lt;br /&gt;        funcPtr_upper = compare_1_upper;&lt;br /&gt;        funcPtr_lower = compare_1_lower;&lt;br /&gt;    }&lt;br /&gt;    else&lt;br /&gt;    {&lt;br /&gt;        funcPtr_upper = compare_0_upper;&lt;br /&gt;        funcPtr_lower = compare_0_lower;&lt;br /&gt;    }&lt;br /&gt;    while(1)&lt;br /&gt;    {&lt;br /&gt;        while(funcPtr_upper(a, --u, pivot));&lt;br /&gt;        while(funcPtr_lower(a, ++l, pivot));&lt;br /&gt;        if(l&amp;lt;u)&lt;br /&gt;            swap(a, l, u);&lt;br /&gt;        else&lt;br /&gt;            return;&lt;br /&gt;    }&lt;br /&gt;    return;&lt;br /&gt;}&lt;br /&gt;int a[] = { 1,1,1,1,1,0,0,1};&lt;br /&gt;void print()&lt;br /&gt;{&lt;br /&gt;    for(int i=0; i&amp;lt; _SIZE; ++i)&lt;br /&gt;        cout&amp;lt;&amp;lt;a[i]&amp;lt;&amp;lt;" ";&lt;br /&gt;    cout&amp;lt;&amp;lt;"\n";&lt;br /&gt;}&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;    print();&lt;br /&gt;    qPartition(a, 0, _SIZE - 1);&lt;br /&gt;    print();&lt;br /&gt;    return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-2045664298202588541?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/2045664298202588541/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2009/01/arrange-0-1.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/2045664298202588541'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/2045664298202588541'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2009/01/arrange-0-1.html' title='Arrange 0&amp;#39;s &amp;amp; 1&amp;#39;s'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-9063916446846705591</id><published>2008-12-29T20:33:00.000+05:30</published><updated>2008-12-29T20:38:28.101+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>XOR Linkedlist</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;Problem:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Implement a doubly linked list with a single pointer.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Solution:&lt;br /&gt;&lt;br /&gt;&lt;pre class='cpp' name='code'&gt;&lt;br /&gt;#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;#include &amp;lt;assert.h&amp;gt;&lt;br /&gt;&lt;br /&gt;        /* pray that a long is the size of a struct link* */&lt;br /&gt;&lt;br /&gt;        typedef unsigned long pointer;&lt;br /&gt;        struct link&lt;br /&gt;        {&lt;br /&gt;          pointer next_prev;&lt;br /&gt;          int payload;&lt;br /&gt;        };&lt;br /&gt;&lt;br /&gt;        typedef struct link link;&lt;br /&gt;        link* add_data(int payload, struct link* list)&lt;br /&gt;        {&lt;br /&gt;          struct link * new_link = (struct link*)malloc(sizeof(link));&lt;br /&gt;          assert(new_link);&lt;br /&gt;          new_link-&amp;gt;next_prev = (pointer)list;&lt;br /&gt;          new_link-&amp;gt;payload = payload;&lt;br /&gt;          if (list != NULL)&lt;br /&gt;          {&lt;br /&gt;            list-&amp;gt;next_prev = (pointer) list-&amp;gt;next_prev ^ (pointer)new_link;&lt;br /&gt;          }&lt;br /&gt;          return new_link;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        void walk_list(link *list)&lt;br /&gt;        {&lt;br /&gt;          struct link* prev = 0;&lt;br /&gt;          while (list != NULL)&lt;br /&gt;          {&lt;br /&gt;            pointer next = ((pointer)prev) ^ list-&amp;gt;next_prev;&lt;br /&gt;            printf("%d ", list-&amp;gt;payload);&lt;br /&gt;            prev = (struct link*)list;&lt;br /&gt;            list = (link*)next;&lt;br /&gt;          }&lt;br /&gt;          printf("\n");&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        int main(void)&lt;br /&gt;        {&lt;br /&gt;          link *l1 = add_data(1, NULL);&lt;br /&gt;          link *l2 = add_data(2, l1);&lt;br /&gt;          /* add something to the front ... */&lt;br /&gt;          /* add something to the back ... */&lt;br /&gt;          link *l3 = add_data(3, l2);&lt;br /&gt;          link *l4 = add_data(4, l3);&lt;br /&gt;          link *l5 = add_data(5, l4);&lt;br /&gt;&lt;br /&gt;          /* walk from front to back */&lt;br /&gt;          walk_list(l1);&lt;br /&gt;          /* walk from back to front */&lt;br /&gt;          walk_list(l5);&lt;br /&gt;&lt;br /&gt;          return 0;&lt;br /&gt;        }&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-9063916446846705591?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/9063916446846705591/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2008/12/xor-linkedlist.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/9063916446846705591'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/9063916446846705591'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2008/12/xor-linkedlist.html' title='XOR Linkedlist'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-6682508576455728469</id><published>2008-12-29T20:29:00.001+05:30</published><updated>2008-12-29T20:30:21.073+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Dutch Nation Flag Problem</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;&lt;u&gt;&lt;b&gt;Problem:&lt;/b&gt;&lt;/u&gt;&lt;br/&gt;&lt;br/&gt;Given an array of red, green and blue balls arrange them in groups of all red together, greens together and blue together. Do in a single scan of the array.&lt;br/&gt;&lt;br/&gt;This is same as You have an array containing only '0's, '1's and '2's. Club same items together in single scan.&lt;br/&gt;&lt;br/&gt;&lt;u&gt;&lt;b&gt;Solution:&lt;/b&gt;&lt;/u&gt;&lt;br/&gt;&lt;br/&gt;&lt;pre name='code' class='cpp'&gt;&amp;lt;br /&amp;gt;#include&amp;lt;iostream.h&amp;gt;&amp;lt;br /&amp;gt;#define _SIZE sizeof(a)/sizeof(a[0])&amp;lt;br /&amp;gt;using namespace std;&amp;lt;br /&amp;gt;void printArray(int *array, int size)&amp;lt;br /&amp;gt;{&amp;lt;br /&amp;gt;    for(int i=0; i&amp;lt;size; ++i)=""&amp;gt;&amp;lt;br /&amp;gt;        cout&amp;lt;&amp;lt;array[i]&amp;lt;&amp;lt;" ";&amp;lt;br /&amp;gt;    cout&amp;lt;&amp;lt;endl;&amp;lt;br /&amp;gt;    return;&amp;lt;br /&amp;gt;}&amp;lt;br /&amp;gt;void swap(int *a, int left, int right)&amp;lt;br /&amp;gt;{&amp;lt;br /&amp;gt;    if(a[left] != a[right])&amp;lt;br /&amp;gt;    {&amp;lt;br /&amp;gt;        a[left] ^= a[right] ^= a[left] ^= a[right];&amp;lt;br /&amp;gt;    }&amp;lt;br /&amp;gt;}&amp;lt;br /&amp;gt;void reArrange(int *a, int length)&amp;lt;br /&amp;gt;{&amp;lt;br /&amp;gt;    int low, mid, high = length -1;&amp;lt;br /&amp;gt;    low =0; mid = 0;&amp;lt;br /&amp;gt;    while(mid &amp;lt;= high)&amp;lt;br /&amp;gt;    {&amp;lt;br /&amp;gt;        switch(a[mid])&amp;lt;br /&amp;gt;        {&amp;lt;br /&amp;gt;            case 0 :&amp;lt;br /&amp;gt;                swap(a, low, mid);&amp;lt;br /&amp;gt;                low++;&amp;lt;br /&amp;gt;                mid++;&amp;lt;br /&amp;gt;                break;&amp;lt;br /&amp;gt;            case 1 :&amp;lt;br /&amp;gt;                mid++;&amp;lt;br /&amp;gt;                break;&amp;lt;br /&amp;gt;            case 2 :&amp;lt;br /&amp;gt;                swap(a, mid, high);&amp;lt;br /&amp;gt;                high--;&amp;lt;br /&amp;gt;                break;&amp;lt;br /&amp;gt;            default:&amp;lt;br /&amp;gt;                cout&amp;lt;&amp;lt;"&amp;gt;&amp;gt;&amp;gt; Error \n";&amp;lt;br /&amp;gt;        }&amp;lt;br /&amp;gt;    }&amp;lt;br /&amp;gt;}&amp;lt;br /&amp;gt;int main()&amp;lt;br /&amp;gt;{&amp;lt;br /&amp;gt;    int a [ ] = { 1,1,1,0,1,2,2,1,0,2,1,2,0 };&amp;lt;br /&amp;gt;    printArray(a, _SIZE);&amp;lt;br /&amp;gt;    reArrange(a, _SIZE);&amp;lt;br /&amp;gt;    printArray(a, _SIZE);&amp;lt;br /&amp;gt;    return 0;&amp;lt;br /&amp;gt;}&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-6682508576455728469?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/6682508576455728469/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2008/12/dutch-nation-flag-problem.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/6682508576455728469'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/6682508576455728469'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2008/12/dutch-nation-flag-problem.html' title='Dutch Nation Flag Problem'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-8019384574861402045</id><published>2008-12-27T19:40:00.000+05:30</published><updated>2008-12-27T19:41:41.606+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><title type='text'>Create encrypted tar file</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;one of the way to create a encrypted tar file under linux&lt;br/&gt;&lt;br/&gt;  $ tar -zcvf - stuff|openssl des3 -salt -k secretpassword | dd of=stuff.des3            &lt;br/&gt;                                                                                                  &lt;br/&gt;          This will create stuff.des3...don't forget the password you                             &lt;br/&gt;          put in place of  secretpassword. This can be done interactive as                        &lt;br/&gt;          well.                                                                                   &lt;br/&gt;                                                                                                  &lt;br/&gt;            $ dd if=stuff.des3 |openssl des3 -d -k secretpassword|tar zxf -                       &lt;br/&gt;                                                                                                  &lt;br/&gt;     NOTE:  above there is a "-" at the end... this will                                          &lt;br/&gt;            extract everything.                                                               &lt;br/&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-8019384574861402045?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/8019384574861402045/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2008/12/create-encrypted-tar-file.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/8019384574861402045'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/8019384574861402045'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2008/12/create-encrypted-tar-file.html' title='Create encrypted tar file'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-547571277174083789</id><published>2008-12-26T05:34:00.001+05:30</published><updated>2008-12-30T21:24:25.184+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><title type='text'>Mount error in Ubuntu</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;I got a wired error in my ubuntu today, when I tried to mount my Windows Partition. So I tried to reboot the machine in windows, and thought OS will do a filesystem check so that the error got wiped out. But no luck after rebooting the machine so many times. And below is the solution what I found:&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;font color='#000099'&gt;&lt;b&gt;&lt;u&gt;Error Message&lt;/u&gt;:&lt;br/&gt;&lt;br/&gt;&lt;img style='max-width: 800px;' src='http://lh4.ggpht.com/_9x6r0w5l1wM/SVQeVXpuDFI/AAAAAAAAAlk/4glzAWdT5rI/%5BUNSET%5D.png?imgmax=800'/&gt;&lt;br/&gt;&lt;br/&gt;&lt;u&gt;Solution:&lt;br/&gt;&lt;br/&gt;&lt;/u&gt;&lt;/b&gt;&lt;br/&gt;&lt;/font&gt;&lt;br/&gt;&lt;br /&gt;1. sudo apt-get install ntfsprogs&lt;br/&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;2. sudo ntfsfix /dev/sda2&lt;br/&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;mganesh@bluegene:~$ sudo ntfsfix /dev/sda3&lt;br/&gt;&lt;br /&gt;Mounting volume... FAILED&lt;br/&gt;&lt;br /&gt;Attempting to correct errors...&lt;br/&gt;&lt;br /&gt;Processing $MFT and $MFTMirr...&lt;br/&gt;&lt;br /&gt;Reading $MFT... OK&lt;br/&gt;&lt;br /&gt;Reading $MFTMirr... OK&lt;br/&gt;&lt;br /&gt;Comparing $MFTMirr to $MFT... OK&lt;br/&gt;&lt;br /&gt;Processing of $MFT and $MFTMirr completed successfully.&lt;br/&gt;&lt;br /&gt;Setting required flags on partition... OK&lt;br/&gt;&lt;br /&gt;Going to empty the journal ($LogFile)... OK&lt;br/&gt;&lt;br /&gt;NTFS volume version is 3.1.&lt;br/&gt;&lt;br /&gt;NTFS partition /dev/sda3 was processed successfully.&lt;br/&gt;&lt;br /&gt;mganesh@bluegene:~$ sudo ntfsfix /dev/sda2&lt;br/&gt;&lt;br /&gt;Mounting volume... FAILED&lt;br/&gt;&lt;br /&gt;Attempting to correct errors...&lt;br/&gt;&lt;br /&gt;Processing $MFT and $MFTMirr...&lt;br/&gt;&lt;br /&gt;Reading $MFT... OK&lt;br/&gt;&lt;br /&gt;Reading $MFTMirr... OK&lt;br/&gt;&lt;br /&gt;Comparing $MFTMirr to $MFT... OK&lt;br/&gt;&lt;br /&gt;Processing of $MFT and $MFTMirr completed successfully.&lt;br/&gt;&lt;br /&gt;Setting required flags on partition... OK&lt;br/&gt;&lt;br /&gt;Going to empty the journal ($LogFile)... OK&lt;br/&gt;&lt;br /&gt;NTFS volume version is 3.1.&lt;br/&gt;&lt;br /&gt;NTFS partition /dev/sda2 was processed successfully.&lt;br/&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;Happy Ubuntu :) !! .. This solves the problem&lt;br/&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;br/&gt;&lt;br /&gt;&lt;br/&gt;&lt;font color='#000099'&gt;&lt;br/&gt;&lt;br/&gt;&lt;b&gt;&lt;br/&gt;&lt;/b&gt;&lt;/font&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-547571277174083789?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/547571277174083789/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2008/12/mount-error-in-ubuntu_26.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/547571277174083789'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/547571277174083789'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2008/12/mount-error-in-ubuntu_26.html' title='Mount error in Ubuntu'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh4.ggpht.com/_9x6r0w5l1wM/SVQeVXpuDFI/AAAAAAAAAlk/4glzAWdT5rI/s72-c/%5BUNSET%5D.png?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-8683547285969238192</id><published>2008-12-24T12:57:00.000+05:30</published><updated>2008-12-30T21:19:04.354+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Search in the Matrix</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;&lt;br/&gt;We a Matrix where every ROW and COL are sorted something like the below:&lt;br/&gt;&lt;br/&gt;1 4 5  6&lt;br/&gt;2 5 7  9&lt;br/&gt;3 6 8 10&lt;br/&gt;&lt;br/&gt;&lt;b&gt;&lt;u&gt;Problem&lt;/u&gt;:&lt;/b&gt; give a number, you need to search whether it is there in the Matrix or not.&lt;br/&gt;&lt;br/&gt;&lt;u&gt;&lt;b&gt;Solution:&lt;/b&gt;&lt;/u&gt;&lt;br/&gt;&lt;br/&gt;The below solution's complexity is O(m+n) where m - ROW, n - COL&lt;br/&gt;&lt;br/&gt;&lt;pre class='cpp' name='code'&gt;&amp;lt;br /&amp;gt;#include&amp;lt;iostream&amp;gt;&amp;lt;br /&amp;gt;using namespace std;&amp;lt;br /&amp;gt;#define ROW 4&amp;lt;br /&amp;gt;#define COL 5&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;int Matrix[ROW][COL] = {&amp;lt;br /&amp;gt;    { 1, 3, 5, 7,  9},&amp;lt;br /&amp;gt;    { 2, 4, 6, 8, 10},&amp;lt;br /&amp;gt;    {11,13,15,17, 19},&amp;lt;br /&amp;gt;    {20,40,60,80,100}&amp;lt;br /&amp;gt;};&amp;lt;br /&amp;gt;bool isValid(int row, int col)&amp;lt;br /&amp;gt;{&amp;lt;br /&amp;gt;    if(row &amp;gt;= 0 &amp;amp;&amp;amp; col &amp;lt; COL)&amp;lt;br /&amp;gt;    {&amp;lt;br /&amp;gt;        return true;&amp;lt;br /&amp;gt;    }&amp;lt;br /&amp;gt;    return false;&amp;lt;br /&amp;gt;}&amp;lt;br /&amp;gt;int main()&amp;lt;br /&amp;gt;{&amp;lt;br /&amp;gt;    int i = ROW-1;&amp;lt;br /&amp;gt;    int j = 0; // Zeroth Column&amp;lt;br /&amp;gt;    int searchItem = 0;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;    cout&amp;lt;&amp;lt;"enter the number to be searched: ";&amp;lt;br /&amp;gt;    cin &amp;gt;&amp;gt; searchItem;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;    while(isValid(i, j))&amp;lt;br /&amp;gt;    {&amp;lt;br /&amp;gt;        if(Matrix[i][j]== searchItem)&amp;lt;br /&amp;gt;        {&amp;lt;br /&amp;gt;            cout&amp;lt;&amp;lt;"Item found @ ("&amp;lt;&amp;lt; i&amp;lt;&amp;lt;","&amp;lt;&amp;lt; j &amp;lt;&amp;lt; ") :"&amp;lt;&amp;lt; searchItem&amp;lt;&amp;lt; endl;&amp;lt;br /&amp;gt;            return 0;&amp;lt;br /&amp;gt;        }&amp;lt;br /&amp;gt;        else if (Matrix[i][j] &amp;gt; searchItem)&amp;lt;br /&amp;gt;        {&amp;lt;br /&amp;gt;            //go up, which means reduce the row&amp;lt;br /&amp;gt;            i--;&amp;lt;br /&amp;gt;        }&amp;lt;br /&amp;gt;        else&amp;lt;br /&amp;gt;        {&amp;lt;br /&amp;gt;            // itea is lesser than the index, go right&amp;lt;br /&amp;gt;            j++;&amp;lt;br /&amp;gt;        }&amp;lt;br /&amp;gt;    }&amp;lt;br /&amp;gt;    cout&amp;lt;&amp;lt;"Item not found :("&amp;lt;&amp;lt; endl;&amp;lt;br /&amp;gt;    return 0;&amp;lt;br /&amp;gt;}&amp;lt;br /&amp;gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-8683547285969238192?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/8683547285969238192/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2008/12/search-in-matrix-we-matrix-where-every.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/8683547285969238192'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/8683547285969238192'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2008/12/search-in-matrix-we-matrix-where-every.html' title='Search in the Matrix'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-6938093419343306236</id><published>2008-12-23T20:47:00.001+05:30</published><updated>2008-12-23T20:47:40.942+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Palindrome Number</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;Check whether a number is palindrome or not ..&lt;br /&gt;&lt;br /&gt;&lt;pre class='cpp' name='code'&gt;&lt;br /&gt;#include&amp;lt;iostream&amp;gt;&lt;br /&gt;using namespace std;&lt;br /&gt;bool isPanlindrome(int n)&lt;br /&gt;{&lt;br /&gt;        int rev = 0;&lt;br /&gt;        int num = n;&lt;br /&gt;        while(n)&lt;br /&gt;        {&lt;br /&gt;                rev = rev * 10 + (n%10);&lt;br /&gt;                n = n /10;&lt;br /&gt;        }&lt;br /&gt;        if(num &amp;amp;&amp;amp; num == rev)&lt;br /&gt;                return true;&lt;br /&gt;&lt;br /&gt;        return false;&lt;br /&gt;}&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;        int number = 0;&lt;br /&gt;&lt;br /&gt;        cout&amp;lt;&amp;lt;"Enter the number: ";&lt;br /&gt;        cin&amp;gt;&amp;gt;number;&lt;br /&gt;&lt;br /&gt;        cout&amp;lt;&amp;lt;number&amp;lt;&amp;lt;" is Panlindrome ?."&amp;lt;&amp;lt; (isPanlindrome(number)? "Yes !!": "No :(!!");&lt;br /&gt;        cout&amp;lt;&amp;lt;endl;&lt;br /&gt;        return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-6938093419343306236?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/6938093419343306236/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2008/12/palindrome-number.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/6938093419343306236'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/6938093419343306236'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2008/12/palindrome-number.html' title='Palindrome Number'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-4751820103751837277</id><published>2008-12-22T21:54:00.001+05:30</published><updated>2008-12-22T21:54:37.643+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>String Manipulation</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;Given a string : abbbccddddeee&lt;br /&gt;Encode it to : ab3c2d4e3&lt;br /&gt;&lt;br /&gt;&lt;pre class='cpp' name='code'&gt;&lt;br /&gt;#include&amp;lt;iostream&amp;gt;&lt;br /&gt;#include &amp;lt;strstream&amp;gt;&lt;br /&gt;#include&amp;lt;stdlib.h&amp;gt;&lt;br /&gt;#include&amp;lt;string.h&amp;gt;&lt;br /&gt;using namespace std;&lt;br /&gt;void convert(char *input)&lt;br /&gt;{&lt;br /&gt;        char *start = input;&lt;br /&gt;        char *s1 = input;&lt;br /&gt;        char *s2 = input + 1;&lt;br /&gt;&lt;br /&gt;        int len = strlen(input);&lt;br /&gt;        int count = 0;&lt;br /&gt;        char *end = start;&lt;br /&gt;        while(--len &amp;amp;&amp;amp; *s1 &amp;amp;&amp;amp; *s2 )&lt;br /&gt;        {&lt;br /&gt;                while(*s1 &amp;amp;&amp;amp; *s2 &amp;amp;&amp;amp; len &amp;amp;&amp;amp; *s1 == *s2)&lt;br /&gt;                {&lt;br /&gt;                        ++count;&lt;br /&gt;                        s2++;&lt;br /&gt;                        --len;&lt;br /&gt;                }&lt;br /&gt;                if(count)&lt;br /&gt;                {&lt;br /&gt;                        ostrstream str;&lt;br /&gt;                        str&amp;lt;&amp;lt;(count+1);&lt;br /&gt;                        *start = *s1;&lt;br /&gt;                        *++start = *(str.str());&lt;br /&gt;                        start = start + strlen(str.str()) - 1;&lt;br /&gt;                        count = 0;&lt;br /&gt;                }&lt;br /&gt;                else&lt;br /&gt;                        *start = *s1;&lt;br /&gt;                start++;&lt;br /&gt;                s1 = s2;&lt;br /&gt;                s2++;&lt;br /&gt;        }&lt;br /&gt;        if(*s1 != *(s1-1))&lt;br /&gt;                *start++ = *s1;&lt;br /&gt;        *start = *s2;&lt;br /&gt;        cout&amp;lt;&amp;lt;"Magic: "&amp;lt;&amp;lt;end&amp;lt;&amp;lt;endl;&lt;br /&gt;        return;&lt;br /&gt;}&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;        char input[100];&lt;br /&gt;        memset(input, 0, 100);&lt;br /&gt;        cout&amp;lt;&amp;lt;"Enter the string: ";&lt;br /&gt;        scanf("%s", input);&lt;br /&gt;        cout&amp;lt;&amp;lt;"You entered: "&amp;lt;&amp;lt;input&amp;lt;&amp;lt;"!!\n";&lt;br /&gt;        convert(input);&lt;br /&gt;        return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-4751820103751837277?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/4751820103751837277/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2008/12/string-manipulation.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/4751820103751837277'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/4751820103751837277'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2008/12/string-manipulation.html' title='String Manipulation'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-7591435774681040122</id><published>2008-12-18T20:15:00.001+05:30</published><updated>2008-12-18T20:15:09.553+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Array Rotation</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;A[M][N] is an array rotated in anti clock wise that is A'[N][M]. then mapping A&lt;i&gt;[j]=A'[ _ ][ _ ] in terms of M,N&lt;br/&gt;&lt;br/&gt;&lt;/i&gt;&lt;i&gt;A &lt;br/&gt;1 2 3 &lt;br/&gt;4 5 6 &lt;br/&gt;&lt;br/&gt;A'&lt;br/&gt;3 6&lt;br/&gt;2 5&lt;br/&gt;1 4&lt;br/&gt;&lt;br/&gt;&lt;/i&gt;&lt;i&gt;&lt;br/&gt;A&lt;i&gt;[j]=A'[ _ ][ _ ] ??&lt;/i&gt;&lt;/i&gt;&lt;br/&gt;&lt;u&gt;&lt;b&gt;&lt;br/&gt;Solution:&lt;/b&gt;&lt;/u&gt;&lt;br/&gt;&lt;br/&gt;i' = N-j-1&lt;br/&gt;j' = i&lt;br/&gt;thus after rotation&lt;br/&gt;A'[i ][j] = A[N-j-1][ i]&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-7591435774681040122?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/7591435774681040122/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2008/12/array-rotation.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/7591435774681040122'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/7591435774681040122'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2008/12/array-rotation.html' title='Array Rotation'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-5591121951712661601</id><published>2008-12-18T15:25:00.001+05:30</published><updated>2008-12-18T15:28:21.476+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>KMP string matching</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;&lt;pre name='code' class='c'&gt;&lt;br /&gt;#include&amp;lt;iostream&amp;gt;&lt;br /&gt;using namespace std;&lt;br /&gt;&lt;br /&gt;void preProcess(int *buf, const char *pattern)&lt;br /&gt;{&lt;br /&gt;    int j = -1;&lt;br /&gt;    int i = 0;&lt;br /&gt;    buf[i] = j;&lt;br /&gt;    int len = strlen(pattern);&lt;br /&gt;    &lt;br /&gt;    while(i&amp;lt;len)&lt;br /&gt;    {&lt;br /&gt;        while(j &amp;gt;=0 &amp;amp;&amp;amp; pattern[i] != pattern[j])&lt;br /&gt;        {&lt;br /&gt;            j=buf[j];&lt;br /&gt;    &lt;br /&gt;        }&lt;br /&gt;    &lt;br /&gt;        ++i;++j;&lt;br /&gt;        buf[i] = j;&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    return;&lt;br /&gt;    &lt;br /&gt;}&lt;br /&gt;void match(const char *str, const char *pattern, const int *pre)&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;    int m = 0;&lt;br /&gt;    int i = 0;&lt;br /&gt;    int len = strlen(str);&lt;br /&gt;    &lt;br /&gt;    while(m+i &amp;lt; len)&lt;br /&gt;    {&lt;br /&gt;        if(str[m+i] == pattern[i])&lt;br /&gt;        {&lt;br /&gt;            i++;&lt;br /&gt;            if(i == strlen(pattern))&lt;br /&gt;            {&lt;br /&gt;                cout&amp;lt;&amp;lt;"Match found at index: "&amp;lt;&amp;lt;m&amp;lt;&amp;lt;endl;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        else&lt;br /&gt;        {&lt;br /&gt;            m = m + i - pre[i];&lt;br /&gt;            if(i &amp;gt; 0)&lt;br /&gt;            {&lt;br /&gt;                i = pre[i];&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    &lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;br /&gt;    return;&lt;br /&gt;}&lt;br /&gt;void KMP()&lt;br /&gt;{&lt;br /&gt;    char String [] = "abcabcabdewqabcabd";&lt;br /&gt;    char pattern [] = "abcabd";&lt;br /&gt;&lt;br /&gt;    &lt;br /&gt;    int *pre = new int [strlen(pattern)+1];&lt;br /&gt;    memset(pre, 0, (strlen(pattern)+1) * sizeof(int));&lt;br /&gt;&lt;br /&gt;    &lt;br /&gt;    /* Preprocess the table */&lt;br /&gt;    preProcess(pre, pattern);&lt;br /&gt;&lt;br /&gt;    for(int i =0; i&amp;lt;strlen(pattern)+1; ++i)&lt;br /&gt;        cout&amp;lt;&amp;lt;pre[i]&amp;lt;&amp;lt;" ";&lt;br /&gt;&lt;br /&gt;    cout&amp;lt;&amp;lt;endl;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    /* Match the string */&lt;br /&gt;    match(String, pattern, pre);&lt;br /&gt;&lt;br /&gt;    delete pre;&lt;br /&gt;    return;&lt;br /&gt;}&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;    KMP();&lt;br /&gt;    return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-5591121951712661601?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/5591121951712661601/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2008/12/kmp-string-matching.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/5591121951712661601'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/5591121951712661601'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2008/12/kmp-string-matching.html' title='KMP string matching'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-674697534304158340</id><published>2008-12-18T13:03:00.003+05:30</published><updated>2008-12-18T15:29:05.937+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Matrix Filp</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;Matrix Flip&lt;br /&gt;&lt;br /&gt;&lt;pre name='code' class='c'&gt;&lt;br /&gt;void BitFlip()&lt;br /&gt;{&lt;br /&gt; int c = 1;&lt;br /&gt; int r = 1;&lt;br /&gt; int i, j;&lt;br /&gt;&lt;br /&gt; print();&lt;br /&gt; for(i=0; i&amp;lt;5; ++i)&lt;br /&gt;  r &amp;amp;= BitArray[0][i];&lt;br /&gt;&lt;br /&gt; for(i=0; i&amp;lt;5; ++i)&lt;br /&gt;  c &amp;amp;= BitArray[i][0];&lt;br /&gt;&lt;br /&gt; for(i=1; i&amp;lt;5; ++i)&lt;br /&gt; {&lt;br /&gt;  for(j=1; j&amp;lt;5; ++j)&lt;br /&gt;  {&lt;br /&gt;   if(! BitArray[i][j] )&lt;br /&gt;   {&lt;br /&gt;    BitArray[i][0] = 0;&lt;br /&gt;    BitArray[0][j] = 0;&lt;br /&gt;   }&lt;br /&gt;   else&lt;br /&gt;   {&lt;br /&gt;    BitArray[i][j] = 0;&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; for(i=1; i&amp;lt;5; ++i)&lt;br /&gt; {&lt;br /&gt;  for(j=1; j&amp;lt;5; ++j)&lt;br /&gt;  {&lt;br /&gt; &lt;br /&gt;   if(BitArray[i][0] &amp;amp;&amp;amp; BitArray[0][j])&lt;br /&gt;    BitArray[i][j] = 1;&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; if(r == 0)&lt;br /&gt;  for(i=0; i&amp;lt;5; ++i)&lt;br /&gt;   BitArray[i][0] = 0;&lt;br /&gt; &lt;br /&gt; if(c ==0)&lt;br /&gt;  for(i=0; i&amp;lt;5; ++i)&lt;br /&gt;   BitArray[0][i] = 0;&lt;br /&gt;&lt;br /&gt; print();&lt;br /&gt;&lt;br /&gt; return;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-674697534304158340?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/674697534304158340/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2008/12/void-bitflip-int-c-1-int-r-1-int-i-j.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/674697534304158340'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/674697534304158340'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2008/12/void-bitflip-int-c-1-int-r-1-int-i-j.html' title='Matrix Filp'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-1037235128109163002</id><published>2008-12-17T20:47:00.001+05:30</published><updated>2008-12-17T20:47:38.385+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Max sum in the array</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;&lt;pre class='c' name='code'&gt;#include&amp;lt;iostream&amp;gt;&lt;br /&gt;using namespace std;&lt;br /&gt;&lt;br /&gt;#define _SIZE sizeof(array)/sizeof(array[0])&lt;br /&gt;#define max(a,b) a&amp;gt;b ? a:b&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;    int array[] = { 0, 1, 2, -3, 5, 6, -5, 1, };&lt;br /&gt;    int MaxSoFar = 0;&lt;br /&gt;    int MaxCurrent = 0;&lt;br /&gt;    for(int i = 0; i&amp;lt;_SIZE; ++i)&lt;br /&gt;    {&lt;br /&gt;        MaxCurrent = max(MaxCurrent+array[i], 0);&lt;br /&gt;        MaxSoFar = max(MaxCurrent, MaxSoFar);&lt;br /&gt;    }&lt;br /&gt;    std::cout&amp;lt;&amp;lt;"Max sum in the array: "&amp;lt;&amp;lt; MaxSoFar&amp;lt;&amp;lt;"\n";&lt;br /&gt;    return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-1037235128109163002?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/1037235128109163002/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2008/12/max-sum-in-array_17.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/1037235128109163002'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/1037235128109163002'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2008/12/max-sum-in-array_17.html' title='Max sum in the array'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-2307107848895312321</id><published>2008-12-15T13:32:00.001+05:30</published><updated>2008-12-15T13:32:27.927+05:30</updated><title type='text'>Perl code to initiate a shutdown from website</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;&lt;small&gt;&lt;font face='verdana'&gt;#!/app/perl5005/bin/perl -w&lt;br/&gt;&lt;br/&gt;use lib "/Progra~1/Perl/site/lib";&lt;br/&gt;&lt;br/&gt;use HTTP::Request::Common qw(POST);&lt;br/&gt;use LWP::UserAgent;&lt;br/&gt;use vars qw($MP);&lt;br/&gt;&lt;br/&gt;$| = 1; # unbuffer output&lt;br/&gt;&lt;br/&gt;# Shutdown the Matrix Pricer first&lt;br/&gt;$ua = LWP::UserAgent-&amp;gt;new;&lt;br/&gt;my $response = $ua-&amp;gt;request(POST "http://localhost:8251/shutdown", [username =&amp;gt; 'rdgadmin', confirm =&amp;gt; 'yes']);&lt;br/&gt;&lt;br/&gt;if(!$response-&amp;gt;is_success)&lt;br/&gt;{&lt;br/&gt;        print STDERR "ERROR - could not shut down DMSwaps MatrixPricer\n";&lt;br/&gt;}&lt;br/&gt;&lt;br/&gt;# sleep for a minute so the PMT has no chance to restart it.&lt;br/&gt;sleep(60);&lt;br/&gt;&lt;br/&gt;exit(0);&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;/font&gt;&lt;/small&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-2307107848895312321?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/2307107848895312321/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2008/12/perl-code-to-initiate-shutdown-from.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/2307107848895312321'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/2307107848895312321'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2008/12/perl-code-to-initiate-shutdown-from.html' title='Perl code to initiate a shutdown from website'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-2664042498708720093</id><published>2008-12-04T19:33:00.000+05:30</published><updated>2008-12-04T19:35:01.945+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Find the start in the circular shifted array</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;A sorted array, with over a million elements in it, is rotated clockwise. Find out the index where the sorted list starts.&lt;br /&gt;&lt;br /&gt;&lt;pre name='code' class='c'&gt;&lt;br /&gt;&lt;br /&gt;int find_index(int *a,int start,int end)&lt;br /&gt;{&lt;br /&gt;   int mid = (start+end)/2;&lt;br /&gt;   if (a[start] &amp;lt; a[mid] &amp;lt; a[end])&lt;br /&gt;      return start;&lt;br /&gt;   else if(a[start] &amp;gt; a[mid])&lt;br /&gt;      return find_index(a, start, mid);&lt;br /&gt;   else if(a[mid] &amp;gt; a[end])&lt;br /&gt;      return find_index(a, mid, end);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-2664042498708720093?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/2664042498708720093/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2008/12/find-start-in-circular-shifted-array.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/2664042498708720093'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/2664042498708720093'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2008/12/find-start-in-circular-shifted-array.html' title='Find the start in the circular shifted array'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-1714270810357110630</id><published>2008-12-04T18:33:00.001+05:30</published><updated>2008-12-04T18:39:56.620+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Compute no of digits after '.' in float</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;Compute the number of digits after '.' in a floating point number.&lt;br /&gt;&lt;br /&gt;e.g. if given 3.554 output=3&lt;br /&gt;for 43.000 output=0&lt;br /&gt;&lt;pre name='code' class='c'&gt;&lt;br /&gt;&lt;br /&gt;double no = 3.44;&lt;br /&gt;int count = 0;&lt;br /&gt;while(no!=((int)no))&lt;br /&gt;{&lt;br /&gt; count++;&lt;br /&gt; no=no*10;&lt;br /&gt;}&lt;br /&gt;printf("%d",count);&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-1714270810357110630?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/1714270810357110630/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2008/12/compute-number-of-digits-after.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/1714270810357110630'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/1714270810357110630'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2008/12/compute-number-of-digits-after.html' title='Compute no of digits after &amp;#39;.&amp;#39; in float'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-9162118345731328709</id><published>2008-12-03T20:49:00.000+05:30</published><updated>2008-12-03T20:50:59.641+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Reduce the comparisons in Binary Search</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;&lt;font face='verdana'&gt;&lt;small&gt;Normally there will be 2 comparisons that will be made in Binary Search Algorithm like&lt;br/&gt;&lt;br/&gt;if(value &amp;gt; array[mid])&lt;br/&gt;   low = mid&lt;br/&gt;else (value &amp;lt; array[mid])&lt;br/&gt;   high = mid&lt;br/&gt;else (value == array[mid])&lt;br/&gt;   found the value&lt;br/&gt;&lt;br/&gt;we have to reduce the number of comparisons made in the above code.&lt;br/&gt;&lt;br/&gt;&lt;/small&gt;&lt;/font&gt;&lt;blockquote&gt;&lt;font face='verdana'&gt;&lt;small&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/small&gt;&lt;/font&gt;&lt;br/&gt;&lt;br/&gt;&lt;font face='verdana'&gt;&lt;small&gt;int array [ ] = { 0, 1,2,3,4,5,6,7,8,9 };&lt;/small&gt;&lt;/font&gt;&lt;br/&gt;&lt;font face='verdana'&gt;&lt;small&gt;int bin_search(int val)&lt;/small&gt;&lt;/font&gt;&lt;br/&gt;&lt;font face='verdana'&gt;&lt;small&gt;{&lt;/small&gt;&lt;/font&gt;&lt;br/&gt;&lt;font face='verdana'&gt;&lt;small&gt;    int low=0;&lt;/small&gt;&lt;/font&gt;&lt;br/&gt;&lt;font face='verdana'&gt;&lt;small&gt;    int high = sizeof(array)/sizeof(array[0]) - 1;&lt;/small&gt;&lt;/font&gt;&lt;br/&gt;&lt;font face='verdana'&gt;&lt;small&gt;    int mid;&lt;/small&gt;&lt;/font&gt;&lt;br/&gt;&lt;font face='verdana'&gt;&lt;small&gt;    while(low &amp;lt; high)&lt;/small&gt;&lt;/font&gt;&lt;br/&gt;&lt;font face='verdana'&gt;&lt;small&gt;    {&lt;/small&gt;&lt;/font&gt;&lt;br/&gt;&lt;font face='verdana'&gt;&lt;small&gt;            mid = (low+high)/2 ;&lt;/small&gt;&lt;/font&gt;&lt;br/&gt;&lt;font face='verdana'&gt;&lt;small&gt;            if(array[mid]&amp;lt;val)&lt;/small&gt;&lt;/font&gt;&lt;br/&gt;&lt;font face='verdana'&gt;&lt;small&gt;               low = mid+1;&lt;/small&gt;&lt;/font&gt;&lt;br/&gt;&lt;font face='verdana'&gt;&lt;small&gt;            else&lt;/small&gt;&lt;/font&gt;&lt;br/&gt;&lt;font face='verdana'&gt;&lt;small&gt;               high = mid;&lt;/small&gt;&lt;/font&gt;&lt;br/&gt;&lt;font face='verdana'&gt;&lt;small&gt;    }&lt;/small&gt;&lt;/font&gt;&lt;br/&gt;&lt;font face='verdana'&gt;&lt;small&gt;    if(array[low] == val)&lt;/small&gt;&lt;/font&gt;&lt;br/&gt;&lt;font face='verdana'&gt;&lt;small&gt;    {&lt;/small&gt;&lt;/font&gt;&lt;br/&gt;&lt;font face='verdana'&gt;&lt;small&gt;       return val; // found the value&lt;/small&gt;&lt;/font&gt;&lt;br/&gt;&lt;font face='verdana'&gt;&lt;small&gt;    }&lt;/small&gt;&lt;/font&gt;&lt;br/&gt;&lt;font face='verdana'&gt;&lt;small&gt;    else&lt;/small&gt;&lt;/font&gt;&lt;br/&gt;&lt;font face='verdana'&gt;&lt;small&gt;       return -1; // not found&lt;/small&gt;&lt;/font&gt;&lt;br/&gt;&lt;font face='verdana'&gt;&lt;small&gt;}&lt;/small&gt;&lt;/font&gt;&lt;br/&gt;&lt;font face='verdana'&gt;&lt;small&gt;int main()&lt;/small&gt;&lt;/font&gt;&lt;br/&gt;&lt;font face='verdana'&gt;&lt;small&gt;{&lt;/small&gt;&lt;/font&gt;&lt;br/&gt;&lt;font face='verdana'&gt;&lt;small&gt;    int i;&lt;/small&gt;&lt;/font&gt;&lt;br/&gt;&lt;font face='verdana'&gt;&lt;small&gt;    for( i=0; i&amp;lt; 11; ++i)&lt;/small&gt;&lt;/font&gt;&lt;br/&gt;&lt;font face='verdana'&gt;&lt;small&gt;            printf("Return: %d\n", bin_search(i));&lt;/small&gt;&lt;/font&gt;&lt;br/&gt;&lt;font face='verdana'&gt;&lt;small&gt;    &lt;/small&gt;&lt;/font&gt;&lt;br/&gt;&lt;font face='verdana'&gt;&lt;small&gt;    return 0;&lt;/small&gt;&lt;/font&gt;&lt;br/&gt;&lt;font face='verdana'&gt;&lt;small&gt;}&lt;/small&gt;&lt;/font&gt;&lt;br/&gt;&lt;/blockquote&gt;&lt;font face='verdana'&gt;&lt;small&gt;&lt;br/&gt;&lt;/small&gt;&lt;/font&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-9162118345731328709?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/9162118345731328709/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2008/12/reduce-comparisons-in-binary-search_8956.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/9162118345731328709'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/9162118345731328709'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2008/12/reduce-comparisons-in-binary-search_8956.html' title='Reduce the comparisons in Binary Search'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-4783559940108985913</id><published>2008-10-25T01:46:00.004+05:30</published><updated>2008-10-25T01:52:39.760+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Random Thoughts'/><title type='text'></title><content type='html'>Writing a post after a very long time .. not because I dont have time but its basically I'm not a good writer :)&lt;br /&gt;&lt;br /&gt;It is a very long day for me today .. yup the time is 4 AM in the morning .. and we are 3 people still awaken ..Just finished watching Saroja and Happy Days .. both the films are worth watching it again ..&lt;br /&gt;&lt;br /&gt;I was thinking about Saran (probably becoz of his poor Telegu) when I was watching Happy Days, and we watched the same movie in PVR Hyderabad .. Missing all those days guys ..&lt;br /&gt;&lt;br /&gt;Hey, i got a good print of these two movies .. if you need to watch this movie, I can start seeding ...&lt;br /&gt;&lt;br /&gt;Hope everyone in Hyderabad would be heading home for Dewali, enjoy guys .. and Happy Dewali ..&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-4783559940108985913?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/4783559940108985913/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2008/10/writing-post-after-very-long-time.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/4783559940108985913'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/4783559940108985913'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2008/10/writing-post-after-very-long-time.html' title=''/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-5898087202838606142</id><published>2008-06-11T12:17:00.004+05:30</published><updated>2008-06-11T14:56:38.962+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Swap two pointers</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;Our task is to two pointers which is pointing to two objects. The problem is very simple and remember to use &lt;em&gt;pointer to pointer concept&lt;/em&gt;. Without that it is just a pass by value to the function.&lt;br/&gt;&lt;pre class='c' name='code'&gt;&lt;br/&gt;&lt;br/&gt;#include&amp;lt;stdio.h&amp;amp;gt;&lt;br/&gt;void swap(int **firstPtr, int **secondPtr)&lt;br/&gt;{&lt;br/&gt; int *temp = *firstPtr;&lt;br/&gt; *firstPtr = *secondPtr;&lt;br/&gt; *secondPtr = temp;&lt;br/&gt;&lt;br/&gt; return;&lt;br/&gt;}&lt;br/&gt;&lt;br/&gt;int main()&lt;br/&gt;{&lt;br/&gt; int a = 10;&lt;br/&gt; int b = 20;&lt;br/&gt;&lt;br/&gt; int *aPtr = &amp;amp;a;&lt;br/&gt; int *bPtr = &amp;amp;b;&lt;br/&gt;&lt;br/&gt; printf("Before Swapping, Address : %x %x, Value : %d %d\n", aPtr, bPtr, *aPtr, *bPtr);&lt;br/&gt; swap(&amp;amp;aPtr, &amp;amp;bPtr);&lt;br/&gt; printf("After  Swapping, Address : %x %x, Value : %d %d\n", aPtr, bPtr, *aPtr, *bPtr);&lt;br/&gt;}&lt;br/&gt;&lt;/pre&gt;&lt;br/&gt;If you compile and see the result, the pointers would be swapped ..&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-5898087202838606142?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/5898087202838606142/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2008/06/swap-pointers.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/5898087202838606142'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/5898087202838606142'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2008/06/swap-pointers.html' title='Swap two pointers'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-6764687745080932834</id><published>2008-06-10T17:09:00.002+05:30</published><updated>2008-06-11T14:55:10.336+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Write your own tail -n implementation</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;&lt;span style='font-family: verdana;'&gt;This is one of the question asked in Adobe to my friend. You need to implement your own tail function. read the man page for more information about tail command.&lt;br /&gt;&lt;br /&gt;I could able to think of two ways to solve the problem. [tail -n 10 filename ]&lt;br /&gt;&lt;br /&gt;&lt;u&gt;&lt;b&gt;Solution 1:&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;&lt;br /&gt;Keep 2 pointers, 1st points to the start of the file, the 2nd points to the n+1 th line :&lt;br /&gt;&lt;br /&gt; if the file is not big enough [ less than n ] then dump the content of the file from the beginning to the end of the file and return&lt;br /&gt; else move the second pointer by one line and move the 1st pointer by one until the second reaches EOF. One the 2nd pointer reaches the end of the file, dump the content from where the 1st pointer currently pointing till the end of the file.&lt;br /&gt;&lt;br /&gt;This is one of the solution me and Arun discussed when I was there in Hyderabad. But there are lot of improvements that we can do in this and the companies expect such kind of answers (just for the interview sake)&lt;br /&gt;&lt;br /&gt;&lt;u&gt;&lt;i&gt;&lt;b&gt;Problem:&lt;/b&gt;&lt;/i&gt;&lt;/u&gt;&lt;i&gt; &lt;/i&gt;One of the biggest problem with the above solution is the performance. Both the pointers are reading the same content (2 times reading the same content). Since disk I/O is costly this is a real performance issue.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;u&gt;&lt;b&gt;Solution 2 :&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;&lt;br /&gt;The next solution is instead of reading from the file twice, create a buffer to hold the content, read the file from the end of the file and dump it into the buffer, also keep track of the no of lines read so far from the end. Once the required no of lines read, print the content of the buffer from the end.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;i&gt;&lt;u&gt;&lt;b&gt;My Implementation :&lt;/b&gt;&lt;/u&gt;&lt;/i&gt;&lt;br /&gt;&lt;pre class='c' name='code'&gt;&lt;br /&gt;&lt;br /&gt;#include &amp;lt;stdio.h&amp;amp;gt;&lt;br /&gt;#include &amp;lt;stdlib.h&amp;amp;gt;&lt;br /&gt;#include &amp;lt;string.h&amp;amp;gt;&lt;br /&gt;#include &amp;lt;sys types.h&amp;gt;&lt;br /&gt;#include &amp;lt;sys stat.h&amp;gt;&lt;br /&gt;#include &amp;lt;fcntl.h&amp;amp;gt;&lt;br /&gt;&lt;br /&gt;void tail(int lines, char *file_name)&lt;br /&gt;{&lt;br /&gt;      struct stat file;&lt;br /&gt;      int size = 0;&lt;br /&gt;      char *ch = NULL;&lt;br /&gt;      char *buf = NULL;&lt;br /&gt;&lt;br /&gt;      FILE *fd = fopen(file_name, "r");&lt;br /&gt;&lt;br /&gt;      if(fd == NULL)&lt;br /&gt;      {&lt;br /&gt;              printf("Not able to open the file : %s\n", file_name);&lt;br /&gt;              return;&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;      // Set the pointer to the end&lt;br /&gt;      fseek(fd, 0, SEEK_END);&lt;br /&gt;&lt;br /&gt;      // Find the size of the file&lt;br /&gt;      size = ftell(fd);&lt;br /&gt;      --size;&lt;br /&gt;&lt;br /&gt;      // Allocate the buffer to hold the content&lt;br /&gt;      ch = (char *)malloc(2);&lt;br /&gt;      buf = (char *)malloc(80 * lines);&lt;br /&gt;      memset(buf, 0, 80 * lines);&lt;br /&gt;&lt;br /&gt;      char * start = buf;&lt;br /&gt;      *buf++ = '\0';&lt;br /&gt;&lt;br /&gt;      // Copy the file content from the end of the file in the reverse order into the buffer&lt;br /&gt;      // Use fseek --&amp;gt; SEEK_SET to navigate the file from the back&lt;br /&gt;&lt;br /&gt;      while(size &amp;amp;&amp;amp; lines)&lt;br /&gt;      {&lt;br /&gt;              --size;&lt;br /&gt;              fseek(fd, size , SEEK_SET);&lt;br /&gt;              fread(ch, 1, 1, fd);&lt;br /&gt;              *buf++ = *ch;&lt;br /&gt;              if(*ch == '\n')&lt;br /&gt;                      lines--;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;      }&lt;br /&gt;      close(fd);&lt;br /&gt;&lt;br /&gt;      // Print the content of the buffer&lt;br /&gt;      while( start != buf)&lt;br /&gt;              printf("%c", *buf--);&lt;br /&gt;&lt;br /&gt;      printf("\n");&lt;br /&gt;      return;&lt;br /&gt;}&lt;br /&gt;int main(int argc, char **argv)&lt;br /&gt;{&lt;br /&gt;      if(argc != 3)&lt;br /&gt;      {&lt;br /&gt;              printf("Run exe file_name no_of_lines\n");&lt;br /&gt;              return (-1);&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;      char *file = argv[1];&lt;br /&gt;      tail(atoi(argv[2]), file);&lt;br /&gt;&lt;br /&gt;      return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;u&gt;&lt;b&gt;input file :&lt;/b&gt;&lt;/u&gt;cat ganesh&lt;br /&gt;1 Ganesh&lt;br /&gt;2 Vishnu&lt;br /&gt;3 Ramak&lt;br /&gt;4 Arun&lt;br /&gt;5 Jerome&lt;br /&gt;&lt;br /&gt;&lt;u&gt;&lt;b&gt;Output:&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;&lt;br /&gt;# ./a ganesh 2&lt;br /&gt;&lt;br /&gt;4 Arun&lt;br /&gt;5 Jerome&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style='font-family: verdana;'&gt;# ./a ganesh 4&lt;br /&gt;&lt;br /&gt;2 Vishnu&lt;br /&gt;3 Ramak&lt;br /&gt;4 Arun&lt;br /&gt;5 Jerome&lt;br /&gt;&lt;br /&gt;./a ganesh 10&lt;br /&gt;1 Ganesh&lt;br /&gt;2 Vishnu&lt;br /&gt;3 Ramak&lt;br /&gt;4 Arun&lt;br /&gt;5 Jerome&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style='color: rgb(255, 204, 0);'&gt;PS : Guys don't get envy that I wrote a big program for myself. I struggled a lot to make this program to work :-)&lt;/span&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-6764687745080932834?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/6764687745080932834/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2008/06/implement-your-own-tail-functionality.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/6764687745080932834'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/6764687745080932834'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2008/06/implement-your-own-tail-functionality.html' title='Write your own tail -n implementation'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-4617826732085162856</id><published>2008-06-10T17:04:00.001+05:30</published><updated>2008-06-10T17:04:50.122+05:30</updated><title type='text'>Reverse the bits in a number</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;The problem is to reverse the bits in a number. &lt;br /&gt;Example : 1011 should be reversed as 1101&lt;br /&gt;&lt;br /&gt;&lt;pre name='code' class='c'&gt;&lt;br /&gt;#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;void bit_form(unsigned int value)&lt;br /&gt;{&lt;br /&gt;            while(value)&lt;br /&gt;            {&lt;br /&gt;                   printf("%d", value &amp;amp; 0x01);&lt;br /&gt;                    value = value &amp;gt;&amp;gt;1;&lt;br /&gt;            }&lt;br /&gt;            printf("\n");&lt;br /&gt;            return;&lt;br /&gt;}&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;        unsigned int value = 0;&lt;br /&gt;        scanf("%d", &amp;amp;value);&lt;br /&gt;        unsigned int return_value = value;&lt;br /&gt;        int loop = sizeof(value) * CHAR_BIT - 1;&lt;br /&gt;&lt;br /&gt;        bit_form(value);&lt;br /&gt;&lt;br /&gt;        for(value &amp;gt;&amp;gt;= 1; value; value &amp;gt;&amp;gt;= 1)&lt;br /&gt;        {&lt;br /&gt;                return_value &amp;lt;&amp;lt;= 1;&lt;br /&gt;                return_value |= value &amp;amp; 1;&lt;br /&gt;                loop--;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        return_value &amp;lt;&amp;lt;= loop;&lt;br /&gt;        bit_form(return_value);&lt;br /&gt;        return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-4617826732085162856?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/4617826732085162856/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2008/06/reverse-bits-in-number_10.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/4617826732085162856'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/4617826732085162856'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2008/06/reverse-bits-in-number_10.html' title='Reverse the bits in a number'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-7352306455454095123</id><published>2008-06-10T13:47:00.001+05:30</published><updated>2008-06-10T13:47:43.708+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Fast Exponentation</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;We need to compute the value of a^&lt;em&gt;n&lt;/em&gt;, for some reasonable large value of n.&lt;br /&gt;&lt;br /&gt;The simplest algorithm that we know is computing axaxax ... xa (up to n times). However we can do this better by observing that n = [n/2] * [n/2]. If n is even, then a^n = [a^n/2]^2. If n is odd, then a^n = a * [a^n/2]^2. In either case we have halved the size of our computation. so &lt;em&gt;O(log n)&lt;/em&gt; multiplications suffice to compute the final value.&lt;br /&gt;&lt;br /&gt;&lt;u&gt;&lt;b&gt;Code :&lt;/b&gt; &lt;/u&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class='c' name='code'&gt;&lt;br /&gt;&lt;br /&gt;#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;int power(int n, int e)&lt;br /&gt;{&lt;br /&gt;        int res;&lt;br /&gt;&lt;br /&gt;        if(n == 0)&lt;br /&gt;                return 0;&lt;br /&gt;        if(e == 0)&lt;br /&gt;                return 1;&lt;br /&gt;&lt;br /&gt;        res = power(n, e/2);&lt;br /&gt;&lt;br /&gt;        if( e%2 ) // ODD&lt;br /&gt;        {&lt;br /&gt;                return n * res * res;&lt;br /&gt;        }&lt;br /&gt;        else // Even&lt;br /&gt;                return res * res;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;        int number;&lt;br /&gt;        int expon;&lt;br /&gt;        int result;&lt;br /&gt;&lt;br /&gt;        printf("Enter the number :");&lt;br /&gt;        scanf("%d", &amp;amp;number);&lt;br /&gt;&lt;br /&gt;        printf("Enter the exponent :");&lt;br /&gt;        scanf("%d", &amp;amp;expon);&lt;br /&gt;        result = power(number, expon);&lt;br /&gt;&lt;br /&gt;        printf("%d ^ %d is : %d\n", number, expon, result);&lt;br /&gt;        return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-7352306455454095123?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/7352306455454095123/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2008/06/fast-exponentation.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/7352306455454095123'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/7352306455454095123'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2008/06/fast-exponentation.html' title='Fast Exponentation'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-8392068643718474359</id><published>2008-06-10T11:51:00.015+05:30</published><updated>2008-06-10T13:25:41.660+05:30</updated><title type='text'></title><content type='html'>I am working hard to make my syntax highlighter to work .. this is yet another shot ..&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="c"&gt;&lt;br /&gt;&lt;br /&gt;#include &amp;lt;iostream.h&amp;gt;&lt;br /&gt;&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;  return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Yeah !! It worked at last ..&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-8392068643718474359?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/8392068643718474359/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2008/06/test.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/8392068643718474359'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/8392068643718474359'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2008/06/test.html' title=''/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-7118149566109833776</id><published>2008-06-09T19:43:00.002+05:30</published><updated>2008-06-11T12:06:35.863+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Implement your own tail functionality</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;&lt;span style='font-family: verdana;'&gt;This is one of the question asked in Adobe to my friend. You need to implement your own tail function. read the man page for more information about tail command.&lt;br /&gt;&lt;br /&gt;I could able to think of two ways to solve the problem. [tail -n 10 filename ]&lt;br /&gt;&lt;br /&gt;&lt;u&gt;&lt;b&gt;Solution 1:&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;&lt;br /&gt;Keep 2 pointers, 1st points to the start of the file, the 2nd points to the n+1 th line :&lt;br /&gt;&lt;br /&gt;  if the file is not big enough [ less than n ] then dump the content of the file from the beginning to the end of the file and return&lt;br /&gt;  else move the second pointer by one line and move the 1st pointer by one until the second reaches EOF. One the 2nd pointer reaches the end of the file, dump the content from where the 1st pointer currently pointing till the end of the file.&lt;br /&gt;&lt;br /&gt;This is one of the solution me and Arun discussed when I was there in Hyderabad. But there are lot of improvements that we can do in this and the companies expect such kind of answers (just for the interview sake)&lt;br /&gt;&lt;br /&gt;&lt;u&gt;&lt;i&gt;&lt;b&gt;Problem:&lt;/b&gt;&lt;/i&gt;&lt;/u&gt;&lt;i&gt; &lt;/i&gt;One of the biggest problem with the above solution is the performance. Both the pointers are reading the same content (2 times reading the same content). Since disk I/O is costly this is a real performance issue.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;u&gt;&lt;b&gt;Solution 2 :&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;&lt;br /&gt;The next solution is instead of reading from the file twice, create a buffer to hold the content, read the file from the end of the file and dump it into the buffer, also keep track of the no of lines read so far from the end. Once the required no of lines read, print the content of the buffer from the end.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;i&gt;&lt;u&gt;&lt;b&gt;My Implementation :&lt;/b&gt;&lt;/u&gt;&lt;/i&gt;&lt;br /&gt;&lt;pre class='c' name='code'&gt;&lt;br /&gt;&lt;br /&gt;#include &amp;lt;stdio.h&amp;amp;gt;&lt;br /&gt;#include&amp;lt;stdlib.h&amp;amp;gt;&lt;br /&gt;#include&amp;lt;string.h&amp;amp;gt;&lt;br /&gt;#include&amp;lt;sys/types.h&amp;amp;gt;&lt;br /&gt;#include&amp;lt;sys/stat.h&amp;amp;gt;&lt;br /&gt;#include&amp;lt;fcntl.h&amp;amp;gt;&lt;br /&gt;&lt;br /&gt;void tail(int lines, char *file_name)&lt;br /&gt;{&lt;br /&gt;       struct stat file;&lt;br /&gt;       int size = 0;&lt;br /&gt;       char *ch = NULL;&lt;br /&gt;       char *buf = NULL;&lt;br /&gt;&lt;br /&gt;       FILE *fd = fopen(file_name, "r");&lt;br /&gt;&lt;br /&gt;       if(fd == NULL)&lt;br /&gt;       {&lt;br /&gt;               printf("Not able to open the file : %s\n", file_name);&lt;br /&gt;               return;&lt;br /&gt;       }&lt;br /&gt;&lt;br /&gt;       // Set the pointer to the end&lt;br /&gt;       fseek(fd, 0, SEEK_END);&lt;br /&gt;&lt;br /&gt;       // Find the size of the file&lt;br /&gt;       size = ftell(fd);&lt;br /&gt;       --size;&lt;br /&gt;&lt;br /&gt;       // Allocate the buffer to hold the content&lt;br /&gt;       ch = (char *)malloc(2);&lt;br /&gt;       buf = (char *)malloc(80 * lines);&lt;br /&gt;       memset(buf, 0, 80 * lines);&lt;br /&gt;&lt;br /&gt;       char * start = buf;&lt;br /&gt;       *buf++ = '\0';&lt;br /&gt;&lt;br /&gt;       // Copy the file content from the end of the file in the reverse order into the buffer&lt;br /&gt;       // Use fseek --&amp;gt; SEEK_SET to navigate the file from the back&lt;br /&gt;&lt;br /&gt;       while(size &amp;amp;&amp;amp; lines)&lt;br /&gt;       {&lt;br /&gt;               --size;&lt;br /&gt;               fseek(fd, size , SEEK_SET);&lt;br /&gt;               fread(ch, 1, 1, fd);&lt;br /&gt;               *buf++ = *ch;&lt;br /&gt;               if(*ch == '\n')&lt;br /&gt;                       lines--;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;       }&lt;br /&gt;       close(fd);&lt;br /&gt;&lt;br /&gt;       // Print the content of the buffer&lt;br /&gt;       while( start != buf)&lt;br /&gt;               printf("%c", *buf--);&lt;br /&gt;&lt;br /&gt;       printf("\n");&lt;br /&gt;       return;&lt;br /&gt;}&lt;br /&gt;int main(int argc, char **argv)&lt;br /&gt;{&lt;br /&gt;       if(argc != 3)&lt;br /&gt;       {&lt;br /&gt;               printf("Run exe file_name no_of_lines\n");&lt;br /&gt;               return (-1);&lt;br /&gt;       }&lt;br /&gt;&lt;br /&gt;       char *file = argv[1];&lt;br /&gt;       tail(atoi(argv[2]), file);&lt;br /&gt;&lt;br /&gt;       return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;u&gt;&lt;b&gt;input file :&lt;/b&gt;&lt;/u&gt;cat ganesh&lt;br /&gt;1 Ganesh&lt;br /&gt;2 Vishnu&lt;br /&gt;3 Ramak&lt;br /&gt;4 Arun&lt;br /&gt;5 Jerome&lt;br /&gt;&lt;br /&gt;&lt;u&gt;&lt;b&gt;Output:&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;&lt;br /&gt;# ./a ganesh 2&lt;br /&gt;&lt;br /&gt;4 Arun&lt;br /&gt;5 Jerome&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style='font-family: verdana;'&gt;# ./a ganesh 4&lt;br /&gt;&lt;br /&gt;2 Vishnu&lt;br /&gt;3 Ramak&lt;br /&gt;4 Arun&lt;br /&gt;5 Jerome&lt;br /&gt;&lt;br /&gt;./a ganesh 10&lt;br /&gt;1 Ganesh&lt;br /&gt;2 Vishnu&lt;br /&gt;3 Ramak&lt;br /&gt;4 Arun&lt;br /&gt;5 Jerome&lt;br /&gt;&lt;br /&gt;&lt;u&gt;&lt;b/&gt;&lt;/u&gt;&lt;b&gt;&lt;span style='color: rgb(255, 204, 0);'&gt;PS : Guys don't get envy that I wrote a big program for myself. I struggled a lot to make this program to work :-)&lt;/span&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-7118149566109833776?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/7118149566109833776/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2008/06/implement-your-own-function.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/7118149566109833776'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/7118149566109833776'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2008/06/implement-your-own-function.html' title='Implement your own tail functionality'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-5741422396532403050</id><published>2008-06-02T12:05:00.001+05:30</published><updated>2008-06-02T12:10:37.282+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Misc'/><title type='text'></title><content type='html'>Aiyoo Aiyoo ..&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;One of the Ultimate comedies of TR :&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;object height="355" width="425"&gt;&lt;param name="movie" value="http://www.youtube.com/v/E0vqUdlrc_I"&gt;&lt;param name="wmode" value="transparent"&gt;&lt;embed src="http://www.youtube.com/v/E0vqUdlrc_I" type="application/x-shockwave-flash" wmode="transparent" height="355" width="425"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-5741422396532403050?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/5741422396532403050/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2008/06/aiyoo-aiyoo.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/5741422396532403050'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/5741422396532403050'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2008/06/aiyoo-aiyoo.html' title=''/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-846104809848000517</id><published>2008-04-25T14:31:00.002+05:30</published><updated>2008-04-25T14:39:19.389+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='VIM'/><title type='text'></title><content type='html'>Commenting out large code in VIM.&lt;br /&gt;&lt;br /&gt;Whenever I need to comment out (C++ style comment //) a large codes in VIM editor, I usually comment out the first line and then go to the next line, then press '.' to repeat the same. But today I found another way to do the same.&lt;br /&gt;&lt;br /&gt;Ctrl-v&lt;br /&gt;96[ press down arrow key]&lt;br /&gt;Shift-i&lt;br /&gt;# or //&lt;br /&gt;[Esc]&lt;br /&gt;&lt;br /&gt;This puts the editor into visual block mode, jumps down 96 lines, puts the editor into insert mode, and then inserts whatever you typed at the beginning of all 96 selected lines. All in 9 key-presses. Not bad!&lt;br /&gt;&lt;br /&gt;You can also uncomment with the following:&lt;br /&gt;&lt;br /&gt;Ctrl-v&lt;br /&gt;96[down]&lt;br /&gt;x&lt;br /&gt;[Esc]&lt;br /&gt;&lt;br /&gt;Nice hacking .. let me know if there are any other ways to do the same ..&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-846104809848000517?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/846104809848000517/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2008/04/commenting-out-large-code-in-vim.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/846104809848000517'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/846104809848000517'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2008/04/commenting-out-large-code-in-vim.html' title=''/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-6615053344619977732</id><published>2008-03-27T11:36:00.007+05:30</published><updated>2008-04-02T11:00:42.333+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Syntax Highlighter'/><title type='text'></title><content type='html'>&lt;pre ='code' class='c++'&gt;&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;cout&lt;&lt;"Hello World";&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-6615053344619977732?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/6615053344619977732/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2008/03/int-main-printfhello-world.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/6615053344619977732'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/6615053344619977732'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2008/03/int-main-printfhello-world.html' title=''/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-7230740678167258222</id><published>2008-02-18T17:40:00.001+05:30</published><updated>2008-02-18T17:40:00.133+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Linux'/><title type='text'>Linux Chear Sheets</title><content type='html'>&lt;span style="font-family: Verdana;"&gt;The below site contains the Ultimate collection of cheat sheets :&lt;/span&gt;&lt;br style="font-family: Verdana;" /&gt;&lt;br style="font-family: Verdana;" /&gt;&lt;a href="http://www.scottklarr.com/topic/115/linux-unix-cheat-sheets---the-ultimate-collection/"&gt;&lt;span style="font-family: Verdana;"&gt;http://www.scottklarr.com/topic/115/linux-unix-cheat-sheets---the-ultimate-collection/&lt;/span&gt;&lt;/a&gt;&lt;br style="font-family: Verdana;" /&gt;&lt;br /&gt;  &lt;p style="text-align: right; font-size: 8px"&gt;Blogged with &lt;a href="http://www.flock.com/blogged-with-flock" title="Flock" target="_new"&gt;Flock&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-7230740678167258222?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/7230740678167258222/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2008/02/linux-chear-sheets.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/7230740678167258222'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/7230740678167258222'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2008/02/linux-chear-sheets.html' title='Linux Chear Sheets'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-2923597710643121379</id><published>2007-12-27T20:35:00.001+05:30</published><updated>2007-12-27T20:35:32.176+05:30</updated><title type='text'>Gotta Digg</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;&lt;p&gt;&lt;object height='350' width='425'&gt;&lt;param value='http://youtube.com/v/LZU2QBhf0xg' name='movie'/&gt;&lt;embed height='350' width='425' type='application/x-shockwave-flash' src='http://youtube.com/v/LZU2QBhf0xg'/&gt;&lt;/object&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;br /&gt;The song, which is pretty damned good, is performed by Kina Grannis. Here are the lyrics (and hear Kina’s other songs here):&lt;br /&gt;&lt;br /&gt;    When I’m feeling lazy, at school or when I work&lt;br /&gt;    I sneak to my computer, and then I like to shirk&lt;br /&gt;    I don’t go online shopping, I don’t email with my mom&lt;br /&gt;    I open up my browser, and go to digg-dot-com&lt;br /&gt;&lt;br /&gt;    Chorus: Gotta digg, gotta digg, gotta digg&lt;br /&gt;    Gotta make this story big!&lt;br /&gt;    Did you hear that awful sound?&lt;br /&gt;    Another server’s down!&lt;br /&gt;&lt;br /&gt;    I always dig up Apple, and I bury Microsoft&lt;br /&gt;    But when I said I was a girl, all the diggers scoffed&lt;br /&gt;    And when I see those stories about Senator Ron Paul&lt;br /&gt;    I don’t even RTFA; I just digg them all!&lt;br /&gt;&lt;br /&gt;    Chorus: Gotta digg, gotta digg, gotta digg&lt;br /&gt;    Gotta make this story big!&lt;br /&gt;    Did you hear that awful sound?&lt;br /&gt;    Another server’s down!&lt;br /&gt;&lt;br /&gt;    The fanboys can be tiresome, they always are outspoken&lt;br /&gt;    And if you’re listening Kevin Rose, the comment system’s broken!&lt;br /&gt;    I know digg isn’t perfect, but be thankful for what we’ve got&lt;br /&gt;    It’s just like daddy always says: “At least it’s not Slashdot!!!”&lt;br /&gt;    Chorus: Gotta digg, gotta digg, gotta digg&lt;br /&gt;    Gotta make this story big!&lt;br /&gt;    Did you hear that awful sound?&lt;br /&gt;    Another server’s down!&lt;/p&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-2923597710643121379?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/2923597710643121379/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2007/12/gotta-digg.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/2923597710643121379'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/2923597710643121379'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2007/12/gotta-digg.html' title='Gotta Digg'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-3388265695809989139</id><published>2007-11-26T20:30:00.001+05:30</published><updated>2007-11-26T20:30:43.115+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Is Valid BST ?</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;&lt;br /&gt;  Given a tree, how t o find out if it is Binary Search Tree or not?&lt;br/&gt;&lt;br/&gt;&lt;h3 class='smller'&gt;two methods&lt;/h3&gt;&lt;br /&gt;  &lt;div class='para'&gt;&lt;br /&gt;  1. Run inorder traversal on the tree and check if the resulting array is sorted or not.&lt;br/&gt;&lt;br/&gt;2. For every node check if the Max of left subtree &amp;amp;lt; the value at node and if min of right subtree&amp;amp;gt; value at root.&lt;br/&gt;&lt;br/&gt;Simple Solution:&lt;br/&gt;&lt;br/&gt;boolean isBST(Node *root)&lt;br/&gt;{&lt;br/&gt; return (root == null || (&lt;br /&gt;(root-&amp;amp;gt;left == null || (root-&amp;amp;gt;left-&amp;amp;gt;data &amp;amp;lt; root-&amp;amp;gt;data&lt;br /&gt;&amp;amp;&amp;amp; isBST(root-&amp;amp;gt;left))) &amp;amp;&amp;amp; (root-&amp;amp;gt;right == null ||&lt;br /&gt;(root-&amp;amp;gt;right-&amp;amp;gt;data &amp;amp;gt; root-&amp;amp;gt;data &amp;amp;&amp;amp;&lt;br /&gt;isBST(root-&amp;amp;gt;right)))));&lt;br/&gt;}&lt;br/&gt;&lt;/div&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p class='poweredbyperformancing'&gt;Powered by &lt;a href='http://scribefire.com/'&gt;ScribeFire&lt;/a&gt;.&lt;/p&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-3388265695809989139?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/3388265695809989139/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2007/11/is-valid-bst.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/3388265695809989139'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/3388265695809989139'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2007/11/is-valid-bst.html' title='Is Valid BST ?'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-8721188852860064095</id><published>2007-10-29T14:31:00.001+05:30</published><updated>2007-10-29T14:31:49.296+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Bash'/><title type='text'>Simple Bash Scripts I find useful</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;&lt;p&gt;bash scriptlet to sort recursively by Time&lt;br/&gt;&lt;br /&gt;find . -printf ‘%CY-%Cm-%Cd:%CT %p\n’ | sort &lt;/p&gt;&lt;br /&gt;&lt;p&gt;Found a great collection:&lt;/p&gt;&lt;br /&gt;&lt;p&gt;————————————————————————-&lt;br/&gt;&lt;br /&gt;HANDY ONE-LINERS FOR SED (Unix stream editor)               Apr. 26, 2004&lt;br/&gt;&lt;br /&gt;compiled by Eric Pement - pemente[at]northpark[dot]edu        version 5.4&lt;br/&gt;&lt;br /&gt;Latest version of this file is usually at:&lt;br/&gt;&lt;span&gt;&lt;br /&gt;   &lt;a href='http://sed.sourceforge.net/sed1line.txt'&gt;http://sed.sourceforge.net/sed1line.txt&lt;/a&gt;&lt;/span&gt;&lt;br/&gt;&lt;span&gt;&lt;br /&gt;   &lt;a href='http://www.student.northpark.edu/pemente/sed/sed1line.txt'&gt;http://www.student.northpark.edu/pemente/sed/sed1line.txt&lt;/a&gt;&lt;/span&gt;&lt;br/&gt;&lt;br /&gt;This file is also available in Portuguese at:&lt;br/&gt;&lt;br /&gt;   http://www.lrv.ufsc.br/wmaker/sed_ptBR.html&lt;/p&gt;&lt;br /&gt;&lt;p&gt;FILE SPACING:&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # double space a file&lt;br/&gt;&lt;br /&gt; sed G&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # double space a file which already has blank lines in it. Output file&lt;br/&gt;&lt;br /&gt; # should contain no more than one blank line between lines of text.&lt;br/&gt;&lt;br /&gt; sed ‘/^$/d;G’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # triple space a file&lt;br/&gt;&lt;br /&gt; sed ‘G;G’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # undo double-spacing (assumes even-numbered lines are always blank)&lt;br/&gt;&lt;br /&gt; sed ‘n;d’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # insert a blank line above every line which matches “regex”&lt;br/&gt;&lt;br /&gt; sed ‘/regex/{x;p;x;}’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # insert a blank line below every line which matches “regex”&lt;br/&gt;&lt;br /&gt; sed ‘/regex/G’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # insert a blank line above and below every line which matches “regex”&lt;br/&gt;&lt;br /&gt; sed ‘/regex/{x;p;x;G;}’&lt;/p&gt;&lt;br /&gt;&lt;p&gt;NUMBERING:&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # number each line of a file (simple left alignment). Using a tab (see&lt;br/&gt;&lt;br /&gt; # note on ‘\t’ at end of file) instead of space will preserve margins.&lt;br/&gt;&lt;br /&gt; sed = filename | sed ‘N;s/\n/\t/’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # number each line of a file (number on left, right-aligned)&lt;br/&gt;&lt;br /&gt; sed = filename | sed ‘N; s/^/     /; s/ *\(.\{6,\}\)\n/\1  /’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # number each line of file, but only print numbers if line is not blank&lt;br/&gt;&lt;br /&gt; sed ‘/./=’ filename | sed ‘/./N; s/\n/ /’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # count lines (emulates “wc -l”)&lt;br/&gt;&lt;br /&gt; sed -n ‘$=’&lt;/p&gt;&lt;br /&gt;&lt;p&gt;TEXT CONVERSION AND SUBSTITUTION:&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # IN UNIX ENVIRONMENT: convert DOS newlines (CR/LF) to Unix format&lt;br/&gt;&lt;br /&gt; sed ’s/.$//’               # assumes that all lines end with CR/LF&lt;br/&gt;&lt;br /&gt; sed ’s/^M$//’              # in bash/tcsh, press Ctrl-V then Ctrl-M&lt;br/&gt;&lt;br /&gt; sed ’s/\x0D$//’            # gsed 3.02.80, but top script is easier&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # IN UNIX ENVIRONMENT: convert Unix newlines (LF) to DOS format&lt;br/&gt;&lt;br /&gt; sed “s/$/`echo -e \\\r`/”            # command line under ksh&lt;br/&gt;&lt;br /&gt; sed ’s/$’”/`echo \\\r`/”             # command line under bash&lt;br/&gt;&lt;br /&gt; sed “s/$/`echo \\\r`/”               # command line under zsh&lt;br/&gt;&lt;br /&gt; sed ’s/$/\r/’                        # gsed 3.02.80&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # IN DOS ENVIRONMENT: convert Unix newlines (LF) to DOS format&lt;br/&gt;&lt;br /&gt; sed “s/$//”                          # method 1&lt;br/&gt;&lt;br /&gt; sed -n p                             # method 2&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # IN DOS ENVIRONMENT: convert DOS newlines (CR/LF) to Unix format&lt;br/&gt;&lt;br /&gt; # Can only be done with UnxUtils sed, version 4.0.7 or higher.&lt;br/&gt;&lt;br /&gt; # Cannot be done with other DOS versions of sed. Use “tr” instead.&lt;br/&gt;&lt;br /&gt; sed “s/\r//” infile &amp;amp;gt;outfile         # UnxUtils sed v4.0.7 or higher&lt;br/&gt;&lt;br /&gt; tr -d \r &lt;infile&gt;outfile            # GNU tr version 1.22 or higher&lt;/infile&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # delete leading whitespace (spaces, tabs) from front of each line&lt;br/&gt;&lt;br /&gt; # aligns all text flush left&lt;br/&gt;&lt;br /&gt; sed ’s/^[ \t]*//’                    # see note on ‘\t’ at end of file&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # delete trailing whitespace (spaces, tabs) from end of each line&lt;br/&gt;&lt;br /&gt; sed ’s/[ \t]*$//’                    # see note on ‘\t’ at end of file&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # delete BOTH leading and trailing whitespace from each line&lt;br/&gt;&lt;br /&gt; sed ’s/^[ \t]*//;s/[ \t]*$//’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # insert 5 blank spaces at beginning of each line (make page offset)&lt;br/&gt;&lt;br /&gt; sed ’s/^/     /’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # align all text flush right on a 79-column width&lt;br/&gt;&lt;br /&gt; sed -e :a -e ’s/^.\{1,78\}$/ &amp;amp;/;ta’  # set at 78 plus 1 space&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # center all text in the middle of 79-column width. In method 1,&lt;br/&gt;&lt;br /&gt; # spaces at the beginning of the line are significant, and trailing&lt;br/&gt;&lt;br /&gt; # spaces are appended at the end of the line. In method 2, spaces at&lt;br/&gt;&lt;br /&gt; # the beginning of the line are discarded in centering the line, and&lt;br/&gt;&lt;br /&gt; # no trailing spaces appear at the end of lines.&lt;br/&gt;&lt;br /&gt; sed  -e :a -e ’s/^.\{1,77\}$/ &amp;amp; /;ta’                     # method 1&lt;br/&gt;&lt;br /&gt; sed  -e :a -e ’s/^.\{1,77\}$/ &amp;amp;/;ta’ -e ’s/\( *\)\1/\1/’  # method 2&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # substitute (find and replace) “foo” with “bar” on each line&lt;br/&gt;&lt;br /&gt; sed ’s/foo/bar/’             # replaces only 1st instance in a line&lt;br/&gt;&lt;br /&gt; sed ’s/foo/bar/4′            # replaces only 4th instance in a line&lt;br/&gt;&lt;br /&gt; sed ’s/foo/bar/g’            # replaces ALL instances in a line&lt;br/&gt;&lt;br /&gt; sed ’s/\(.*\)foo\(.*foo\)/\1bar\2/’ # replace the next-to-last case&lt;br/&gt;&lt;br /&gt; sed ’s/\(.*\)foo/\1bar/’            # replace only the last case&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # substitute “foo” with “bar” ONLY for lines which contain “baz”&lt;br/&gt;&lt;br /&gt; sed ‘/baz/s/foo/bar/g’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # substitute “foo” with “bar” EXCEPT for lines which contain “baz”&lt;br/&gt;&lt;br /&gt; sed ‘/baz/!s/foo/bar/g’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # change “scarlet” or “ruby” or “puce” to “red”&lt;br/&gt;&lt;br /&gt; sed ’s/scarlet/red/g;s/ruby/red/g;s/puce/red/g’   # most seds&lt;br/&gt;&lt;br /&gt; gsed ’s/scarlet\|ruby\|puce/red/g’                # GNU sed only&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # reverse order of lines (emulates “tac”)&lt;br/&gt;&lt;br /&gt; # bug/feature in HHsed v1.5 causes blank lines to be deleted&lt;br/&gt;&lt;br /&gt; sed ‘1!G;h;$!d’               # method 1&lt;br/&gt;&lt;br /&gt; sed -n ‘1!G;h;$p’             # method 2&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # reverse each character on the line (emulates “rev”)&lt;br/&gt;&lt;br /&gt; sed ‘/\n/!G;s/\(.\)\(.*\n\)/&amp;amp;\2\1/;//D;s/.//’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # join pairs of lines side-by-side (like “paste”)&lt;br/&gt;&lt;br /&gt; sed ‘$!N;s/\n/ /’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # if a line ends with a backslash, append the next line to it&lt;br/&gt;&lt;br /&gt; sed -e :a -e ‘/\\$/N; s/\\\n//; ta’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # if a line begins with an equal sign, append it to the previous line&lt;br/&gt;&lt;br /&gt; # and replace the “=” with a single space&lt;br/&gt;&lt;br /&gt; sed -e :a -e ‘$!N;s/\n=/ /;ta’ -e ‘P;D’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # add commas to numeric strings, changing “1234567″ to “1,234,567″&lt;br/&gt;&lt;br /&gt; gsed ‘:a;s/\B[0-9]\{3\}\&amp;amp;gt;/,&amp;amp;/;ta’                     # GNU sed&lt;br/&gt;&lt;br /&gt; sed -e :a -e ’s/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta’  # other seds&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # add commas to numbers with decimal points and minus signs (GNU sed)&lt;br/&gt;&lt;br /&gt; gsed ‘:a;s/\(^\|[^0-9.]\)\([0-9]\+\)\([0-9]\{3\}\)/\1\2,\3/g;ta’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # add a blank line every 5 lines (after lines 5, 10, 15, 20, etc.)&lt;br/&gt;&lt;br /&gt; gsed ‘0~5G’                  # GNU sed only&lt;br/&gt;&lt;br /&gt; sed ‘n;n;n;n;G;’             # other seds&lt;/p&gt;&lt;br /&gt;&lt;p&gt;SELECTIVE PRINTING OF CERTAIN LINES:&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # print first 10 lines of file (emulates behavior of “head”)&lt;br/&gt;&lt;br /&gt; sed 10q&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # print first line of file (emulates “head -1″)&lt;br/&gt;&lt;br /&gt; sed q&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # print the last 10 lines of a file (emulates “tail”)&lt;br/&gt;&lt;br /&gt; sed -e :a -e ‘$q;N;11,$D;ba’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # print the last 2 lines of a file (emulates “tail -2″)&lt;br/&gt;&lt;br /&gt; sed ‘$!N;$!D’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # print the last line of a file (emulates “tail -1″)&lt;br/&gt;&lt;br /&gt; sed ‘$!d’                    # method 1&lt;br/&gt;&lt;br /&gt; sed -n ‘$p’                  # method 2&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # print only lines which match regular expression (emulates “grep”)&lt;br/&gt;&lt;br /&gt; sed -n ‘/regexp/p’           # method 1&lt;br/&gt;&lt;br /&gt; sed ‘/regexp/!d’             # method 2&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # print only lines which do NOT match regexp (emulates “grep -v”)&lt;br/&gt;&lt;br /&gt; sed -n ‘/regexp/!p’          # method 1, corresponds to above&lt;br/&gt;&lt;br /&gt; sed ‘/regexp/d’              # method 2, simpler syntax&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # print the line immediately before a regexp, but not the line&lt;br/&gt;&lt;br /&gt; # containing the regexp&lt;br/&gt;&lt;br /&gt; sed -n ‘/regexp/{g;1!p;};h’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # print the line immediately after a regexp, but not the line&lt;br/&gt;&lt;br /&gt; # containing the regexp&lt;br/&gt;&lt;br /&gt; sed -n ‘/regexp/{n;p;}’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # print 1 line of context before and after regexp, with line number&lt;br/&gt;&lt;br /&gt; # indicating where the regexp occurred (similar to “grep -A1 -B1″)&lt;br/&gt;&lt;br /&gt; sed -n -e ‘/regexp/{=;x;1!p;g;$!N;p;D;}’ -e h&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # grep for AAA and BBB and CCC (in any order)&lt;br/&gt;&lt;br /&gt; sed ‘/AAA/!d; /BBB/!d; /CCC/!d’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # grep for AAA and BBB and CCC (in that order)&lt;br/&gt;&lt;br /&gt; sed ‘/AAA.*BBB.*CCC/!d’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # grep for AAA or BBB or CCC (emulates “egrep”)&lt;br/&gt;&lt;br /&gt; sed -e ‘/AAA/b’ -e ‘/BBB/b’ -e ‘/CCC/b’ -e d    # most seds&lt;br/&gt;&lt;br /&gt; gsed ‘/AAA\|BBB\|CCC/!d’                        # GNU sed only&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # print paragraph if it contains AAA (blank lines separate paragraphs)&lt;br/&gt;&lt;br /&gt; # HHsed v1.5 must insert a ‘G;’ after ‘x;’ in the next 3 scripts below&lt;br/&gt;&lt;br /&gt; sed -e ‘/./{H;$!d;}’ -e ‘x;/AAA/!d;’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # print paragraph if it contains AAA and BBB and CCC (in any order)&lt;br/&gt;&lt;br /&gt; sed -e ‘/./{H;$!d;}’ -e ‘x;/AAA/!d;/BBB/!d;/CCC/!d’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # print paragraph if it contains AAA or BBB or CCC&lt;br/&gt;&lt;br /&gt; sed -e ‘/./{H;$!d;}’ -e ‘x;/AAA/b’ -e ‘/BBB/b’ -e ‘/CCC/b’ -e d&lt;br/&gt;&lt;br /&gt; gsed ‘/./{H;$!d;};x;/AAA\|BBB\|CCC/b;d’         # GNU sed only&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # print only lines of 65 characters or longer&lt;br/&gt;&lt;br /&gt; sed -n ‘/^.\{65\}/p’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # print only lines of less than 65 characters&lt;br/&gt;&lt;br /&gt; sed -n ‘/^.\{65\}/!p’        # method 1, corresponds to above&lt;br/&gt;&lt;br /&gt; sed ‘/^.\{65\}/d’            # method 2, simpler syntax&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # print section of file from regular expression to end of file&lt;br/&gt;&lt;br /&gt; sed -n ‘/regexp/,$p’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # print section of file based on line numbers (lines 8-12, inclusive)&lt;br/&gt;&lt;br /&gt; sed -n ‘8,12p’               # method 1&lt;br/&gt;&lt;br /&gt; sed ‘8,12!d’                 # method 2&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # print line number 52&lt;br/&gt;&lt;br /&gt; sed -n ‘52p’                 # method 1&lt;br/&gt;&lt;br /&gt; sed ‘52!d’                   # method 2&lt;br/&gt;&lt;br /&gt; sed ‘52q;d’                  # method 3, efficient on large files&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # beginning at line 3, print every 7th line&lt;br/&gt;&lt;br /&gt; gsed -n ‘3~7p’               # GNU sed only&lt;br/&gt;&lt;br /&gt; sed -n ‘3,${p;n;n;n;n;n;n;}’ # other seds&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # print section of file between two regular expressions (inclusive)&lt;br/&gt;&lt;br /&gt; sed -n ‘/Iowa/,/Montana/p’             # case sensitive&lt;/p&gt;&lt;br /&gt;&lt;p&gt;SELECTIVE DELETION OF CERTAIN LINES:&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # print all of file EXCEPT section between 2 regular expressions&lt;br/&gt;&lt;br /&gt; sed ‘/Iowa/,/Montana/d’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # delete duplicate, consecutive lines from a file (emulates “uniq”).&lt;br/&gt;&lt;br /&gt; # First line in a set of duplicate lines is kept, rest are deleted.&lt;br/&gt;&lt;br /&gt; sed ‘$!N; /^\(.*\)\n\1$/!P; D’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # delete duplicate, nonconsecutive lines from a file. Beware not to&lt;br/&gt;&lt;br /&gt; # overflow the buffer size of the hold space, or else use GNU sed.&lt;br/&gt;&lt;br /&gt; sed -n ‘G; s/\n/&amp;amp;&amp;amp;/; /^\([ -~]*\n\).*\n\1/d; s/\n//; h; P’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # delete all lines except duplicate lines (emulates “uniq -d”).&lt;br/&gt;&lt;br /&gt; sed ‘$!N; s/^\(.*\)\n\1$/\1/; t; D’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # delete the first 10 lines of a file&lt;br/&gt;&lt;br /&gt; sed ‘1,10d’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # delete the last line of a file&lt;br/&gt;&lt;br /&gt; sed ‘$d’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # delete the last 2 lines of a file&lt;br/&gt;&lt;br /&gt; sed ‘N;$!P;$!D;$d’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # delete the last 10 lines of a file&lt;br/&gt;&lt;br /&gt; sed -e :a -e ‘$d;N;2,10ba’ -e ‘P;D’   # method 1&lt;br/&gt;&lt;br /&gt; sed -n -e :a -e ‘1,10!{P;N;D;};N;ba’  # method 2&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # delete every 8th line&lt;br/&gt;&lt;br /&gt; gsed ‘0~8d’                           # GNU sed only&lt;br/&gt;&lt;br /&gt; sed ‘n;n;n;n;n;n;n;d;’                # other seds&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # delete ALL blank lines from a file (same as “grep ‘.’ “)&lt;br/&gt;&lt;br /&gt; sed ‘/^$/d’                           # method 1&lt;br/&gt;&lt;br /&gt; sed ‘/./!d’                           # method 2&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # delete all CONSECUTIVE blank lines from file except the first; also&lt;br/&gt;&lt;br /&gt; # deletes all blank lines from top and end of file (emulates “cat -s”)&lt;br/&gt;&lt;br /&gt; sed ‘/./,/^$/!d’          # method 1, allows 0 blanks at top, 1 at EOF&lt;br/&gt;&lt;br /&gt; sed ‘/^$/N;/\n$/D’        # method 2, allows 1 blank at top, 0 at EOF&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # delete all CONSECUTIVE blank lines from file except the first 2:&lt;br/&gt;&lt;br /&gt; sed ‘/^$/N;/\n$/N;//D’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # delete all leading blank lines at top of file&lt;br/&gt;&lt;br /&gt; sed ‘/./,$!d’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # delete all trailing blank lines at end of file&lt;br/&gt;&lt;br /&gt; sed -e :a -e ‘/^\n*$/{$d;N;ba’ -e ‘}’  # works on all seds&lt;br/&gt;&lt;br /&gt; sed -e :a -e ‘/^\n*$/N;/\n$/ba’        # ditto, except for gsed 3.02*&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # delete the last line of each paragraph&lt;br/&gt;&lt;br /&gt; sed -n ‘/^$/{p;h;};/./{x;/./p;}’&lt;/p&gt;&lt;br /&gt;&lt;p&gt;SPECIAL APPLICATIONS:&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # remove nroff overstrikes (char, backspace) from man pages. The ‘echo’&lt;br/&gt;&lt;br /&gt; # command may need an -e switch if you use Unix System V or bash shell.&lt;br/&gt;&lt;br /&gt; sed “s/.`echo \\\b`//g”    # double quotes required for Unix environment&lt;br/&gt;&lt;br /&gt; sed ’s/.^H//g’             # in bash/tcsh, press Ctrl-V and then Ctrl-H&lt;br/&gt;&lt;br /&gt; sed ’s/.\x08//g’           # hex expression for sed v1.5&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # get Usenet/e-mail message header&lt;br/&gt;&lt;br /&gt; sed ‘/^$/q’                # deletes everything after first blank line&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # get Usenet/e-mail message body&lt;br/&gt;&lt;br /&gt; sed ‘1,/^$/d’              # deletes everything up to first blank line&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # get Subject header, but remove initial “Subject: ” portion&lt;br/&gt;&lt;br /&gt; sed ‘/^Subject: */!d; s///;q’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # get return address header&lt;br/&gt;&lt;br /&gt; sed ‘/^Reply-To:/q; /^From:/h; /./d;g;q’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # parse out the address proper. Pulls out the e-mail address by itself&lt;br/&gt;&lt;br /&gt; # from the 1-line return address header (see preceding script)&lt;br/&gt;&lt;br /&gt; sed ’s/ *(.*)//; s/&amp;amp;gt;.*//; s/.*[:&amp;amp;lt;] *//'&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # add a leading angle bracket and space to each line (quote a message)&lt;br/&gt;&lt;br /&gt; sed 's/^/&amp;amp;gt; /’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # delete leading angle bracket &amp;amp; space from each line (unquote a message)&lt;br/&gt;&lt;br /&gt; sed ’s/^&amp;amp;gt; //’&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # remove most HTML tags (accommodates multiple-line tags)&lt;br/&gt;&lt;br /&gt; sed -e :a -e ’s/&amp;amp;lt;[^&amp;amp;gt;]*&amp;amp;gt;//g;/&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # extract multi-part uuencoded binaries, removing extraneous header&lt;br/&gt;&lt;br /&gt; # info, so that only the uuencoded portion remains. Files passed to&lt;br/&gt;&lt;br /&gt; # sed must be passed in the proper order. Version 1 can be entered&lt;br/&gt;&lt;br /&gt; # from the command line; version 2 can be made into an executable&lt;br/&gt;&lt;br /&gt; # Unix shell script. (Modified from a script by Rahul Dhesi.)&lt;br/&gt;&lt;br /&gt; sed '/^end/,/^begin/d' file1 file2 ... fileX | uudecode   # vers. 1&lt;br/&gt;&lt;br /&gt; sed '/^end/,/^begin/d' "$@" | uudecode                    # vers. 2&lt;/p&gt;&lt;br /&gt;&lt;p&gt; # zip up each .TXT file individually, deleting the source file and&lt;br/&gt;&lt;br /&gt; # setting the name of each .ZIP file to the basename of the .TXT file&lt;br/&gt;&lt;br /&gt; # (under DOS: the "dir /b" switch returns bare filenames in all caps).&lt;br/&gt;&lt;br /&gt; echo @echo off &amp;amp;gt;zipup.bat&lt;br/&gt;&lt;br /&gt; dir /b *.txt | sed “s/^\(.*\)\.TXT/pkzip -mo \1 \1.TXT/” &amp;amp;gt;&amp;amp;gt;zipup.bat&lt;/p&gt;&lt;br /&gt;&lt;p&gt;TYPICAL USE: Sed takes one or more editing commands and applies all of&lt;br/&gt;&lt;br /&gt;them, in sequence, to each line of input. After all the commands have&lt;br/&gt;&lt;br /&gt;been applied to the first input line, that line is output and a second&lt;br/&gt;&lt;br /&gt;input line is taken for processing, and the cycle repeats. The&lt;br/&gt;&lt;br /&gt;preceding examples assume that input comes from the standard input&lt;br/&gt;&lt;br /&gt;device (i.e, the console, normally this will be piped input). One or&lt;br/&gt;&lt;br /&gt;more filenames can be appended to the command line if the input does&lt;br/&gt;&lt;br /&gt;not come from stdin. Output is sent to stdout (the screen). Thus:&lt;/p&gt;&lt;br /&gt;&lt;p&gt; cat filename | sed ‘10q’        # uses piped input&lt;br/&gt;&lt;br /&gt; sed ‘10q’ filename              # same effect, avoids a useless “cat”&lt;br/&gt;&lt;br /&gt; sed ‘10q’ filename &amp;amp;gt; newfile    # redirects output to disk&lt;/p&gt;&lt;br /&gt;&lt;p&gt;For additional syntax instructions, including the way to apply editing&lt;br/&gt;&lt;br /&gt;commands from a disk file instead of the command line, consult “sed &amp;amp;&lt;br/&gt;&lt;br /&gt;awk, 2nd Edition,” by Dale Dougherty and Arnold Robbins (O’Reilly,&lt;br/&gt;&lt;span&gt;&lt;br /&gt;1997; &lt;a href='http://www.ora.com/'&gt;http://www.ora.com),&lt;/a&gt; “UNIX Text Processing,” by Dale Dougherty&lt;/span&gt;&lt;br/&gt;&lt;br /&gt;and Tim O’Reilly (Hayden Books, 1987) or the tutorials by Mike Arst&lt;br/&gt;&lt;br /&gt;distributed in U-SEDIT2.ZIP (many sites). To fully exploit the power&lt;br/&gt;&lt;br /&gt;of sed, one must understand “regular expressions.” For this, see&lt;br/&gt;&lt;br /&gt;“Mastering Regular Expressions” by Jeffrey Friedl (O’Reilly, 1997).&lt;br/&gt;&lt;br /&gt;The manual (”man”) pages on Unix systems may be helpful (try “man&lt;br/&gt;&lt;br /&gt;sed”, “man regexp”, or the subsection on regular expressions in “man&lt;br/&gt;&lt;br /&gt;ed”), but man pages are notoriously difficult. They are not written to&lt;br/&gt;&lt;br /&gt;teach sed use or regexps to first-time users, but as a reference text&lt;br/&gt;&lt;br /&gt;for those already acquainted with these tools.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;QUOTING SYNTAX: The preceding examples use single quotes (’…’)&lt;br/&gt;&lt;br /&gt;instead of double quotes (”…”) to enclose editing commands, since&lt;br/&gt;&lt;br /&gt;sed is typically used on a Unix platform. Single quotes prevent the&lt;br/&gt;&lt;br /&gt;Unix shell from intrepreting the dollar sign ($) and backquotes&lt;br/&gt;&lt;br /&gt;(`…`), which are expanded by the shell if they are enclosed in&lt;br/&gt;&lt;br /&gt;double quotes. Users of the “csh” shell and derivatives will also need&lt;br/&gt;&lt;br /&gt;to quote the exclamation mark (!) with the backslash (i.e., \!) to&lt;br/&gt;&lt;br /&gt;properly run the examples listed above, even within single quotes.&lt;br/&gt;&lt;br /&gt;Versions of sed written for DOS invariably require double quotes&lt;br/&gt;&lt;br /&gt;(”…”) instead of single quotes to enclose editing commands.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;USE OF ‘\t’ IN SED SCRIPTS: For clarity in documentation, we have used&lt;br/&gt;&lt;br /&gt;the expression ‘\t’ to indicate a tab character (0×09) in the scripts.&lt;br/&gt;&lt;br /&gt;However, most versions of sed do not recognize the ‘\t’ abbreviation,&lt;br/&gt;&lt;br /&gt;so when typing these scripts from the command line, you should press&lt;br/&gt;&lt;br /&gt;the TAB key instead. ‘\t’ is supported as a regular expression&lt;br/&gt;&lt;br /&gt;metacharacter in awk, perl, and HHsed, sedmod, and GNU sed v3.02.80.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;VERSIONS OF SED: Versions of sed do differ, and some slight syntax&lt;br/&gt;&lt;br /&gt;variation is to be expected. In particular, most do not support the&lt;br/&gt;&lt;br /&gt;use of labels (:name) or branch instructions (b,t) within editing&lt;br/&gt;&lt;br /&gt;commands, except at the end of those commands. We have used the syntax&lt;br/&gt;&lt;br /&gt;which will be portable to most users of sed, even though the popular&lt;br/&gt;&lt;br /&gt;GNU versions of sed allow a more succinct syntax. When the reader sees&lt;br/&gt;&lt;br /&gt;a fairly long command such as this:&lt;/p&gt;&lt;br /&gt;&lt;p&gt;   sed -e ‘/AAA/b’ -e ‘/BBB/b’ -e ‘/CCC/b’ -e d&lt;/p&gt;&lt;br /&gt;&lt;p&gt;it is heartening to know that GNU sed will let you reduce it to:&lt;/p&gt;&lt;br /&gt;&lt;p&gt;   sed ‘/AAA/b;/BBB/b;/CCC/b;d’      # or even&lt;br/&gt;&lt;br /&gt;   sed ‘/AAA\|BBB\|CCC/b;d’&lt;/p&gt;&lt;br /&gt;&lt;p&gt;In addition, remember that while many versions of sed accept a command&lt;br/&gt;&lt;br /&gt;like “/one/ s/RE1/RE2/”, some do NOT allow “/one/! s/RE1/RE2/”, which&lt;br/&gt;&lt;br /&gt;contains space before the ’s’. Omit the space when typing the command.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;OPTIMIZING FOR SPEED: If execution speed needs to be increased (due to&lt;br/&gt;&lt;br /&gt;large input files or slow processors or hard disks), substitution will&lt;br/&gt;&lt;br /&gt;be executed more quickly if the “find” expression is specified before&lt;br/&gt;&lt;br /&gt;giving the “s/…/…/” instruction. Thus:&lt;/p&gt;&lt;br /&gt;&lt;p&gt;   sed ’s/foo/bar/g’ filename         # standard replace command&lt;br/&gt;&lt;br /&gt;   sed ‘/foo/ s/foo/bar/g’ filename   # executes more quickly&lt;br/&gt;&lt;br /&gt;   sed ‘/foo/ s//bar/g’ filename      # shorthand sed syntax&lt;/p&gt;&lt;br /&gt;&lt;p&gt;On line selection or deletion in which you only need to output lines&lt;br/&gt;&lt;br /&gt;from the first part of the file, a “quit” command (q) in the script&lt;br/&gt;&lt;br /&gt;will drastically reduce processing time for large files. Thus:&lt;/p&gt;&lt;br /&gt;&lt;p&gt;   sed -n ‘45,50p’ filename           # print line nos. 45-50 of a file&lt;br/&gt;&lt;br /&gt;   sed -n ‘51q;45,50p’ filename       # same, but executes much faster&lt;/p&gt;&lt;br/&gt;&lt;br/&gt;&lt;p class='poweredbyperformancing'&gt;Powered by &lt;a href='http://scribefire.com/'&gt;ScribeFire&lt;/a&gt;.&lt;/p&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-8721188852860064095?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/8721188852860064095/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2007/10/simple-bash-scripts-i-find-useful.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/8721188852860064095'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/8721188852860064095'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2007/10/simple-bash-scripts-i-find-useful.html' title='Simple Bash Scripts I find useful'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-3938035093497083014</id><published>2007-10-01T17:37:00.001+05:30</published><updated>2007-10-01T17:37:48.507+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Minimum Triplet</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;Problem:&lt;br/&gt;===========&lt;br/&gt;You are given 3 integer arrays A, B and C of length n1, n2 and n3 respectively. All arrays are sorted. We define triplet of these 3 arrays as (x,y,z) where x is any integer from A, y from B and z from C. We define distance of triplet as maximum difference among triplet elements, i.e. Maximum of x – y, y – z or z – x. Write a program to find minimum triplet distance. (means there are n1*n2*n3 number of possible triplets are possible...among all triplets which triplet has minimum distance...Give only distance, but not triplet elements). Your program must be as much efficient as possible.&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;Solution:&lt;br/&gt;=========&lt;br/&gt;int incMin(int *i, int *j, int *k); helper function that will increase the minimum of the three input indexes of 3 arrays, e.g. if a[.i] is least out of a[.i], b[j], c[k] then it will do i++ and if any one goes out of bound, it will return ERROR&lt;br/&gt;&lt;br/&gt;int windowSize(int i, int j, int k); helper function that returns the current window size = max(a[.i], b[j], c[k]) - min(a[.i], b[j], c[k])&lt;br/&gt;&lt;br/&gt;now the concept goes as following:&lt;br/&gt;we start with a window of 3 elements, one from each array. and keep altering the window as required and keep updating the minimum window found so far.&lt;br/&gt;&lt;br/&gt;minWindow = 99999; // some very large value&lt;br/&gt;returnVal = 0;&lt;br/&gt;i = j = k =0;&lt;br/&gt;&lt;br/&gt;while(returnVal != ERROR) //while one of the arrays does not exhaust&lt;br/&gt;{&lt;br/&gt;..currMinWindow = windowSize(i, j, k);&lt;br/&gt;&lt;br/&gt;..if(currMinWindow &amp;amp;lt; minWindow)&lt;br/&gt;....minWindow = currMinWindow;&lt;br/&gt;&lt;br/&gt;..returnVal = incMin(&amp;amp;i, &amp;amp;j, &amp;amp;k); // this will increase one of the i, j, k&lt;br/&gt;}&lt;br/&gt;&lt;br/&gt;int incMin(int *i, int *j, int *k)&lt;br/&gt;{&lt;br/&gt;..if(a[*i] &amp;amp;lt; b[*j])&lt;br/&gt;..{&lt;br/&gt;....if(a[*i] &amp;amp;lt; c[*k])&lt;br/&gt;....{&lt;br/&gt;......if(i&amp;amp;lt;sizeof(A))&lt;br/&gt;........(*i)++; //a[.i] is minimum, so inc i&lt;br/&gt;......else&lt;br/&gt;........return ERROR;&lt;br/&gt;....}&lt;br/&gt;....else&lt;br/&gt;.....{&lt;br/&gt;........if(k &amp;amp;lt; sizeof(C))&lt;br/&gt;..........(*k)++; //c[k] is minimum, so inc k&lt;br/&gt;........else&lt;br/&gt;..........return ERROR;&lt;br/&gt;......}&lt;br/&gt;..}&lt;br/&gt;..else&lt;br/&gt;..{&lt;br/&gt;....if(b[*j] &amp;amp;lt; c[*k])&lt;br/&gt;....{&lt;br/&gt;......if(j &amp;amp;lt; sizeof(B))&lt;br/&gt;........(*j)++; //b[j] is minimum, so inc j&lt;br/&gt;......else&lt;br/&gt;........return ERROR;&lt;br/&gt;....}&lt;br/&gt;....else&lt;br/&gt;....{&lt;br/&gt;......if(k &amp;amp;lt; sizeof(C))&lt;br/&gt;........(*k)++; //c[k] is minimum, so inc k&lt;br/&gt;......else&lt;br/&gt;........return ERROR;&lt;br/&gt;....}&lt;br/&gt;..}&lt;br/&gt;}&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p class='poweredbyperformancing'&gt;Powered by &lt;a href='http://scribefire.com/'&gt;ScribeFire&lt;/a&gt;.&lt;/p&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-3938035093497083014?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/3938035093497083014/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2007/10/minimum-triplet.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/3938035093497083014'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/3938035093497083014'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2007/10/minimum-triplet.html' title='Minimum Triplet'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-2586653537568338214</id><published>2007-09-12T10:45:00.001+05:30</published><updated>2007-09-12T10:46:43.663+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'></title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;Solution:&lt;br/&gt;------------&lt;br/&gt;&lt;br/&gt;let a and b be given nos ( or values of given nodes )&lt;br/&gt;&lt;br/&gt;common_ance( node )&lt;br/&gt;{&lt;br/&gt;........if( ( a &amp;amp;lt;node &amp;amp;&amp;amp; b &amp;amp;gt; node ) || ( a &amp;amp;gt; node &amp;amp;&amp;amp; b &amp;amp;lt; node ) || a == node || b== node)&lt;br/&gt;........ return node&lt;br/&gt;&lt;br/&gt;........else if ( a &amp;amp;lt; node &amp;amp;&amp;amp; b &amp;amp;lt; node ) &lt;br/&gt;........ return common_ance( node - &amp;amp;gt; left )&lt;br/&gt;&lt;br/&gt;........ else&lt;br/&gt;........ return common_ance ( node -&amp;amp;gt; right )&lt;br/&gt;}&lt;br/&gt;&lt;br/&gt;initial call is common_ance( root )&lt;br/&gt;&lt;br/&gt;Psudocode:&lt;br/&gt;----------------&lt;br/&gt;&lt;br/&gt;first condition checks if given nodes lie in left n right subtrees of root&lt;br/&gt;if yes return root&lt;br/&gt;else&lt;br/&gt;if both lie in left subtree then call common_ance( root -&amp;amp;gt; left )&lt;br/&gt;else common_ance ( root - &amp;amp;gt; right )&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p class='poweredbyperformancing'&gt;Powered by &lt;a href='http://scribefire.com/'&gt;ScribeFire&lt;/a&gt;.&lt;/p&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-2586653537568338214?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/2586653537568338214/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2007/09/for-finding-common-ancestor.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/2586653537568338214'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/2586653537568338214'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2007/09/for-finding-common-ancestor.html' title=''/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-6230121348204287294</id><published>2007-09-12T10:36:00.001+05:30</published><updated>2007-09-12T10:36:13.068+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Division with using /,% operator</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;Question:&lt;br/&gt;--------------&lt;br/&gt;&lt;br/&gt;Two integers a, b how to divde a/b without using /,% operator... (repeted subtraction is not the solution).&lt;br/&gt;&lt;br/&gt;Solution:&lt;br/&gt;-----------&lt;br/&gt;&lt;br/&gt;#include&amp;amp;lt;stdio.h&amp;amp;gt;&lt;br/&gt;int main()&lt;br/&gt;{&lt;br/&gt;    printf("%d\n", divide(40,2));&lt;br/&gt;    return 0;&lt;br/&gt;}&lt;br/&gt;&lt;br/&gt;int divide(int num, int denom)&lt;br/&gt;{&lt;br/&gt;    int a=0, b=0;&lt;br/&gt;    int i= 31; // CAREFUL: works only on int=32-bit machine!&lt;br/&gt;    /* Work from leftmost to rightmost bit in numerator */&lt;br/&gt;    while(i&amp;amp;gt;=0) {&lt;br/&gt;        /* appends one bit from numerator to a */&lt;br/&gt;        a = (a &amp;amp;lt;&amp;amp;lt; 1) + ((num &amp;amp; (1 &amp;amp;lt;&amp;amp;lt; i)) &amp;amp;gt;&amp;amp;gt; i);&lt;br/&gt;        b = b &amp;amp;lt;&amp;amp;lt; 1;&lt;br/&gt;        printf("After shifting a=%d and b=%d\n",a,b);&lt;br/&gt;        if (a &amp;amp;gt;= denom) {&lt;br/&gt;        a -= denom;&lt;br/&gt;        b++;&lt;br/&gt;        }&lt;br/&gt;        printf("After subtraction a=%d and b=%d\n",a,b);&lt;br/&gt;        i--;&lt;br/&gt;    }&lt;br/&gt;    return b;&lt;br/&gt;}&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p class='poweredbyperformancing'&gt;Powered by &lt;a href='http://scribefire.com/'&gt;ScribeFire&lt;/a&gt;.&lt;/p&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-6230121348204287294?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/6230121348204287294/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2007/09/division-with-using-operator.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/6230121348204287294'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/6230121348204287294'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2007/09/division-with-using-operator.html' title='Division with using /,% operator'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-8493314095260399545</id><published>2007-09-09T23:07:00.000+05:30</published><updated>2007-09-09T23:08:36.076+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'></title><content type='html'>One of the site which I came across&lt;br /&gt;&lt;br /&gt;http://www.tekpool.com/?cat=9&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-8493314095260399545?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/8493314095260399545/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2007/09/one-of-site-which-i-came-across-httpwww.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/8493314095260399545'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/8493314095260399545'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2007/09/one-of-site-which-i-came-across-httpwww.html' title=''/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-2739769661635158062</id><published>2007-08-28T17:38:00.001+05:30</published><updated>2007-08-28T17:38:48.316+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Detect a loop in a linked list</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;How would you detect a loop in a linked list? Write a C program to detect a loop in a linked list.&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;/*&lt;br/&gt;  Start two pointers at the head of the list&lt;br/&gt;  Loop infinitely&lt;br/&gt;      If the fast pointer reaches a NULL pointer&lt;br/&gt;        Return that the list is NULL terminated&lt;br/&gt;    If the fast pointer moves onto or over the slow pointer&lt;br/&gt;        Return that there is a cycle&lt;br/&gt;    Advances the slow pointer one node&lt;br/&gt;    Advances the fast pointer two node    &lt;br/&gt;*/&lt;br/&gt;&lt;br/&gt;#include &amp;amp;lt;stdio.h&amp;amp;gt;&lt;br/&gt;#include &amp;amp;lt;stdlib.h&amp;amp;gt;&lt;br/&gt;&lt;br/&gt;struct linkedList{&lt;br/&gt;    int element;&lt;br/&gt;    struct linkedList* next;&lt;br/&gt;};&lt;br/&gt;&lt;br/&gt;typedef struct linkedList* List;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;/* Takes a pointer to the head of a linked list and determines&lt;br/&gt;   if the list ends in a cycle or is NULL terminated&lt;br/&gt;*/&lt;br/&gt;&lt;br/&gt;int DetermineTermination(List *head)&lt;br/&gt;{&lt;br/&gt;    List *fast, *slow;&lt;br/&gt;    fast = slow = head;&lt;br/&gt;    while(1)&lt;br/&gt;    {&lt;br/&gt;        if(!fast || !fast-&amp;amp;gt;next)&lt;br/&gt;            return 0;&lt;br/&gt;        else if(fast == slow || fast -&amp;amp;gt;next == slow)&lt;br/&gt;            return 1; // Loop detected&lt;br/&gt;        else{&lt;br/&gt;            slow = slow-&amp;amp;gt;next;&lt;br/&gt;            fast = fast-&amp;amp;gt;next-&amp;amp;gt;next;&lt;br/&gt;        }&lt;br/&gt;    }&lt;br/&gt;}&lt;blockquote/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p class='poweredbyperformancing'&gt;Powered by &lt;a href='http://scribefire.com/'&gt;ScribeFire&lt;/a&gt;.&lt;/p&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-2739769661635158062?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/2739769661635158062/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2007/08/detect-loop-in-linked-list.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/2739769661635158062'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/2739769661635158062'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2007/08/detect-loop-in-linked-list.html' title='Detect a loop in a linked list'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-5177366789834564515</id><published>2007-08-28T17:36:00.001+05:30</published><updated>2007-09-12T10:48:10.312+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'></title><content type='html'>&lt;blockquote&gt;&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;Given only a pointer to a node to be deleted in a singly linked list, how do you delete it?&lt;br/&gt;&lt;br/&gt;&lt;blockquote/&gt; struct linkedList{&lt;br/&gt;      int element;&lt;br/&gt;      struct linkedList* next;&lt;br/&gt;  };&lt;br/&gt;  &lt;br/&gt;  typedef struct linkedList* List;&lt;br/&gt;  &lt;br/&gt;  void deleteNode(List Node)&lt;br/&gt;  {&lt;br/&gt;      List tmp;&lt;br/&gt;      if(Node)&lt;br/&gt;      {  // If current node is not NULL&lt;br/&gt;          &lt;br/&gt;          tmp = List-&amp;amp;gt;next; // take backup of next Node&lt;br/&gt;          Node-&amp;amp;gt;element = Node-&amp;amp;gt;next-&amp;amp;gt;element; // replace current node element with next Node element&lt;br/&gt;          Node-&amp;amp;gt;next = Node-&amp;amp;gt;next-&amp;amp;gt;next; // change next pointer to next to next&lt;br/&gt;          free(tmp); // free the next Node which was taken backup&lt;br/&gt;&lt;br/&gt;      }&lt;br/&gt;      return;&lt;br/&gt;}&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p class='poweredbyperformancing'&gt;Powered by &lt;a href='http://scribefire.com/'&gt;ScribeFire&lt;/a&gt;.&lt;/p&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-5177366789834564515?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/5177366789834564515/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2007/08/delete-node-in-list.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/5177366789834564515'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/5177366789834564515'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2007/08/delete-node-in-list.html' title=''/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-7687777219524491208</id><published>2007-08-28T17:35:00.001+05:30</published><updated>2007-08-28T17:35:03.019+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Reverse a linked list</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;Here is the iterative and recursive solution:&lt;br/&gt;&lt;br/&gt;&lt;blockquote/&gt;struct linkedList{&lt;br/&gt;    int element;&lt;br/&gt;    struct linkedList *next;&lt;br/&gt;};&lt;br/&gt;&lt;br/&gt;typedef struct linkedList* List;&lt;br/&gt;&lt;br/&gt;List reverseList(List L)&lt;br/&gt;{&lt;br/&gt;    List tmp, previous=NULL;&lt;br/&gt;&lt;br/&gt;    while(L){&lt;br/&gt;        tmp = L-&amp;amp;gt;next;&lt;br/&gt;        L-&amp;amp;gt;next = previous;&lt;br/&gt;        previous = L;&lt;br/&gt;        L = tmp;&lt;br/&gt;    }&lt;br/&gt;    L = previous;&lt;br/&gt;    return L;&lt;br/&gt;    &lt;br/&gt;}&lt;br/&gt;&lt;br/&gt;List recursiveReverse(List L)&lt;br/&gt;{&lt;br/&gt;    List first, rest;&lt;br/&gt;    if(!L)&lt;br/&gt;        return NULL;&lt;br/&gt;    first = L;&lt;br/&gt;    rest = L-&amp;amp;gt;next;&lt;br/&gt;    if(!rest)&lt;br/&gt;        return NULL;&lt;br/&gt;    rest = recursiveReverse(rest);&lt;br/&gt;    first-&amp;amp;gt;next-&amp;amp;gt;next = first;&lt;br/&gt;    first-&amp;amp;gt;next = NULL;&lt;br/&gt;    L=rest;    &lt;br/&gt;&lt;br/&gt;    return L;&lt;br/&gt;  }&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p class='poweredbyperformancing'&gt;Powered by &lt;a href='http://scribefire.com/'&gt;ScribeFire&lt;/a&gt;.&lt;/p&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-7687777219524491208?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/7687777219524491208/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2007/08/reverse-linked-list.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/7687777219524491208'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/7687777219524491208'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2007/08/reverse-linked-list.html' title='Reverse a linked list'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-100674993052917796</id><published>2007-08-20T15:51:00.001+05:30</published><updated>2007-08-20T15:51:21.595+05:30</updated><title type='text'>memcpy function implementation</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;&lt;br/&gt;&lt;blockquote&gt;//Most simplified copy function.&lt;br/&gt;void *memcpy(void* dest, const void* src, size_t count)&lt;br/&gt;{ &lt;br/&gt;        char *s = (char *)src;&lt;br/&gt;        char *d = (char *)dest;&lt;br/&gt;        for(; count; count--)&lt;br/&gt;        { &lt;br/&gt;            *s++ = *d++; //usage of operator precendence &lt;br/&gt;        }&lt;br/&gt;}&lt;/blockquote&gt;&lt;br/&gt;&lt;br/&gt;&lt;p class='poweredbyperformancing'&gt;Powered by &lt;a href='http://scribefire.com/'&gt;ScribeFire&lt;/a&gt;.&lt;/p&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-100674993052917796?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/100674993052917796/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2007/08/memcpy-function-implementation.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/100674993052917796'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/100674993052917796'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2007/08/memcpy-function-implementation.html' title='memcpy function implementation'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-8919720020591032747</id><published>2007-08-20T12:12:00.001+05:30</published><updated>2007-08-20T12:12:24.332+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>Card Shuffling Algorithm</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;&lt;h2&gt;The Algorithm&lt;/h2&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;Step 1&lt;/b&gt;: Initialize the cards. For each &lt;b&gt;&lt;i&gt;i&lt;/i&gt;&lt;/b&gt; in the &lt;b&gt;&lt;i&gt;[0...n-1]&lt;/i&gt;&lt;/b&gt; range, set &lt;b&gt;&lt;i&gt;card[i] = i&lt;/i&gt;&lt;/b&gt;.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;Step 2 (optional)&lt;/b&gt;: Seed the &lt;a href='http://www.everything2.com/index.pl?node=random%20number%20generator' title='random number generator'&gt;random number generator&lt;/a&gt;.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;Step 3&lt;/b&gt;: Let &lt;b&gt;&lt;i&gt;i = 0&lt;/i&gt;&lt;/b&gt;.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;Step 4&lt;/b&gt;: Let &lt;b&gt;&lt;i&gt;j = random_number MOD n&lt;/i&gt;&lt;/b&gt;.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;Step 5&lt;/b&gt;: Exchange the values of &lt;b&gt;&lt;i&gt;card[i]&lt;/i&gt;&lt;/b&gt; and &lt;b&gt;&lt;i&gt;card[j]&lt;/i&gt;&lt;/b&gt;.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;Step 6&lt;/b&gt;: Let &lt;b&gt;&lt;i&gt;i = i + 1&lt;/i&gt;&lt;/b&gt;. If &lt;b&gt;&lt;i&gt;i&lt;/i&gt;&lt;/b&gt; is less than &lt;b&gt;&lt;i&gt;n&lt;/i&gt;&lt;/b&gt;, go to &lt;b&gt;step 4&lt;/b&gt;.&lt;br/&gt;&lt;/p&gt;&lt;h2&gt;Sample Source Code&lt;/h2&gt;&lt;br /&gt;&lt;p&gt;Here is a sample &lt;a href='http://www.everything2.com/index.pl?node=C' title='C'&gt;C&lt;/a&gt; &lt;a href='http://www.everything2.com/index.pl?node=function' title='function'&gt;function&lt;/a&gt; implementing the &lt;a href='http://www.everything2.com/index.pl?node=algorithm' title='algorithm'&gt;algorithm&lt;/a&gt;:&lt;/p&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;pre&gt;void shuffle(int *card, int n) {&lt;br/&gt;	int i, j, k;&lt;br/&gt;&lt;br/&gt;	for (i = 0; i &amp;amp;lt; n; i++)&lt;br/&gt;		card[i] = i;&lt;br/&gt;&lt;br/&gt;	for (i = 0; i &amp;amp;lt; n; i++) {&lt;br/&gt;		j = rand() % n;&lt;br/&gt;		k = card[i];&lt;br/&gt;		card[i] = card[j];&lt;br/&gt;		card[j] = k;&lt;br/&gt;	}&lt;br/&gt;}&lt;br/&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;br/&gt;&lt;br/&gt;&lt;p class='poweredbyperformancing'&gt;Powered by &lt;a href='http://scribefire.com/'&gt;ScribeFire&lt;/a&gt;.&lt;/p&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-8919720020591032747?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/8919720020591032747/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2007/08/card-shuffling-algorithm.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/8919720020591032747'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/8919720020591032747'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2007/08/card-shuffling-algorithm.html' title='Card Shuffling Algorithm'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-4827172818518657695</id><published>2007-08-20T11:23:00.001+05:30</published><updated>2007-08-20T11:24:35.648+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'></title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;&lt;u&gt;Question :&lt;/u&gt;&lt;br/&gt;&lt;br/&gt;&lt;br /&gt;  Write a C Program to reverse a stack "in place" using recursion ?&lt;br/&gt;You can only use the following ADT functions on Stack:&lt;br/&gt;IsEmpty&lt;br/&gt;IsFull&lt;br/&gt;Push&lt;br/&gt;Pop&lt;br/&gt;Top&lt;br/&gt;&lt;br/&gt;&lt;u&gt;Solution:&lt;/u&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;void reverse()&lt;br/&gt;{&lt;br/&gt;....int a = s.pop();&lt;br/&gt;....if(s.count!=1)&lt;br/&gt;........reverse();&lt;br/&gt;&lt;br/&gt;....Push(a);&lt;br/&gt;}&lt;br/&gt;&lt;br/&gt;void Push(int a)&lt;br/&gt;{&lt;br/&gt;....int m = s.pop();&lt;br/&gt;....if(s.count!=0)&lt;br/&gt;........Push(a);&lt;br/&gt;....Else&lt;br/&gt;........s.push(a);&lt;br/&gt;&lt;br/&gt;....s.push(m);&lt;br/&gt;}&lt;br/&gt;&lt;br/&gt;&lt;p class='poweredbyperformancing'&gt;Powered by &lt;a href='http://scribefire.com/'&gt;ScribeFire&lt;/a&gt;.&lt;/p&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-4827172818518657695?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/4827172818518657695/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2007/08/how-to-reverse-stack.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/4827172818518657695'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/4827172818518657695'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2007/08/how-to-reverse-stack.html' title=''/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-7158369280616092105</id><published>2007-08-19T20:20:00.001+05:30</published><updated>2007-08-19T20:20:24.426+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>No of BTS's</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;&lt;u&gt;Question :&lt;br/&gt;&lt;br/&gt;&lt;/u&gt;Given  a number N, find the number of binary search trees(BST) possible with numbers 1,2....N&lt;br/&gt;&lt;br/&gt;for E.g. if N = 2 , no. of BSTs with node-values 1 and 2 = 2&lt;br/&gt;if N = 3 , no. of BSTs with node-values 1,2 and 3 = 5&lt;u&gt;&lt;br/&gt;&lt;/u&gt;&lt;br/&gt;&lt;br/&gt;Solution: &lt;br/&gt;&lt;br/&gt;&lt;b&gt;recursive sol for the same&lt;/b&gt;&lt;br/&gt;&lt;br /&gt;  int countTrees(int numKeys) {&lt;br/&gt;&lt;br/&gt;    if (numKeys &amp;amp;lt;=1) {&lt;br/&gt;            return(1);&lt;br/&gt;    }&lt;br/&gt;    else&lt;br/&gt;     {&lt;br/&gt;            // there will be one value at the root, with whatever remains&lt;br/&gt;            // on the left and right each forming their own subtrees.&lt;br/&gt;            // Iterate through all the values that could be the root...&lt;br/&gt;        &lt;br/&gt;            int sum = 0;&lt;br/&gt;            int left, right, root;&lt;br/&gt;&lt;br/&gt;        for (root=1; root&amp;amp;lt;=numKeys; root++) {&lt;br/&gt;                left = countTrees(root - 1);&lt;br/&gt;                right = countTrees(numKeys - root);&lt;br/&gt;&lt;br/&gt;                // number of possible trees with this root == left*right&lt;br/&gt;                sum += left*right;&lt;br/&gt;        }&lt;br/&gt;&lt;br/&gt;        return(sum);&lt;br/&gt;    }&lt;br/&gt;}&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p class='poweredbyperformancing'&gt;Powered by &lt;a href='http://scribefire.com/'&gt;ScribeFire&lt;/a&gt;.&lt;/p&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-7158369280616092105?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/7158369280616092105/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2007/08/no-of-bts.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/7158369280616092105'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/7158369280616092105'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2007/08/no-of-bts.html' title='No of BTS&amp;#39;s'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-2218454272781021049</id><published>2007-08-19T12:26:00.001+05:30</published><updated>2007-08-19T12:26:17.563+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'>MS Question</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;Question:&lt;br/&gt;------------&lt;br/&gt;&lt;br/&gt;Given an array having 16000 unique integers, each lying within the range 1&amp;amp;lt;x&amp;amp;lt;20000, how do u sort it. U can load only 1000 numbers at a time in memory.&lt;br/&gt;&lt;br/&gt;Solution:&lt;br/&gt;&lt;br/&gt;Have an array of 2500 bytes (memory equaivalent of 625 ints) - Each bit in the array will show the presence/absence of a num betw 1-20,000. Lets call this the "presence-bit-map".&lt;br/&gt;&lt;br/&gt;Since you can store the presence of 8 nos in a byte, you need (20,000/8) = 2500 bytes.&lt;br/&gt;&lt;br/&gt;Initialize all bytes in the presence-bit-map to 0, meaning 'absent'.&lt;br/&gt;&lt;br/&gt;Iterate the large integer list(be it in file / mem) once. For every number encountered, set the corresponding bit to 1(indicating present) in the presence-bit-map.&lt;br/&gt;&lt;br/&gt;Now, by scanning the presence-bit-map once, you can write the present numbers in sorted order.&lt;br/&gt;&lt;br/&gt;complexity&lt;br/&gt;===========&lt;br/&gt;The soln has a complexity of 'order of n', where n is 20,000 in this particular case. O(n) is the best u can get for a sorting problem !&lt;br/&gt;&lt;br/&gt;O(n) is possible here coz we have 2 facts that could be taken advantage of&lt;br/&gt;1. Numbers are known to be unique&lt;br/&gt;2. Nos. are known to be in a specific range.&lt;br/&gt;&lt;br/&gt;In a generic sorting problem, O(n) is usually not achievable since we can't assume anything like this.&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p class='poweredbyperformancing'&gt;Powered by &lt;a href='http://scribefire.com/'&gt;ScribeFire&lt;/a&gt;.&lt;/p&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-2218454272781021049?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/2218454272781021049/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2007/08/ms-question.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/2218454272781021049'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/2218454272781021049'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2007/08/ms-question.html' title='MS Question'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-1094903018477461113</id><published>2007-08-19T12:20:00.000+05:30</published><updated>2007-08-19T20:34:47.677+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Algorithms'/><title type='text'></title><content type='html'>I planned to maintain all the data structure and Algorithm questions which will surely benefit me and my friends .. So keep watching this page for more entries ..&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-1094903018477461113?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/1094903018477461113/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2007/08/i-planned-to-maintain-all-data.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/1094903018477461113'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/1094903018477461113'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2007/08/i-planned-to-maintain-all-data.html' title=''/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-729174642513053141</id><published>2007-06-26T19:50:00.001+05:30</published><updated>2007-06-26T19:50:18.291+05:30</updated><title type='text'>Sivaji - The BOSS</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;&lt;b&gt;Excited. &lt;/b&gt;&lt;small&gt;This is one word that explains the feeling when one gets while seeing the movie "Sivaji - The Boss". I can't imagine about a person other than shankar who showed Rajini with his real look. People who thinks that the age catches up him with time, then they must watch Sivaji for sure. What a style at this age, what a dialogue delivery, and no one can able to do a role with comedy, action and romance. But on the other side of the movie there's not much punch dialog from thalaivar but the team tried delivering the punch dialog through Vivek. And Vivek's first punch dialog was very good. The comedy and the love sequence is very good in the first half. &lt;br&gt;&lt;/br&gt;&lt;br&gt;&lt;/br&gt;We are keep on trying to get tickets for another show during the weekends. Hope we will get atleast this weekend :-)&lt;br&gt;&lt;/br&gt;&lt;/small&gt;&lt;br&gt;&lt;/br&gt;&lt;br&gt;&lt;/br&gt;&lt;p class='poweredbyperformancing'&gt;Powered by &lt;a href='http://scribefire.com/'&gt;ScribeFire&lt;/a&gt;.&lt;/p&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-729174642513053141?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/729174642513053141/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2007/06/sivaji-boss_26.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/729174642513053141'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/729174642513053141'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2007/06/sivaji-boss_26.html' title='Sivaji - The BOSS'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-5314032069754568792</id><published>2007-06-01T19:29:00.001+05:30</published><updated>2007-06-01T19:29:56.811+05:30</updated><title type='text'>Sivaji - The Boss</title><content type='html'>&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;&lt;p&gt;&lt;object height='350' width='425'&gt;&lt;param value='http://youtube.com/v/Bh63w2mwXIM' name='movie'&gt;&lt;/param&gt;&lt;embed height='350' width='425' type='application/x-shockwave-flash' src='http://youtube.com/v/Bh63w2mwXIM'&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/p&gt;&lt;p&gt;So the much awaited film of this year is going to hit the theaters soon. Thalaivar Rockzzzz .. &lt;/p&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-5314032069754568792?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/5314032069754568792/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2007/06/sivaji-boss.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/5314032069754568792'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/5314032069754568792'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2007/06/sivaji-boss.html' title='Sivaji - The Boss'/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-2336185872865764539</id><published>2007-05-23T14:50:00.000+05:30</published><updated>2007-05-23T15:05:03.877+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='IM'/><title type='text'></title><content type='html'>&lt;font style="font-family: verdana;" size="2"&gt;Hey today I happened to find the improved yahoo messenger on Web. The interface looks pretty cool.. The last time I tried using this web interface was during my college days. Thats before 4 years I guess. Now the GUI is developed using Flash 9.&lt;br /&gt;&lt;br /&gt;The advantage of using this is no download and it bypasses the Firewall :-).&lt;br /&gt;&lt;br /&gt;See for yourself at http://webmessenger.yahoo.com, or simply &lt;a href="http://web.im/"&gt;http://web.im&lt;/a&gt;&lt;/font&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-2336185872865764539?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/2336185872865764539/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2007/05/hey-today-i-happened-to-find-improved.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/2336185872865764539'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/2336185872865764539'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2007/05/hey-today-i-happened-to-find-improved.html' title=''/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-3065435904367819377</id><published>2007-05-20T01:21:00.000+05:30</published><updated>2007-05-20T01:25:33.664+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Life'/><title type='text'></title><content type='html'>Life in 30 Secs&lt;br /&gt;&lt;br /&gt;Have a look at it and you realize we are in a rat race.Found this video in Yahoo ..&lt;br /&gt;&lt;br /&gt;&lt;embed src="http://us.i1.yimg.com/cosmos.bcst.yahoo.com/player/media/swf/FLVVideoSolo.swf" flashvars="id=1054582&amp;emailUrl=http%3A%2F%2Fvideo.yahoo.com%2Futil%2Fmail%3Fei%3DUTF-8%26vid%3D128758&amp;amp;imUrl=http%253A%252F%252Fvideo.yahoo.com%252Fvideo%252Fplay%253Fei%253DUTF-8%2526vid%253D128758&amp;imTitle=run%2Ba%2Blife&amp;amp;searchUrl=http://video.yahoo.com/video/search?p=&amp;profileUrl=http://video.yahoo.com/video/profile?yid=&amp;amp;creatorValue=ZWNob21pbmQw&amp;amp;vid=128758" type="application/x-shockwave-flash" height="350" width="425"&gt;&lt;/embed&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-3065435904367819377?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/3065435904367819377/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2007/05/have-look-at-it-and-you-realize-we-are.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/3065435904367819377'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/3065435904367819377'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2007/05/have-look-at-it-and-you-realize-we-are.html' title=''/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-20767463.post-8919127882072393675</id><published>2006-12-08T13:30:00.000+05:30</published><updated>2006-12-08T13:31:05.969+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='First Blog'/><title type='text'></title><content type='html'>&lt;span style="color: rgb(51, 102, 255);font-size:85%;" &gt;This is my first blog :-) &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/20767463-8919127882072393675?l=mganesh.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mganesh.blogspot.com/feeds/8919127882072393675/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mganesh.blogspot.com/2006/12/this-is-my-first-blog.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/8919127882072393675'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/20767463/posts/default/8919127882072393675'/><link rel='alternate' type='text/html' href='http://mganesh.blogspot.com/2006/12/this-is-my-first-blog.html' title=''/><author><name>Ganesh M</name><uri>http://www.blogger.com/profile/09649484724847141426</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='30' height='32' src='http://2.bp.blogspot.com/_9x6r0w5l1wM/TBD4h-nEHhI/AAAAAAAADCI/n2AQ8kr8ti8/S220/DSC04853-1.JPG'/></author><thr:total>0</thr:total></entry></feed>
