<?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-6902761</id><updated>2012-02-16T01:21:21.044-08:00</updated><category term='editor'/><category term='tags'/><category term='SPICE'/><category term='programming'/><category term='hotel sitara'/><category term='EDA'/><category term='lex-yacc'/><category term='ramoji film city'/><category term='vim'/><category term='parsing'/><category term='Euler Cycle'/><category term='programming.'/><category term='Algorithms'/><category term='VLSI'/><title type='text'>Silent rants of my life.........</title><subtitle type='html'>Algorithms, Theory, Statistics, Life, Technology, UNIX, Food and Workout .......trying to sort these deterministically in constant time $\Theta(1)$.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default?start-index=101&amp;max-results=100'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>150</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6902761.post-7373976059064589386</id><published>2011-05-14T11:06:00.000-07:00</published><updated>2011-05-15T23:20:25.269-07:00</updated><title type='text'>[TECH] Enumerating set partitions with $DLX$</title><content type='html'>&lt;p&gt;
I have been a great fan of Dr. Knuth's paper about &lt;a href="http://arxiv.org/abs/cs/0011047"&gt; Dancing Links (Algorithm X) &lt;/a&gt;. In that paper 
Don suggests how the combinatorial search using backtracking can be improved in practice with the original idea from &lt;a href="http://portal.acm.org/citation.cfm?id=1710829"&gt;Hitotumatu and Noshita&lt;/a&gt;. One strange thing about Dancing Links is that its not Don's original idea, however Don made it popular by writing a paper about it. Don used the $DLX$ idea to solve the exact cover (matrix cover) problem and he gave several examples (e.g. Covering an rectilinear area with Pentominos) where he certain combinatorial problems to exact cover.
&lt;/p&gt;

&lt;p&gt;
I have been waiting to find a problem where I get to apply $DLX$ without reducing it to exact cover problem. I'm really happy now that simultaneous hamming neighborhood problem (given a set $S=\{s_1,s_2\ldots s_n\},\, s_i\in \Sigma^{l}$ of strings compute the set $N_d(S) = \{ t | hamming(s_i,t)\leq d ,\forall s_i \in S\}$) which I have been working lately can be solved by applying $DLX$. As I mentioned in my earlier post the algorithm to compute $N_d(S)$ needs solve a set partition problem -- which further needs an algorithm to enumerate all the subsets of a given size $r$. In my previous post we have seen how to compute $n \choose r$ efficiently with backtracking. I'm now going use $DLX$ to solve the same problem. Notice that $DLX$ is an overkill to this simple problem, however it really makes sense if we look it from the perspective of the partitioning problem -- which is what we want to solve.  $DLX$ just plays the role of UNDO operation see below.
&lt;/p&gt;

&lt;pre name="code" class="cpp"&gt;
/*Implementation of $n \choose r$ using $DLX$*/
enum_count_t EnumSubSetsCountDLX(size_t n, size_t r){
 enum_count_t n_choose_r=0;
 DLXState *dlx_sentinal = GetEnumSubSetsDLXState(n); /*Initialize the DLXState*/
 DLXState *sidx_dat[r+1], **state_idx=sidx_dat; /*item picked in the state*/
 /*total # of items picked in a given state*/
 size_t scidx_dat[r+1], *state_count_idx=scidx_dat; 
 size_t level;

 state_count_idx--; state_idx--; /*1-indexing*/
 level=1; state_count_idx[level]=0; state_idx[level] = dlx_sentinal;
 while(level){
  if(level == r+1){
   n_choose_r++;
   level--; 
   if(level) Dance(state_idx[level]);
  }else if(state_count_idx[level]+r-level &gt; n-1){ /*state_idx[level]*/
   level--; 
   if(level) Dance(state_idx[level]);
  }else{
   state_idx[level] = state_idx[level]-&gt;right; 
   Break(state_idx[level]);
   state_count_idx[level]++; 
   /*track forward*/
   state_count_idx[level+1] = state_count_idx[level]; 
   state_idx[level+1] = state_idx[level];
   level++;
  }
 }
 CleanDLXState(dlx_sentinal); /*cleanup*/
 return n_choose_r;
}

/*Break and Dance operations*/
void Break(DLXState *state){
 state-&gt;left-&gt;right = state-&gt;right;
 state-&gt;right-&gt;left = state-&gt;left;
}
void Dance(DLXState *state){
 state-&gt;left-&gt;right = state;
 state-&gt;right-&gt;left = state;
}

/*Initializes a new DLX state required to enumerate $n \choose r$*/
EnumSubSetState* GetNewEnumSStateWithDLX(DLXState *dlx_sentinal, 
 size_t n, size_t r){

 EnumSubSetState *estate = malloc(sizeof(EnumSubSetState));
 assert(estate);
 estate-&gt;dlx_sentinal = dlx_sentinal;

 estate-&gt;state_count_idx = malloc(sizeof(size_t)*(r+1));
 estate-&gt;state_idx = malloc(sizeof(DLXState *)*(r+1));
 assert(estate-&gt;state_count_idx &amp;&amp; estate-&gt;state_idx);

 (estate-&gt;state_count_idx)--; (estate-&gt;state_idx)--;

 estate-&gt;level=1; estate-&gt;state_count_idx[1]=0; 
 estate-&gt;state_idx[1] = estate-&gt;dlx_sentinal;
 estate-&gt;n = n; estate-&gt;r = r;
 return estate;

}



&lt;/pre&gt;

&lt;p&gt; Next I'll post the most interesting part which is to enumerate the partitions using $DLX$.
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-7373976059064589386?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/7373976059064589386/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=7373976059064589386&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/7373976059064589386'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/7373976059064589386'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2011/05/tech-enumerating-set-partitions-with.html' title='[TECH] Enumerating set partitions with $DLX$'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-6763305901955208323</id><published>2011-05-06T18:52:00.000-07:00</published><updated>2011-05-07T06:36:58.673-07:00</updated><title type='text'>[TECH] Enumerating subsets with backtracking and some interesting observations on the backtracking enumeration tree.</title><content type='html'>&lt;p&gt;
During my current research on enumerating all the common &lt;em&gt;Hamming&lt;/em&gt; neighborhood of a set of strings. I needed an algorithm which can enumerate seven disjoint subsets from a given set. The fundamental building block in that is an algorithm which enumerates all the subsets of size $r$ from a given set of size $n$. I'm very much aware of the standard recursive algorithm which uses the fact 
${n \choose r} = {n-1 \choose r} + {n-1 \choose r-1}$. However I wanted a much efficient version because I need to use this several times and cannot afford the constants in stack based implementations. So I wrote the following to backtracking based algorithm to enumerate the subsets. Once I did that I started observing some very interesting patterns in the number of leaves for each internal backtrack node at level $r-1$.
&lt;/p&gt; 



&lt;pre&gt;&lt;span style=' color: Green;'&gt;/*Back tracking*/&lt;/span&gt; 
enum_count_t EnumSubSetsPrint(&lt;span style=' color: Blue;'&gt;char&lt;/span&gt; *set, size_t n, size_t r){ 
    size_t state_idx_data[r+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;], i, level; 
    size_t *state_idx = state_idx_data; 
    enum_count_t n_choose_r=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;  

    set--; 
    state_idx--; 
    &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(i=&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;; i&amp;lt;=r+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;; i++){ &lt;span style=' color: Green;'&gt;/*initialize*/&lt;/span&gt; 
        state_idx[i] = &lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;; 
    } 

    level = &lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;; 
    &lt;span style=' color: Blue;'&gt;while&lt;/span&gt;(level){ 
        &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(level == r+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;){
            &lt;span style=' color: Green;'&gt;/*back track*/&lt;/span&gt; 
            &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(i=&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;; i&amp;lt;=r; i++){ 
                printf(&lt;span style=' color: Maroon;'&gt;"%c "&lt;/span&gt;, set[state_idx[i]]); 
            } 
            printf(&lt;span style=' color: Maroon;'&gt;"\n"&lt;/span&gt;); 
            n_choose_r++; 
            level--; 
        }&lt;span style=' color: Blue;'&gt;else&lt;/span&gt; &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(state_idx[level]+r-level &amp;gt; n-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;){ 
            level--; 
        }&lt;span style=' color: Blue;'&gt;else&lt;/span&gt;{  
            &lt;span style=' color: Green;'&gt;/*track forward*/&lt;/span&gt; 
            state_idx[level]++; &lt;span style=' color: Green;'&gt;/*pick a item*/&lt;/span&gt; 
            state_idx[level+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;] = state_idx[level]; 
            level++; 
        } 
    } 
    &lt;span style=' color: Blue;'&gt;return&lt;/span&gt; n_choose_r; 
} 
&lt;/pre&gt;


&lt;p&gt;
By looking at these patterns (at the end of this paragraph) I came up with the following interesting identities for $n \choose 3$ and $n \choose 4$. &lt;br&gt;

&lt;bf&gt;IDENTITY-1:&lt;/bf&gt; ${n\choose 3} = \sum_{i=1}^{n-2} (n-i)(i-1)$ &lt;br&gt;
&lt;bf&gt;IDENTITY-2:&lt;/bf&gt; ${n\choose 4} = \sum_{j=1}^{n-3}\sum_{i=1}^{n-2-j} (i)(j) $&lt;br&gt;

I'm actually printing the number of leaves under an internal node at level $r-1$ in the backtracking tree. I'm observing the following pattern.
&lt;/p&gt;

&lt;pre&gt;
=================
8 3 0

6 5 4 3 2 1 
5 4 3 2 1 
4 3 2 1 
3 2 1 
2 1 
1 
(8 \choose 3) = 56 

Please enter n and r &lt; n and print_option
 (e.g. 15 14 1 or 15 14 0)
9 3 0

7 6 5 4 3 2 1 
6 5 4 3 2 1 
5 4 3 2 1 
4 3 2 1 
3 2 1 
2 1 
1 
(9 \choose 3) = 84 

Please enter n and r &lt; n and print_option
 (e.g. 15 14 1 or 15 14 0)
10 3 0

8 7 6 5 4 3 2 1 
7 6 5 4 3 2 1 
6 5 4 3 2 1 
5 4 3 2 1 
4 3 2 1 
3 2 1 
2 1 
1 
(10 \choose 3) = 120 
Please enter n and r &lt; n and print_option
 (e.g. 15 14 1 or 15 14 0)
11 3 0

9 8 7 6 5 4 3 2 1 
8 7 6 5 4 3 2 1 
7 6 5 4 3 2 1 
6 5 4 3 2 1 
5 4 3 2 1 
4 3 2 1 
3 2 1 
2 1 
1 
===============================

The following are for $n \choose 4$ for various values of $n$.
===============================
8 4 0

5 4 3 2 1 
4 3 2 1 
3 2 1 
2 1 
1 
4 3 2 1 
3 2 1 
2 1 
1 
3 2 1 
2 1 
1 
2 1 
1 
1 
(8 \choose 4) = 70 

Please enter n and r &lt; n and print_option
 (e.g. 15 14 1 or 15 14 0)
9 4 0

6 5 4 3 2 1 
5 4 3 2 1 
4 3 2 1 
3 2 1 
2 1 
1 
5 4 3 2 1 
4 3 2 1 
3 2 1 
2 1 
1 
4 3 2 1 
3 2 1 
2 1 
1 
3 2 1 
2 1 
1 
2 1 
1 
1 

===============================
&lt;/pre&gt;

&lt;p&gt;
Play around with this program &lt;a href="http://trinity.engr.uconn.edu/Enumerate.c"&gt;Enumerate.c&lt;/a&gt; , &lt;a href="http://trinity.engr.uconn.edu/Enumerate.h"&gt;Enumerate.h&lt;/a&gt;.
&lt;/p&gt;

&lt;p&gt;
Finally I enabled $LaTeX$ setting for the blog.
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-6763305901955208323?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/6763305901955208323/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=6763305901955208323&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/6763305901955208323'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/6763305901955208323'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2011/05/tech-enumerating-subsets-with.html' title='[TECH] Enumerating subsets with backtracking and some interesting observations on the backtracking enumeration tree.'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-3658627980372573088</id><published>2011-05-05T16:46:00.000-07:00</published><updated>2011-05-05T17:10:41.918-07:00</updated><title type='text'>[THEORY] Is nature a giant guessing algorithm ?</title><content type='html'>&lt;p&gt; I was reading &lt;a href="http://rjlipton.wordpress.com/"&gt;Dr. Lipton's blog&lt;/a&gt; on guessing and was really impressed on how he relates the power of guessing with the question whether &lt;b&gt;P=NP&lt;/b&gt; or &lt;b&gt;P!=NP&lt;/b&gt;. &lt;/p&gt;

&lt;p&gt;
Looks like &lt;i&gt;nature&lt;/i&gt; on the other had seems to be solving several combinatorial problems almost instantly (e.g. folding of the proteins to minimize its energy), does nature guess the solution to the problem ?. One way to guess a solution to a problem is to look inside the building blocks which formulated the problem. Dr. Lipton gives an example were we were supposed to guess the digits which can open a lock -- the lock we normally use in the GYM. It may be hard to guess the digits which can open a lock without any help. However if we can get an X-ray of the levers we can guess the solution to the problem more easily. So does this mean nature looks at the problems in a totally different perspective ? , is there something very intuitive to the nature which the humans fail to recognize ?.
&lt;/p&gt;

&lt;p&gt; 
Why did all the great mathematicians failed to find a polynomial solution 3-SAT ? -- or prove it does not exist. Is there something missing in the way we are looking at a digital circuit ? , can we design guessing algorithms to solve the NP-Complete problems ?. We don't know the answers for all these. But I'm sure that nature is a great guessing algorithm and it may be impossible for us to guess its guessing algorithm.
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-3658627980372573088?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/3658627980372573088/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=3658627980372573088&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/3658627980372573088'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/3658627980372573088'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2011/05/theory-is-nature-gaint-guessing.html' title='[THEORY] Is nature a giant guessing algorithm ?'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-503494992758026404</id><published>2011-04-12T12:46:00.000-07:00</published><updated>2011-04-12T13:14:46.486-07:00</updated><title type='text'>[TECH] Unbuffered message logging of interactive programs.</title><content type='html'>&lt;p&gt;
We generally use one of the following methods to log the output messages of programs which print a lot of messages. 
&lt;ul&gt;
&lt;li&gt; &lt;pre&gt; $ ./program &gt;&amp; message.log &lt;/pre&gt;
&lt;li&gt; &lt;pre&gt; $ ./program |&amp; tee message.log &lt;/pre&gt;
&lt;/ul&gt;
Since &lt;b&gt;stdout&lt;/b&gt; is line buffered we expect the same to hold when we re-direct &lt;b&gt;stdout&lt;/b&gt; or any other stream. However this is not true if you keep monitoring the program status with &lt;b&gt; tail -f message.log&lt;/b&gt; you will not notice any output from the program this is because the redirection is not line buffered. And in certain unfortunate cases when the running program aborts the redirection may not even flush the buffers and you find that &lt;b&gt;message.log&lt;/b&gt; is empty and there is NO way to figure out what has happened.
&lt;/p&gt;

&lt;p&gt;One obvious way to fix this is to put &lt;b&gt;fflush(stdout)&lt;/b&gt; after every &lt;b&gt;printf&lt;/b&gt; statement you have, this is OK for small programs but for very large programs its really tedious. I came up with the following technique to solve this problem. This solution is generic.
&lt;/p&gt;
&lt;pre&gt;
[main.c]

int main(int argc, char **argv){

 ForceLogMessages("message.log");
 ....
 ... 
}

void ForceLogMessages(const char *mesg_file){
    int ret_setvbuf;
    /*close the stdout and re-open a text file*/
    fclose(stdout);
    stdout = fopen(name, "w");
    //make stdout unbuffered
    ret_setvbuf = setvbuf(stdout, (char *) NULL, _IOLBF, 0);   
    if(ret_setvbuf){
        fprintf(stderr, "UNABLE TO MAKE stdout UNBUFFERED %s", strerror(errno));
    }   
    assert(stdout);
}
&lt;/pre&gt;

&lt;p&gt;
Now if we run the program and we can monitor the status with &lt;b&gt;tail -f message.log&lt;/b&gt; since we have made &lt;b&gt;stdout&lt;/b&gt; unbuffered we can see a message in message.log every time a &lt;b&gt;printf&lt;/b&gt; is executed in the original program and you can know what exactly is happening.
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-503494992758026404?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/503494992758026404/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=503494992758026404&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/503494992758026404'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/503494992758026404'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2011/04/tech-unbuffered-message-logging-of.html' title='[TECH] Unbuffered message logging of interactive programs.'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-2729298013791167995</id><published>2011-03-24T18:59:00.000-07:00</published><updated>2011-03-24T19:11:35.555-07:00</updated><title type='text'>[TECH] juggernaut-asm: An out-of-core sequence assembler</title><content type='html'>&lt;p&gt;
Development updates on the juggernaut-asm project.I'm now branching off the trunk to implement the feature which avoids using the UNIX sort. 
To checkout the main branch as follows. This is the version of the code I used to obtain the results on 4million reads which the in-memory algorithm of Velvet could not handle.
&lt;/p&gt;
&lt;pre&gt;
cvs -d:pserver:anonymous@juggernaut-asm.cvs.sourceforge.net:/cvsroot/juggernaut-asm co .
&lt;/pre&gt;
&lt;p&gt;
The code to replace the unix sort being developed in the branch name 'replace-unix-sort'.
&lt;/p&gt;
&lt;pre&gt;
cvs -d:ext:vamsi99@juggernaut-asm.cvs.sourceforge.net:/cvsroot/juggernaut-asm co -r replace-unix-sort .
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-2729298013791167995?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/2729298013791167995/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=2729298013791167995&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/2729298013791167995'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/2729298013791167995'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2011/03/tech-juggernaut-asm-out-of-core.html' title='[TECH] juggernaut-asm: An out-of-core sequence assembler'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-4469039490125647124</id><published>2011-03-23T13:42:00.000-07:00</published><updated>2011-03-23T14:18:48.260-07:00</updated><title type='text'>[TECH] External R-Way Merge sorting.</title><content type='html'>&lt;p&gt;
http://lib-ex-sort.sourceforge.net/ is an external sorting program the following are the limitations I wish to remove before I leave in May. Most of them are engineering changes but
are very useful for several algorithms based on external sorting.
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt; Currently the size of each key is a constant. We need to remove this by adding a key_header for each key.
&lt;li&gt; Use MMAP for integer sorting to avoid copy between user and kernel space.
&lt;li&gt; Support for sorting when the data spans multiple files.
&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-4469039490125647124?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://lib-ex-sort.sourceforge.net/' title='[TECH] External R-Way Merge sorting.'/><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/4469039490125647124/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=4469039490125647124&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/4469039490125647124'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/4469039490125647124'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2011/03/tech-external-r-way-merge-sorting.html' title='[TECH] External R-Way Merge sorting.'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-890929752016257490</id><published>2010-08-27T16:19:00.000-07:00</published><updated>2010-08-27T16:24:56.574-07:00</updated><title type='text'>[TECH] Combinatorial counting under symmetries with Polya's Theorem</title><content type='html'>&lt;p&gt; Recently I have started looking at the problem of enumerating Graphs. During my journey I was thrilled at the beauty of Polya's theorem. After applying the theorem on several examples I felt that I should write an article which explains the context and need for Polya's theorem.
&lt;/p&gt;

&lt;p&gt;This is the first blog I'm writing after taking a break over the summer. I had few things which had happened to me recently. I'm going to talk about them some other time as they are more philosophical.
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-890929752016257490?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/890929752016257490/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=890929752016257490&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/890929752016257490'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/890929752016257490'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2010/08/tech-combinatorial-counting-under.html' title='[TECH] Combinatorial counting under symmetries with Polya&apos;s Theorem'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-8974902085800857179</id><published>2010-04-09T01:49:00.000-07:00</published><updated>2010-04-09T02:00:53.923-07:00</updated><title type='text'>[TECH] Super-fast tokenizing of sequence word patterns</title><content type='html'>&lt;html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;


&lt;meta http-equiv="content-type" content="text/html; charset=utf-8"&gt;
&lt;title&gt;C++ code colored by C++2HTML&lt;/title&gt;
&lt;meta name="generator" content="C++2HTML by Jasper Bedaux"&gt;
&lt;!-- To generate your own colored code visit http://www.bedaux.net/cpp2html/ --&gt;
&lt;style type="text/css"&gt;
.comment { color: #999999; font-style: italic; }
.pre { color: #000099; }
.string { color: #009900; }
.char { color: #009900; }
.float { color: #996600; }
.int { color: #999900; }
.bool { color: #000000; font-weight: bold; }
.type { color: #FF6633; }
.flow { color: #FF0000; }
.keyword { color: #990000; }
.operator { color: #663300; font-weight: bold; }
.operator { color: #663300; font-weight: bold; }
&lt;/style&gt;
&lt;/head&gt;&lt;body&gt;
&lt;pre&gt;&lt;span class="pre"&gt;#!/bin/perl 
#
# AHO-CORASICK-TOKENIZER on words, will also work on any delemiter.
# INPUT(1): Set of patterns (sequence of words) 'P'
# INPUT(2): Text 'T' 
# OUTPUT: report all the occuring patterns -- we don't even 
# want to know their locations. 
#
# NOTE: We don't want to worry much about the time required to 
# construct the failure function. All we need is to improve the
# scan speed.
#
# PATTERN FILE FORMAT:
# &amp;lt;annotation&amp;gt; $$$ pattern
#
# vamsik@engr.uconn.edu 04/08/2010
#
&lt;/span&gt;&lt;span class="operator"&gt;
(&lt;/span&gt;$#ARGV&lt;span class="operator"&gt; ==&lt;/span&gt;&lt;span class="int"&gt; 1&lt;/span&gt;&lt;span class="operator"&gt;)&lt;/span&gt;&lt;span class="operator"&gt; or&lt;/span&gt; die&lt;span class="operator"&gt;(&lt;/span&gt;&lt;span class="string"&gt;"USAGE: perl &amp;lt;name&amp;gt; pattern_file text_file"&lt;/span&gt;&lt;span class="operator"&gt;);&lt;/span&gt;

open&lt;span class="operator"&gt;(&lt;/span&gt;PATTERN_FILE&lt;span class="operator"&gt;,&lt;/span&gt; $ARGV&lt;span class="operator"&gt;[&lt;/span&gt;&lt;span class="int"&gt;0&lt;/span&gt;&lt;span class="operator"&gt;])&lt;/span&gt;&lt;span class="operator"&gt; or&lt;/span&gt; die&lt;span class="operator"&gt;(&lt;/span&gt;$&lt;span class="operator"&gt;!);&lt;/span&gt;

open&lt;span class="operator"&gt;(&lt;/span&gt;TEXT_FILE&lt;span class="operator"&gt;,&lt;/span&gt; $ARGV&lt;span class="operator"&gt;[&lt;/span&gt;&lt;span class="int"&gt;1&lt;/span&gt;&lt;span class="operator"&gt;])&lt;/span&gt;&lt;span class="operator"&gt; or&lt;/span&gt; die&lt;span class="operator"&gt;(&lt;/span&gt;$&lt;span class="operator"&gt;!);
%&lt;/span&gt;AC_TREE&lt;span class="operator"&gt;;
%&lt;/span&gt;PATTERN_HASH&lt;span class="operator"&gt;;&lt;/span&gt;

$ANNOT_DELIM&lt;span class="operator"&gt; =&lt;/span&gt;&lt;span class="string"&gt; ";;a;;"&lt;/span&gt;&lt;span class="operator"&gt;;&lt;/span&gt;
$FAILED_DELIM&lt;span class="operator"&gt; =&lt;/span&gt;&lt;span class="string"&gt; ";;f;;"&lt;/span&gt;&lt;span class="operator"&gt;;&lt;/span&gt; 
$HEIGHT_DELIM&lt;span class="operator"&gt; =&lt;/span&gt;&lt;span class="string"&gt; ";;h;;"&lt;/span&gt;&lt;span class="operator"&gt;;&lt;/span&gt; #to move within the text

sub BuildKwordTree&lt;span class="operator"&gt;{&lt;/span&gt;&lt;span class="pre"&gt;

# root of the Aho-Corasick tree #
&lt;/span&gt;	my @params&lt;span class="operator"&gt; =&lt;/span&gt; @_&lt;span class="operator"&gt;;&lt;/span&gt;
	my $ac_root&lt;span class="operator"&gt; =&lt;/span&gt; $params&lt;span class="operator"&gt;[&lt;/span&gt;&lt;span class="int"&gt;0&lt;/span&gt;&lt;span class="operator"&gt;];&lt;/span&gt;

	my $PFILE&lt;span class="operator"&gt; =&lt;/span&gt; $params&lt;span class="operator"&gt;[&lt;/span&gt;&lt;span class="int"&gt;1&lt;/span&gt;&lt;span class="operator"&gt;];&lt;/span&gt;
	my&lt;span class="operator"&gt; (&lt;/span&gt;$line&lt;span class="operator"&gt;,&lt;/span&gt; $pword_list&lt;span class="operator"&gt;,&lt;/span&gt; $pattern&lt;span class="operator"&gt;,&lt;/span&gt; $curr_node&lt;span class="operator"&gt;,&lt;/span&gt; $pword&lt;span class="operator"&gt;);&lt;/span&gt;&lt;span class="flow"&gt;

	
	while&lt;/span&gt;&lt;span class="operator"&gt;(&amp;lt;&lt;/span&gt;$PFILE&lt;span class="operator"&gt;&amp;gt;){&lt;/span&gt;
		$line&lt;span class="operator"&gt; =&lt;/span&gt; $_&lt;span class="operator"&gt;;&lt;/span&gt; chomp&lt;span class="operator"&gt;(&lt;/span&gt;$line&lt;span class="operator"&gt;);&lt;/span&gt;&lt;span class="flow"&gt;

		if&lt;/span&gt;&lt;span class="operator"&gt;(&lt;/span&gt;$line&lt;span class="operator"&gt; =~ /([^\&lt;/span&gt;$&lt;span class="operator"&gt;]+)\&lt;/span&gt;$&lt;span class="operator"&gt;\&lt;/span&gt;$&lt;span class="operator"&gt;\&lt;/span&gt;$&lt;span class="operator"&gt; (.*)/){&lt;/span&gt;
			$annotation&lt;span class="operator"&gt; =&lt;/span&gt; $&lt;span class="int"&gt;1&lt;/span&gt;&lt;span class="operator"&gt;;&lt;/span&gt;

			$pattern&lt;span class="operator"&gt; =&lt;/span&gt; $&lt;span class="int"&gt;2&lt;/span&gt;&lt;span class="operator"&gt;;&lt;/span&gt;&lt;span class="pre"&gt;
# split the pattern into words delimited by any #
# non-newline character. #
&lt;/span&gt;			@pword_list&lt;span class="operator"&gt; =&lt;/span&gt; split&lt;span class="operator"&gt;(/\&lt;/span&gt;s&lt;span class="operator"&gt;+/,&lt;/span&gt; $pattern&lt;span class="operator"&gt;);&lt;/span&gt;

			$curr_node&lt;span class="operator"&gt; =&lt;/span&gt; $ac_root&lt;span class="operator"&gt;;&lt;/span&gt; 
			foreach $pword&lt;span class="operator"&gt; (&lt;/span&gt;@pword_list&lt;span class="operator"&gt;){&lt;/span&gt;
				$&lt;span class="operator"&gt;{&lt;/span&gt;$curr_node&lt;span class="operator"&gt;}{&lt;/span&gt;$pword&lt;span class="operator"&gt;} = 
					{}&lt;/span&gt; unless exists $&lt;span class="operator"&gt;{&lt;/span&gt;$curr_node&lt;span class="operator"&gt;}{&lt;/span&gt;$pword&lt;span class="operator"&gt;};&lt;/span&gt;

				$curr_node&lt;span class="operator"&gt; =&lt;/span&gt; $&lt;span class="operator"&gt;{&lt;/span&gt;$curr_node&lt;span class="operator"&gt;}{&lt;/span&gt;$pword&lt;span class="operator"&gt;};
			}&lt;/span&gt;&lt;span class="pre"&gt;
# put-the annotation into the last-node of the key-word tree 
&lt;/span&gt;			$&lt;span class="operator"&gt;{&lt;/span&gt;$curr_node&lt;span class="operator"&gt;}{&lt;/span&gt;$ANNOT_DELIM&lt;span class="operator"&gt;} =&lt;/span&gt; $annotation&lt;span class="operator"&gt;;
		}
	}
}&lt;/span&gt;&lt;span class="pre"&gt;

#
# Build the failure function level-by level
#
#
&lt;/span&gt;sub BuildFailureFunction&lt;span class="operator"&gt;{&lt;/span&gt;
	my @params&lt;span class="operator"&gt; =&lt;/span&gt; @_&lt;span class="operator"&gt;;&lt;/span&gt;
	my $ac_root&lt;span class="operator"&gt; =&lt;/span&gt; $params&lt;span class="operator"&gt;[&lt;/span&gt;&lt;span class="int"&gt;0&lt;/span&gt;&lt;span class="operator"&gt;];&lt;/span&gt;

	my&lt;span class="operator"&gt; (&lt;/span&gt;$k&lt;span class="operator"&gt;,&lt;/span&gt; @bfs_list&lt;span class="operator"&gt;,&lt;/span&gt; $keyword&lt;span class="operator"&gt;);&lt;/span&gt;&lt;span class="pre"&gt; 
#
# Incremental algorithm; For level-1 its the $ac_root itself  
#
&lt;/span&gt;	$&lt;span class="operator"&gt;{&lt;/span&gt;$ac_root&lt;span class="operator"&gt;}{&lt;/span&gt;$FAILED_DELIM&lt;span class="operator"&gt;} =&lt;/span&gt; $ac_root&lt;span class="operator"&gt;;&lt;/span&gt;

	$&lt;span class="operator"&gt;{&lt;/span&gt;$ac_root&lt;span class="operator"&gt;}{&lt;/span&gt;$HEIGHT_DELIM&lt;span class="operator"&gt;} =&lt;/span&gt;&lt;span class="int"&gt; 0&lt;/span&gt;&lt;span class="operator"&gt;;&lt;/span&gt;
	foreach $k&lt;span class="operator"&gt; (&lt;/span&gt;keys&lt;span class="operator"&gt; %&lt;/span&gt;$ac_root&lt;span class="operator"&gt;){&lt;/span&gt;&lt;span class="flow"&gt;

		if&lt;/span&gt;&lt;span class="operator"&gt;((&lt;/span&gt;$k eq $FAILED_DELIM&lt;span class="operator"&gt;)&lt;/span&gt;&lt;span class="operator"&gt; or&lt;/span&gt;&lt;span class="operator"&gt; (&lt;/span&gt;$k eq $ANNOT_DELIM&lt;span class="operator"&gt;)&lt;/span&gt;&lt;span class="operator"&gt;
			or&lt;/span&gt;&lt;span class="operator"&gt; (&lt;/span&gt;$k eq $HEIGHT_DELIM&lt;span class="operator"&gt;)){&lt;/span&gt;

			next&lt;span class="operator"&gt;;
		}&lt;/span&gt;
		$&lt;span class="operator"&gt;{&lt;/span&gt;$&lt;span class="operator"&gt;{&lt;/span&gt;$ac_root&lt;span class="operator"&gt;}{&lt;/span&gt;$k&lt;span class="operator"&gt;}}{&lt;/span&gt;$FAILED_DELIM&lt;span class="operator"&gt;} =&lt;/span&gt;  $ac_root&lt;span class="operator"&gt;;&lt;/span&gt;

		$&lt;span class="operator"&gt;{&lt;/span&gt;$&lt;span class="operator"&gt;{&lt;/span&gt;$ac_root&lt;span class="operator"&gt;}{&lt;/span&gt;$k&lt;span class="operator"&gt;}}{&lt;/span&gt;$HEIGHT_DELIM&lt;span class="operator"&gt;} =&lt;/span&gt;&lt;span class="int"&gt; 1&lt;/span&gt;&lt;span class="operator"&gt;;&lt;/span&gt;
		push&lt;span class="operator"&gt;(&lt;/span&gt;@bfs_list&lt;span class="operator"&gt;,&lt;/span&gt; $&lt;span class="operator"&gt;{&lt;/span&gt;$ac_root&lt;span class="operator"&gt;}{&lt;/span&gt;$k&lt;span class="operator"&gt;});
	}&lt;/span&gt;&lt;span class="flow"&gt;

	
	while&lt;/span&gt;&lt;span class="operator"&gt;(&lt;/span&gt;$#bfs_list&lt;span class="operator"&gt; &amp;gt;=&lt;/span&gt;&lt;span class="int"&gt; 0&lt;/span&gt;&lt;span class="operator"&gt;){&lt;/span&gt;
		$nref&lt;span class="operator"&gt; =&lt;/span&gt; shift&lt;span class="operator"&gt;(&lt;/span&gt;@bfs_list&lt;span class="operator"&gt;);&lt;/span&gt; #node

		foreach $keyword&lt;span class="operator"&gt; (&lt;/span&gt;keys&lt;span class="operator"&gt; %&lt;/span&gt;$nref&lt;span class="operator"&gt;){&lt;/span&gt;&lt;span class="flow"&gt;

			if&lt;/span&gt;&lt;span class="operator"&gt;((&lt;/span&gt;$keyword eq $FAILED_DELIM&lt;span class="operator"&gt;)&lt;/span&gt;&lt;span class="operator"&gt; or&lt;/span&gt;&lt;span class="operator"&gt; 
					(&lt;/span&gt;$keyword eq $ANNOT_DELIM&lt;span class="operator"&gt;)&lt;/span&gt;&lt;span class="operator"&gt; or&lt;/span&gt;&lt;span class="operator"&gt; 
					(&lt;/span&gt;$keyword eq $HEIGHT_DELIM&lt;span class="operator"&gt;)){&lt;/span&gt;

				next&lt;span class="operator"&gt;;
			}&lt;/span&gt;

			$nnref&lt;span class="operator"&gt; =&lt;/span&gt; $&lt;span class="operator"&gt;{&lt;/span&gt;$nref&lt;span class="operator"&gt;}{&lt;/span&gt;$keyword&lt;span class="operator"&gt;};&lt;/span&gt;

			$fpref&lt;span class="operator"&gt; =&lt;/span&gt; $&lt;span class="operator"&gt;{&lt;/span&gt;$nref&lt;span class="operator"&gt;}{&lt;/span&gt;$FAILED_DELIM&lt;span class="operator"&gt;};&lt;/span&gt;&lt;span class="flow"&gt; 
			while&lt;/span&gt;&lt;span class="operator"&gt;(!(&lt;/span&gt;exists $&lt;span class="operator"&gt;{&lt;/span&gt;$fpref&lt;span class="operator"&gt;}{&lt;/span&gt;$keyword&lt;span class="operator"&gt;})&lt;/span&gt;&lt;span class="operator"&gt;

				and&lt;/span&gt; $fpref&lt;span class="operator"&gt; !=&lt;/span&gt; $ac_root&lt;span class="operator"&gt;){&lt;/span&gt;
				$fpref&lt;span class="operator"&gt; =&lt;/span&gt; $&lt;span class="operator"&gt;{&lt;/span&gt;$fpref&lt;span class="operator"&gt;}{&lt;/span&gt;$FAILED_DELIM&lt;span class="operator"&gt;};
			}&lt;/span&gt;&lt;span class="flow"&gt;

			if&lt;/span&gt;&lt;span class="operator"&gt;(&lt;/span&gt;exists $&lt;span class="operator"&gt;{&lt;/span&gt;$fpref&lt;span class="operator"&gt;}{&lt;/span&gt;$keyword&lt;span class="operator"&gt;}){&lt;/span&gt;
				$&lt;span class="operator"&gt;{&lt;/span&gt;$nnref&lt;span class="operator"&gt;}{&lt;/span&gt;$FAILED_DELIM&lt;span class="operator"&gt;} =&lt;/span&gt; $&lt;span class="operator"&gt;{&lt;/span&gt;$fpref&lt;span class="operator"&gt;}{&lt;/span&gt;$keyword&lt;span class="operator"&gt;};
			}&lt;/span&gt;&lt;span class="flow"&gt;else&lt;/span&gt;&lt;span class="operator"&gt;{&lt;/span&gt;

				$&lt;span class="operator"&gt;{&lt;/span&gt;$nnref&lt;span class="operator"&gt;}{&lt;/span&gt;$FAILED_DELIM&lt;span class="operator"&gt;} =&lt;/span&gt; $ac_root&lt;span class="operator"&gt;; 
			}&lt;/span&gt;
			$&lt;span class="operator"&gt;{&lt;/span&gt;$nnref&lt;span class="operator"&gt;}{&lt;/span&gt;$HEIGHT_DELIM&lt;span class="operator"&gt;} =&lt;/span&gt; $&lt;span class="operator"&gt;{&lt;/span&gt;$nref&lt;span class="operator"&gt;}{&lt;/span&gt;$HEIGHT_DELIM&lt;span class="operator"&gt;}+&lt;/span&gt;&lt;span class="int"&gt;1&lt;/span&gt;&lt;span class="operator"&gt;;&lt;/span&gt;

			push&lt;span class="operator"&gt;(&lt;/span&gt;@bfs_list&lt;span class="operator"&gt;,&lt;/span&gt; $nnref&lt;span class="operator"&gt;);
		}
	}
}&lt;/span&gt;&lt;span class="pre"&gt;
#
# Reads word delimited text from the stream or a file
#
&lt;/span&gt;sub MatchWordDelimText&lt;span class="operator"&gt;{&lt;/span&gt;
	my @params&lt;span class="operator"&gt; =&lt;/span&gt; @_&lt;span class="operator"&gt;;&lt;/span&gt;

	my $ac_root&lt;span class="operator"&gt; =&lt;/span&gt; $params&lt;span class="operator"&gt;[&lt;/span&gt;&lt;span class="int"&gt;0&lt;/span&gt;&lt;span class="operator"&gt;];&lt;/span&gt;
	my $stream&lt;span class="operator"&gt; =&lt;/span&gt; $params&lt;span class="operator"&gt;[&lt;/span&gt;&lt;span class="int"&gt;1&lt;/span&gt;&lt;span class="operator"&gt;];&lt;/span&gt;

	my&lt;span class="operator"&gt; (&lt;/span&gt;$curr_state&lt;span class="operator"&gt;,&lt;/span&gt; $annot&lt;span class="operator"&gt;,&lt;/span&gt; $sword&lt;span class="operator"&gt;,&lt;/span&gt; $c&lt;span class="operator"&gt;,&lt;/span&gt; $height&lt;span class="operator"&gt;);&lt;/span&gt;

	my $line&lt;span class="operator"&gt;;&lt;/span&gt;&lt;span class="flow"&gt;

	while&lt;/span&gt;&lt;span class="operator"&gt;(&amp;lt;&lt;/span&gt;$stream&lt;span class="operator"&gt;&amp;gt;){&lt;/span&gt;
		$line&lt;span class="operator"&gt; =&lt;/span&gt; $_&lt;span class="operator"&gt;;&lt;/span&gt; chomp&lt;span class="operator"&gt;(&lt;/span&gt;$line&lt;span class="operator"&gt;);&lt;/span&gt;

		$curr_state&lt;span class="operator"&gt; =&lt;/span&gt; $ac_root&lt;span class="operator"&gt;;&lt;/span&gt;
		@swords&lt;span class="operator"&gt; =&lt;/span&gt; split&lt;span class="operator"&gt;(/\&lt;/span&gt;s&lt;span class="operator"&gt;+/,&lt;/span&gt; $_&lt;span class="operator"&gt;);&lt;/span&gt;

		$c&lt;span class="operator"&gt; =&lt;/span&gt;&lt;span class="int"&gt; 0&lt;/span&gt;&lt;span class="operator"&gt;;&lt;/span&gt;&lt;span class="flow"&gt; 
		while&lt;/span&gt;&lt;span class="operator"&gt;(&lt;/span&gt;$c&lt;span class="operator"&gt; &amp;lt;=&lt;/span&gt; $#swords&lt;span class="operator"&gt;){&lt;/span&gt;

			$sword&lt;span class="operator"&gt; =&lt;/span&gt; $swords&lt;span class="operator"&gt;[&lt;/span&gt;$c&lt;span class="operator"&gt;];&lt;/span&gt;&lt;span class="pre"&gt;
# Change the state of the automaton by reading the input 
#			print "I:$sword C:$c 1:$curr_state ";
&lt;/span&gt;&lt;span class="flow"&gt;			if&lt;/span&gt;&lt;span class="operator"&gt;(&lt;/span&gt;exists $&lt;span class="operator"&gt;{&lt;/span&gt;$curr_state&lt;span class="operator"&gt;}{&lt;/span&gt;$sword&lt;span class="operator"&gt;}){&lt;/span&gt;

				$curr_state&lt;span class="operator"&gt; =&lt;/span&gt; $&lt;span class="operator"&gt;{&lt;/span&gt;$curr_state&lt;span class="operator"&gt;}{&lt;/span&gt;$sword&lt;span class="operator"&gt;};&lt;/span&gt;
				$c&lt;span class="operator"&gt;++;
			}&lt;/span&gt;&lt;span class="flow"&gt;else&lt;/span&gt;&lt;span class="operator"&gt;{&lt;/span&gt;&lt;span class="flow"&gt;

				if&lt;/span&gt;&lt;span class="operator"&gt;(&lt;/span&gt;$curr_state&lt;span class="operator"&gt; ==&lt;/span&gt; $ac_root&lt;span class="operator"&gt;){&lt;/span&gt;
					$c&lt;span class="operator"&gt;++;
				}&lt;/span&gt;
				$curr_state&lt;span class="operator"&gt; =&lt;/span&gt; $&lt;span class="operator"&gt;{&lt;/span&gt;$curr_state&lt;span class="operator"&gt;}{&lt;/span&gt;$FAILED_DELIM&lt;span class="operator"&gt;};
			}&lt;/span&gt;&lt;span class="pre"&gt;

#			print "2:$curr_state \n";
&lt;/span&gt;&lt;span class="flow"&gt;			if&lt;/span&gt;&lt;span class="operator"&gt;(&lt;/span&gt;exists $&lt;span class="operator"&gt;{&lt;/span&gt;$curr_state&lt;span class="operator"&gt;}{&lt;/span&gt;$ANNOT_DELIM&lt;span class="operator"&gt;}){&lt;/span&gt;
				$annot&lt;span class="operator"&gt; =&lt;/span&gt; $&lt;span class="operator"&gt;{&lt;/span&gt;$curr_state&lt;span class="operator"&gt;}{&lt;/span&gt;$ANNOT_DELIM&lt;span class="operator"&gt;};&lt;/span&gt;

				print&lt;span class="string"&gt; "$annot \n"&lt;/span&gt;&lt;span class="operator"&gt;;
			}
		}
	}
}&lt;/span&gt;

sub StressTestMatchWordDelimText&lt;span class="operator"&gt;{&lt;/span&gt;
	my @params&lt;span class="operator"&gt; =&lt;/span&gt; @_&lt;span class="operator"&gt;;&lt;/span&gt;

	my $ac_root&lt;span class="operator"&gt; =&lt;/span&gt; $params&lt;span class="operator"&gt;[&lt;/span&gt;&lt;span class="int"&gt;0&lt;/span&gt;&lt;span class="operator"&gt;];&lt;/span&gt;
	my $stream&lt;span class="operator"&gt; =&lt;/span&gt; $params&lt;span class="operator"&gt;[&lt;/span&gt;&lt;span class="int"&gt;1&lt;/span&gt;&lt;span class="operator"&gt;];&lt;/span&gt;

	my&lt;span class="operator"&gt; (&lt;/span&gt;$curr_state&lt;span class="operator"&gt;,&lt;/span&gt; $annot&lt;span class="operator"&gt;,&lt;/span&gt; $sword&lt;span class="operator"&gt;,&lt;/span&gt; $c&lt;span class="operator"&gt;,&lt;/span&gt; $height&lt;span class="operator"&gt;);&lt;/span&gt;

	my $line&lt;span class="operator"&gt;;&lt;/span&gt;
	my&lt;span class="operator"&gt; (&lt;/span&gt;$stress_me&lt;span class="operator"&gt;,&lt;/span&gt; $ss&lt;span class="operator"&gt;);&lt;/span&gt;
	$line&lt;span class="operator"&gt; = &amp;lt;&lt;/span&gt;$stream&lt;span class="operator"&gt;&amp;gt;;&lt;/span&gt;

	print&lt;span class="string"&gt; "ABSTRACT: $line\n"&lt;/span&gt;&lt;span class="operator"&gt;;&lt;/span&gt;
	chomp&lt;span class="operator"&gt;(&lt;/span&gt;$line&lt;span class="operator"&gt;);&lt;/span&gt;
	$stress_me&lt;span class="operator"&gt; =&lt;/span&gt;&lt;span class="int"&gt; 1000000&lt;/span&gt;&lt;span class="operator"&gt;;&lt;/span&gt;&lt;span class="flow"&gt;

	for&lt;/span&gt;&lt;span class="operator"&gt;(&lt;/span&gt;$s&lt;span class="operator"&gt;=&lt;/span&gt;&lt;span class="int"&gt;0&lt;/span&gt;&lt;span class="operator"&gt;;&lt;/span&gt; $s&lt;span class="operator"&gt;&amp;lt;&lt;/span&gt; $stress_me&lt;span class="operator"&gt;;&lt;/span&gt; $s&lt;span class="operator"&gt;++){&lt;/span&gt;&lt;span class="flow"&gt;
		if&lt;/span&gt;&lt;span class="operator"&gt;(&lt;/span&gt;$s&lt;span class="operator"&gt;%&lt;/span&gt;&lt;span class="int"&gt;100000&lt;/span&gt;&lt;span class="operator"&gt; ==&lt;/span&gt;&lt;span class="int"&gt; 0&lt;/span&gt;&lt;span class="operator"&gt;){&lt;/span&gt;

			print&lt;span class="string"&gt; "iteration $s \n"&lt;/span&gt;&lt;span class="operator"&gt;;
		}&lt;/span&gt;
		$curr_state&lt;span class="operator"&gt; =&lt;/span&gt; $ac_root&lt;span class="operator"&gt;;&lt;/span&gt;
		@swords&lt;span class="operator"&gt; =&lt;/span&gt; split&lt;span class="operator"&gt;(/\&lt;/span&gt;s&lt;span class="operator"&gt;+/,&lt;/span&gt; $_&lt;span class="operator"&gt;);&lt;/span&gt;

		$c&lt;span class="operator"&gt; =&lt;/span&gt;&lt;span class="int"&gt; 0&lt;/span&gt;&lt;span class="operator"&gt;;&lt;/span&gt;&lt;span class="flow"&gt; 
		while&lt;/span&gt;&lt;span class="operator"&gt;(&lt;/span&gt;$c&lt;span class="operator"&gt; &amp;lt;=&lt;/span&gt; $#swords&lt;span class="operator"&gt;){&lt;/span&gt;

			$sword&lt;span class="operator"&gt; =&lt;/span&gt; $swords&lt;span class="operator"&gt;[&lt;/span&gt;$c&lt;span class="operator"&gt;];&lt;/span&gt;&lt;span class="pre"&gt;
# Change the state of the automaton by reading the input 
#			print "I:$sword C:$c 1:$curr_state ";
&lt;/span&gt;&lt;span class="flow"&gt;			if&lt;/span&gt;&lt;span class="operator"&gt;(&lt;/span&gt;exists $&lt;span class="operator"&gt;{&lt;/span&gt;$curr_state&lt;span class="operator"&gt;}{&lt;/span&gt;$sword&lt;span class="operator"&gt;}){&lt;/span&gt;

				$curr_state&lt;span class="operator"&gt; =&lt;/span&gt; $&lt;span class="operator"&gt;{&lt;/span&gt;$curr_state&lt;span class="operator"&gt;}{&lt;/span&gt;$sword&lt;span class="operator"&gt;};&lt;/span&gt;
				$c&lt;span class="operator"&gt;++;
			}&lt;/span&gt;&lt;span class="flow"&gt;else&lt;/span&gt;&lt;span class="operator"&gt;{&lt;/span&gt;&lt;span class="flow"&gt;

				if&lt;/span&gt;&lt;span class="operator"&gt;(&lt;/span&gt;$curr_state&lt;span class="operator"&gt; ==&lt;/span&gt; $ac_root&lt;span class="operator"&gt;){&lt;/span&gt;
					$c&lt;span class="operator"&gt;++;
				}&lt;/span&gt;
				$curr_state&lt;span class="operator"&gt; =&lt;/span&gt; $&lt;span class="operator"&gt;{&lt;/span&gt;$curr_state&lt;span class="operator"&gt;}{&lt;/span&gt;$FAILED_DELIM&lt;span class="operator"&gt;};
			}&lt;/span&gt;&lt;span class="pre"&gt;

#			print "2:$curr_state \n";
&lt;/span&gt;&lt;span class="flow"&gt;			if&lt;/span&gt;&lt;span class="operator"&gt;(&lt;/span&gt;exists $&lt;span class="operator"&gt;{&lt;/span&gt;$curr_state&lt;span class="operator"&gt;}{&lt;/span&gt;$ANNOT_DELIM&lt;span class="operator"&gt;}){&lt;/span&gt;
				$annot&lt;span class="operator"&gt; =&lt;/span&gt; $&lt;span class="operator"&gt;{&lt;/span&gt;$curr_state&lt;span class="operator"&gt;}{&lt;/span&gt;$ANNOT_DELIM&lt;span class="operator"&gt;};&lt;/span&gt;&lt;span class="pre"&gt;

#				print "$annot \n";
&lt;/span&gt;&lt;span class="operator"&gt;			}
		}
	}
}&lt;/span&gt;&lt;span class="pre"&gt;

#
# Just to see how the tree looks -- for viewing pleasure :)
#
&lt;/span&gt;sub PrintKwordTree&lt;span class="operator"&gt;{&lt;/span&gt;
	my @params&lt;span class="operator"&gt; =&lt;/span&gt; @_&lt;span class="operator"&gt;;&lt;/span&gt;

	my $ac_root&lt;span class="operator"&gt; =&lt;/span&gt; $params&lt;span class="operator"&gt;[&lt;/span&gt;&lt;span class="int"&gt;0&lt;/span&gt;&lt;span class="operator"&gt;];&lt;/span&gt; 
	my $level&lt;span class="operator"&gt; =&lt;/span&gt; $params&lt;span class="operator"&gt;[&lt;/span&gt;&lt;span class="int"&gt;1&lt;/span&gt;&lt;span class="operator"&gt;];&lt;/span&gt;

	my&lt;span class="operator"&gt; (&lt;/span&gt;$k&lt;span class="operator"&gt;,&lt;/span&gt; $aref&lt;span class="operator"&gt;,&lt;/span&gt; $annot&lt;span class="operator"&gt;,&lt;/span&gt; $j&lt;span class="operator"&gt;,&lt;/span&gt; $nref&lt;span class="operator"&gt;,&lt;/span&gt; $fref&lt;span class="operator"&gt;,&lt;/span&gt; $height&lt;span class="operator"&gt;);&lt;/span&gt;

	foreach $k&lt;span class="operator"&gt; (&lt;/span&gt;keys&lt;span class="operator"&gt; %&lt;/span&gt;$ac_root&lt;span class="operator"&gt;){&lt;/span&gt;&lt;span class="flow"&gt;
		if&lt;/span&gt;&lt;span class="operator"&gt;((&lt;/span&gt;$k eq $ANNOT_DELIM&lt;span class="operator"&gt;)&lt;/span&gt;&lt;span class="operator"&gt; 
			or&lt;/span&gt;&lt;span class="operator"&gt; (&lt;/span&gt;$k eq $FAILED_DELIM&lt;span class="operator"&gt;)&lt;/span&gt;&lt;span class="operator"&gt; or&lt;/span&gt;&lt;span class="operator"&gt; (&lt;/span&gt;$k eq $HEIGHT_DELIM&lt;span class="operator"&gt;)){&lt;/span&gt;

			next&lt;span class="operator"&gt;;
		}&lt;/span&gt;&lt;span class="flow"&gt;
		for&lt;/span&gt;&lt;span class="operator"&gt;(&lt;/span&gt;$j&lt;span class="operator"&gt;=&lt;/span&gt;&lt;span class="int"&gt;0&lt;/span&gt;&lt;span class="operator"&gt;;&lt;/span&gt; $j&lt;span class="operator"&gt;&amp;lt;&lt;/span&gt;$level&lt;span class="operator"&gt;;&lt;/span&gt; $j&lt;span class="operator"&gt;++){&lt;/span&gt;

			print&lt;span class="string"&gt; " "&lt;/span&gt;&lt;span class="operator"&gt;;
		}&lt;/span&gt;
		$fref&lt;span class="operator"&gt; =&lt;/span&gt; $&lt;span class="operator"&gt;{&lt;/span&gt;$&lt;span class="operator"&gt;{&lt;/span&gt;$ac_root&lt;span class="operator"&gt;}{&lt;/span&gt;$k&lt;span class="operator"&gt;}}{&lt;/span&gt;$FAILED_DELIM&lt;span class="operator"&gt;};&lt;/span&gt;

		$nref&lt;span class="operator"&gt; =&lt;/span&gt; $&lt;span class="operator"&gt;{&lt;/span&gt;$ac_root&lt;span class="operator"&gt;}{&lt;/span&gt;$k&lt;span class="operator"&gt;};&lt;/span&gt;
		$height&lt;span class="operator"&gt; =&lt;/span&gt; $&lt;span class="operator"&gt;{&lt;/span&gt;$nref&lt;span class="operator"&gt;}{&lt;/span&gt;$HEIGHT_DELIM&lt;span class="operator"&gt;};&lt;/span&gt;

		print&lt;span class="string"&gt; "-$k-&amp;gt; N=$nref F=$fref h=$height\n"&lt;/span&gt;&lt;span class="operator"&gt;;&lt;/span&gt;
		PrintKwordTree&lt;span class="operator"&gt;(&lt;/span&gt;$&lt;span class="operator"&gt;{&lt;/span&gt;$ac_root&lt;span class="operator"&gt;}{&lt;/span&gt;$k&lt;span class="operator"&gt;},&lt;/span&gt; $level&lt;span class="operator"&gt;+&lt;/span&gt;&lt;span class="int"&gt;1&lt;/span&gt;&lt;span class="operator"&gt;);
	}&lt;/span&gt;&lt;span class="flow"&gt;

	

	if&lt;/span&gt;&lt;span class="operator"&gt;(&lt;/span&gt;exists $&lt;span class="operator"&gt;{&lt;/span&gt;$ac_root&lt;span class="operator"&gt;}{&lt;/span&gt;$ANNOT_DELIM&lt;span class="operator"&gt;}){&lt;/span&gt;
		$annot&lt;span class="operator"&gt; =&lt;/span&gt; $&lt;span class="operator"&gt;{&lt;/span&gt;$ac_root&lt;span class="operator"&gt;}{&lt;/span&gt;$ANNOT_DELIM&lt;span class="operator"&gt;};&lt;/span&gt;&lt;span class="flow"&gt;

		for&lt;/span&gt;&lt;span class="operator"&gt;(&lt;/span&gt;$j&lt;span class="operator"&gt;=&lt;/span&gt;&lt;span class="int"&gt;0&lt;/span&gt;&lt;span class="operator"&gt;;&lt;/span&gt; $j&lt;span class="operator"&gt;&amp;lt;&lt;/span&gt;$level&lt;span class="operator"&gt;;&lt;/span&gt; $j&lt;span class="operator"&gt;++){&lt;/span&gt;
			print&lt;span class="string"&gt; " "&lt;/span&gt;&lt;span class="operator"&gt;;
		}&lt;/span&gt;

		print&lt;span class="string"&gt; "; $annot ;\n\n"&lt;/span&gt;&lt;span class="operator"&gt;;&lt;/span&gt;&lt;span class="flow"&gt;
		return&lt;/span&gt;&lt;span class="operator"&gt;;
	}
}&lt;/span&gt;&lt;span class="pre"&gt;
#
# A simple unit-test
#
&lt;/span&gt;sub&lt;span class="keyword"&gt; main&lt;/span&gt;&lt;span class="operator"&gt;{&lt;/span&gt;
	BuildKwordTree&lt;span class="operator"&gt;(\%&lt;/span&gt;AC_TREE&lt;span class="operator"&gt;,&lt;/span&gt; PATTERN_FILE&lt;span class="operator"&gt;);&lt;/span&gt;&lt;span class="pre"&gt;

#	PrintKwordTree(\%AC_TREE, 0);
&lt;/span&gt;	BuildFailureFunction&lt;span class="operator"&gt;(\%&lt;/span&gt;AC_TREE&lt;span class="operator"&gt;);&lt;/span&gt;&lt;span class="pre"&gt;
#	PrintKwordTree(\%AC_TREE, 0);
# Now build the failure function.
&lt;/span&gt;	print&lt;span class="string"&gt; "please enter the words\n"&lt;/span&gt;&lt;span class="operator"&gt;;&lt;/span&gt;&lt;span class="pre"&gt;
#	MatchWordDelimText(\%AC_TREE, STDIN);
&lt;/span&gt;	StressTestMatchWordDelimText&lt;span class="operator"&gt;(\%&lt;/span&gt;AC_TREE&lt;span class="operator"&gt;,&lt;/span&gt; TEXT_FILE&lt;span class="operator"&gt;);&lt;/span&gt;

	print&lt;span class="string"&gt; "\n....THANK YOU......\n"&lt;/span&gt;&lt;span class="operator"&gt;;
}&lt;/span&gt;&lt;span class="keyword"&gt;
main&lt;/span&gt;&lt;span class="operator"&gt;();&lt;/span&gt;&lt;/pre&gt;
&lt;/body&gt;&lt;/html&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-8974902085800857179?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/8974902085800857179/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=8974902085800857179&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/8974902085800857179'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/8974902085800857179'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2010/04/tech-super-fast-tokenizing-of-words.html' title='[TECH] Super-fast tokenizing of sequence word patterns'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-5488379654460016334</id><published>2010-03-11T14:08:00.000-08:00</published><updated>2010-03-11T14:17:26.213-08:00</updated><title type='text'>[PHIL] My best lines in "The zen and art of motor cycle  maintenance"</title><content type='html'>&lt;p&gt;
We often read a lot. On the other hand we also tend to forget most of what we read. However the essence/flavor/curx what ever you might call may still persist. Some time if were asked to recall about something -- say a novel for example. Then some very distinctively marked paragraphs would normally on top of your head. So whenever I think about "The zen and the art of motorcycle maintenance" the following few paragraphs are always on my mind. You can read the full book &lt;a href="http://design.caltech.edu/Misc/pirsig.html"&gt;here&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;b&gt;
&lt;p&gt;
In time...six months; five years, perhaps...a change could easily begin to take place. He would become less and less satisfied with a kind of dumb, day-to-day shopwork. His creative intelligence, stifled by too much theory and too many grades in college, would now become reawakened by the boredom of the shop. Thousands of hours of frustrating mechanical problems would have made him more interested in machine design. He would like to design machinery himself. He’d think he could do a better job. He would try modifying a few engines, meet with success, look for more success, but feel blocked because he didn’t have the theoretical information. He would discover that when before he felt stupid because of his lack of interest in theoretical information, he’d now find a brand of theoretical information which he’d have a lot of respect for, namely, mechanical engineering.
&lt;/p&gt;
&lt;p&gt;
So he would come back to our degreeless and gradeless school, but with a difference. He’d no longer be a grade-motivated person. He’d be a knowledge-motivated person. He would need no external pushing to learn. His push would come from inside. He’d be a free man. He wouldn’t need a lot of discipline to shape him up. In fact, if the instructors assigned him were slacking on the job he would be likely to shape them up by asking rude questions. He’d be there to learn something, would be paying to learn something and they’d better come up with it.
&lt;/p&gt;
&lt;p&gt;
Motivation of this sort, once it catches hold, is a ferocious force, and in the gradeless, degreeless institution where our student would find himself, he wouldn’t stop with rote engineering information. Physics and mathematics were going to come within his sphere of interest because he’d see he needed them. Metallurgy and electrical engineering would come up for attention. And, in the process of intellectual maturing that these abstract studies gave him, he would he likely to branch out into other theoretical areas that weren’t directly related to machines but had become a part of a newer larger goal. This larger goal wouldn’t be the imitation of education in Universities today, glossed over and concealed by grades and degrees that give the appearance of something happening when, in fact, almost nothing is going on. It would be the real thing.
&lt;/p&gt;


&lt;/b&gt;


&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-5488379654460016334?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/5488379654460016334/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=5488379654460016334&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/5488379654460016334'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/5488379654460016334'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2010/03/phil-my-best-lines-in-zen-and-art-of.html' title='[PHIL] My best lines in &quot;The zen and art of motor cycle  maintenance&quot;'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-4495994562433420301</id><published>2010-03-10T23:07:00.000-08:00</published><updated>2010-03-11T11:36:37.995-08:00</updated><title type='text'>[TECH] Tutte matrix and Sufficiency of Perfect Matching.</title><content type='html'>&lt;p&gt;I know that this is a standard results. But a hands on proof is really useful because it makes things more clear. I knew the fact that any permutation could be broken into disjoint cycles. However I did not know how the sign of the permutation changes if we swap the elements with in a disjoint cycle. It turns out that some of the fundamental properties of the signs of the permutation can be used to prove the sufficiency of a perfect matching in graph. A Tutte Matrix is defined as follows.
&lt;/p&gt;
&lt;dd&gt;&lt;img class="tex" alt="A_{ij} = \begin{cases} x_{ij}\;\;\mbox{if}\;(i,j) \in E \mbox{ and } i&amp;lt;j\\
-x_{ji}\;\;\mbox{if}\;(i,j) \in E \mbox{ and } i&amp;gt;j\\
0\;\;\;\;\mbox{otherwise} \end{cases}" src="http://upload.wikimedia.org/math/5/f/1/5f17b26812cce1011abc7d6f5c45801f.png"&gt;&lt;/dd&gt;

&lt;p&gt; Given a Tutte matrix we now prove the sufficiency of perfect matching &lt;/p&gt;

Determinant of Tutte matrix is as follows &lt;!-- MATH
 $det(T) = \Sigma_{\pi \in S_n} (-1)^{sgn(\pi)}\Pi_{i=1}^{n} t_{i,\pi(i)}$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="259" HEIGHT="38" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img1.png"
 ALT="$ det(T) = \Sigma_{\pi \in S_n} (-1)^{sgn(\pi)}\Pi_{i=1}^{n} t_{i,\pi(i)}$"&gt;&lt;/SPAN&gt;.
We know that every permutation can be expressed as disjoint cycles. For example permutation &lt;!-- MATH
 $\{5, 1, 4, 3, 2\}$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="88" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img2.png"
 ALT="$ \{5, 1, 4, 3, 2\}$"&gt;&lt;/SPAN&gt;
can be expressed as two cycles &lt;!-- MATH
 $\{(1\rightarrow 5 \rightarrow 2 \rightarrow 1) , (3 \rightarrow 4 \rightarrow 3) \}$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="231" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img3.png"
 ALT="$ \{(1\rightarrow 5 \rightarrow 2 \rightarrow 1) , (3 \rightarrow 4 \rightarrow 3) \}$"&gt;&lt;/SPAN&gt;. 
Also &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="51" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img4.png"
 ALT="$ sgn(\pi)$"&gt;&lt;/SPAN&gt; is the number of swaps we need do required to convert &lt;!-- MATH
 $\{1, 2, \ldots n\}$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="81" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img5.png"
 ALT="$ \{1, 2, \ldots n\}$"&gt;&lt;/SPAN&gt; to the permutation &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="14" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img6.png"
 ALT="$ \pi$"&gt;&lt;/SPAN&gt;.
We observe the following important properties which help solve the problem.

&lt;UL&gt;
&lt;LI&gt;&lt;I CLASS="sans"&gt;PROPERTY-1&lt;/I&gt; If &lt;!-- MATH
 $c_i = (t_1\rightarrow t_2 \rightarrow t_3 \ldots t_n\rightarrow t_1)$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="214" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img7.png"
 ALT="$ c_i = (t_1\rightarrow t_2 \rightarrow t_3 \ldots t_n\rightarrow t_1)$"&gt;&lt;/SPAN&gt; is a cycle 
in &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="14" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img6.png"
 ALT="$ \pi$"&gt;&lt;/SPAN&gt; then if we replace &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="16" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img8.png"
 ALT="$ c_i$"&gt;&lt;/SPAN&gt; with &lt;EM&gt;reverse cycle&lt;/EM&gt; &lt;!-- MATH
 $c'_i = (t_n\rightarrow t_1\rightarrow t_2 \rightarrow \ldots t_n)$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="200" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img9.png"
 ALT="$ c'_i = (t_n\rightarrow t_1\rightarrow t_2 \rightarrow \ldots t_n)$"&gt;&lt;/SPAN&gt; then &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="51" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img4.png"
 ALT="$ sgn(\pi)$"&gt;&lt;/SPAN&gt; remains
the same - because we did not change the number of swaps required but just changed the order of swaps. For instance,
let &lt;!-- MATH
 $\pi=\{5, 1, 4, 3, 2\}$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="119" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img10.png"
 ALT="$ \pi=\{5, 1, 4, 3, 2\}$"&gt;&lt;/SPAN&gt; then cycle &lt;!-- MATH
 $c_1 = \{(1\rightarrow 5 \rightarrow 2 \rightarrow 1)\}$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="174" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img11.png"
 ALT="$ c_1 = \{(1\rightarrow 5 \rightarrow 2 \rightarrow 1)\}$"&gt;&lt;/SPAN&gt; now we replace
it with &lt;!-- MATH
 $c'_1 =\{2\rightarrow 5 \rightarrow 1 \rightarrow 2\}$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="161" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img12.png"
 ALT="$ c'_1 =\{2\rightarrow 5 \rightarrow 1 \rightarrow 2\}$"&gt;&lt;/SPAN&gt;. This results in &lt;!-- MATH
 $\pi'=\{2, 5, 4, 3, 1\}$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="123" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img13.png"
 ALT="$ \pi'=\{2, 5, 4, 3, 1\}$"&gt;&lt;/SPAN&gt;.
&lt;/LI&gt;
&lt;LI&gt;&lt;I CLASS="sans"&gt;PROPERTY-2&lt;/I&gt; Let &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="16" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img8.png"
 ALT="$ c_i$"&gt;&lt;/SPAN&gt; is a cycle of odd length in &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="14" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img6.png"
 ALT="$ \pi$"&gt;&lt;/SPAN&gt; and let &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="18" HEIGHT="15" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img14.png"
 ALT="$ \pi'$"&gt;&lt;/SPAN&gt; be the permutation
by replacing &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="16" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img8.png"
 ALT="$ c_i$"&gt;&lt;/SPAN&gt; with its &lt;EM&gt;reverse cycle&lt;/EM&gt; &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="16" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img15.png"
 ALT="$ c'_i$"&gt;&lt;/SPAN&gt;. Then the corresponding terms in the determinant
for &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="16" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img8.png"
 ALT="$ c_i$"&gt;&lt;/SPAN&gt; and &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="16" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img15.png"
 ALT="$ c'_i$"&gt;&lt;/SPAN&gt; are &lt;!-- MATH
 $\Pi_{\pi(i)\in c_i} t_{i,\pi(i)}$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="97" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img16.png"
 ALT="$ \Pi_{\pi(i)\in c_i} t_{i,\pi(i)}$"&gt;&lt;/SPAN&gt; and &lt;!-- MATH
 $\Pi_{\pi(i)\in c_i} t_{\pi(i),i}$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="97" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img17.png"
 ALT="$ \Pi_{\pi(i)\in c_i} t_{\pi(i),i}$"&gt;&lt;/SPAN&gt;.
For example in the previous example &lt;!-- MATH
 $c_1 = \{(1\rightarrow 5 \rightarrow 2 \rightarrow 1)\}$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="174" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img11.png"
 ALT="$ c_1 = \{(1\rightarrow 5 \rightarrow 2 \rightarrow 1)\}$"&gt;&lt;/SPAN&gt; so the
corresponding term in the determinant for &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="18" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img18.png"
 ALT="$ c_1$"&gt;&lt;/SPAN&gt; is &lt;!-- MATH
 $t_{1,5}t_{5,2}t_{2,1}$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="73" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img19.png"
 ALT="$ t_{1,5}t_{5,2}t_{2,1}$"&gt;&lt;/SPAN&gt;. On the other hand
the reverse cycle &lt;!-- MATH
 $c'_1 \{2 \rightarrow 5 \rightarrow 1 \rightarrow 2\}$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="140" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img20.png"
 ALT="$ c'_1 \{2 \rightarrow 5 \rightarrow 1 \rightarrow 2\}$"&gt;&lt;/SPAN&gt; has the following term
&lt;!-- MATH
 $t_{2,5}t_{5,1}t_{1,2}$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="73" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img21.png"
 ALT="$ t_{2,5}t_{5,1}t_{1,2}$"&gt;&lt;/SPAN&gt;in the determinant.
&lt;/LI&gt;
&lt;LI&gt;&lt;I CLASS="sans"&gt;PROPERTY-3&lt;/I&gt; If all the cycles in the permutation &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="14" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img6.png"
 ALT="$ \pi$"&gt;&lt;/SPAN&gt; are even and corresponding term
in the determinant (i.e. &lt;!-- MATH
 $\Pi_{i=1}^{n} t_{i,\pi(i)}$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="76" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img22.png"
 ALT="$ \Pi_{i=1}^{n} t_{i,\pi(i)}$"&gt;&lt;/SPAN&gt;) is &lt;EM&gt;non-zero&lt;/EM&gt; then its the set &lt;!-- MATH
 $\{(1,\pi(1)), (2,\pi(2))\ldots
(n,\pi(n))\}$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="226" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img23.png"
 ALT="$ \{(1,\pi(1)), (2,\pi(2))\ldots
(n,\pi(n))\}$"&gt;&lt;/SPAN&gt; is a valid &lt;EM&gt;perfect match&lt;/EM&gt; in the graph. This is because by the definition of Tutte matrix
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="29" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img24.png"
 ALT="$ t_{u,v}$"&gt;&lt;/SPAN&gt; represents an edge in the graph and the permutation &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="14" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img6.png"
 ALT="$ \pi$"&gt;&lt;/SPAN&gt; is giving a subset of &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="14" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img25.png"
 ALT="$ n$"&gt;&lt;/SPAN&gt; edges since
the product is non-zero, on the other than this sub-set of edges is a match.
&lt;/LI&gt;
&lt;/UL&gt;
&lt;H3&gt;&lt;A NAME="SECTION00011000000000000000"&gt;
 "IF &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="17" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img26.png"
 ALT="$ G$"&gt;&lt;/SPAN&gt; has a perfect match THEN &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="49" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img27.png"
 ALT="$ det(T)$"&gt;&lt;/SPAN&gt; has at least one non-zero term"&lt;/A&gt;
&lt;/H3&gt;
Let &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="21" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img28.png"
 ALT="$ M$"&gt;&lt;/SPAN&gt; be the perfect match in &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="17" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img26.png"
 ALT="$ G$"&gt;&lt;/SPAN&gt; then we construct a permutation &lt;!-- MATH
 $\pi(u)=v, \pi(v)=u$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="132" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img29.png"
 ALT="$ \pi(u)=v, \pi(v)=u$"&gt;&lt;/SPAN&gt; where &lt;!-- MATH
 $(u,v)\in M$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="78" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img30.png"
 ALT="$ (u,v)\in M$"&gt;&lt;/SPAN&gt;, this
permutation on the other hand has even cycles - because we created a cycle for every pair. Now we apply
&lt;I CLASS="sans"&gt;PROPERTY-3&lt;/I&gt; and the term corresponding to &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="14" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img6.png"
 ALT="$ \pi$"&gt;&lt;/SPAN&gt; in &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="49" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img27.png"
 ALT="$ det(T)$"&gt;&lt;/SPAN&gt; is non-zero. 

&lt;H3&gt;&lt;A NAME="SECTION00012000000000000000"&gt;
IF &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="79" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img31.png"
 ALT="$ det(T)=0$"&gt;&lt;/SPAN&gt; THEN &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="17" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img26.png"
 ALT="$ G$"&gt;&lt;/SPAN&gt; has no perfect matching&lt;/A&gt;
&lt;/H3&gt;
Now consider the case when &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="17" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img26.png"
 ALT="$ G$"&gt;&lt;/SPAN&gt; does not have no perfect matching. Then by &lt;I CLASS="sans"&gt;PROPERTY-3&lt;/I&gt; all the terms
corresponding permutations with &lt;EM&gt;even&lt;/EM&gt; cycles must be &lt;EM&gt;zero&lt;/EM&gt; - otherwise our assumption leads
to contradiction. Now consider the permutations with at least one &lt;EM&gt;odd&lt;/EM&gt; cycle, let &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="14" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img6.png"
 ALT="$ \pi$"&gt;&lt;/SPAN&gt;
be that permutation and &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="16" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img8.png"
 ALT="$ c_i$"&gt;&lt;/SPAN&gt; be the odd cycle. Now we replace &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="16" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img8.png"
 ALT="$ c_i$"&gt;&lt;/SPAN&gt; with its reverse cycle &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="16" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img15.png"
 ALT="$ c'_i$"&gt;&lt;/SPAN&gt; and
create the permutation &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="18" HEIGHT="15" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img14.png"
 ALT="$ \pi'$"&gt;&lt;/SPAN&gt;. By &lt;I CLASS="sans"&gt;PROPERTY-1&lt;/I&gt; &lt;!-- MATH
 $sgn(\pi) = sgn(\pi')$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="124" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img32.png"
 ALT="$ sgn(\pi) = sgn(\pi')$"&gt;&lt;/SPAN&gt;. Now we exploit the &lt;EM&gt;skew-symmetry&lt;/EM&gt;
of the Tutte matrix. By &lt;I CLASS="sans"&gt;PROPERTY-2&lt;/I&gt; the terms corresponding to &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="14" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img6.png"
 ALT="$ \pi$"&gt;&lt;/SPAN&gt;, &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="18" HEIGHT="15" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img14.png"
 ALT="$ \pi'$"&gt;&lt;/SPAN&gt; in the determinant are
as follows. &lt;!-- MATH
 $\Pi_{\pi(k)\in c_i} t_{k,\pi(k)}$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="104" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img33.png"
 ALT="$ \Pi_{\pi(k)\in c_i} t_{k,\pi(k)}$"&gt;&lt;/SPAN&gt;, &lt;!-- MATH
 $\Pi_{\pi(k)\in c_i} t_{\pi(k),k}$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="104" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img34.png"
 ALT="$ \Pi_{\pi(k)\in c_i} t_{\pi(k),k}$"&gt;&lt;/SPAN&gt;. But by &lt;EM&gt;skew-symmetry&lt;/EM&gt;
&lt;!-- MATH
 $t_{\pi(k),k} = - t_{k,\pi(k)}$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="122" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img35.png"
 ALT="$ t_{\pi(k),k} = - t_{k,\pi(k)}$"&gt;&lt;/SPAN&gt;, on the other hand since the cycle length is odd this gives that the actual terms
corresponding to &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="14" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img6.png"
 ALT="$ \pi$"&gt;&lt;/SPAN&gt; and &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="18" HEIGHT="15" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img14.png"
 ALT="$ \pi'$"&gt;&lt;/SPAN&gt; are &lt;!-- MATH
 $(-1)^{sgn(\pi)}\Pi_{i=1}^{n}t_{i,\pi(i)}$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="148" HEIGHT="38" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img36.png"
 ALT="$ (-1)^{sgn(\pi)}\Pi_{i=1}^{n}t_{i,\pi(i)}$"&gt;&lt;/SPAN&gt; and &lt;!-- MATH
 $-(-1)^{sgn(\pi')}\Pi_{i=1}^{n}t_{i,\pi(i)}$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="164" HEIGHT="38" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img37.png"
 ALT="$ -(-1)^{sgn(\pi')}\Pi_{i=1}^{n}t_{i,\pi(i)}$"&gt;&lt;/SPAN&gt;. This means all the terms corresponding to permutations with at least one odd cycle can be grouped and pairs
such as &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="14" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img6.png"
 ALT="$ \pi$"&gt;&lt;/SPAN&gt; and &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="18" HEIGHT="15" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img14.png"
 ALT="$ \pi'$"&gt;&lt;/SPAN&gt; be cancelled. So the only contribution for the &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="49" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img27.png"
 ALT="$ det(T)$"&gt;&lt;/SPAN&gt; comes from permutations will &lt;EM&gt;all&lt;/EM&gt; even cycles - in this
case we have none, so &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="79" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/MATCHING1/img31.png"
 ALT="$ det(T)=0$"&gt;&lt;/SPAN&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-4495994562433420301?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/4495994562433420301/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=4495994562433420301&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/4495994562433420301'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/4495994562433420301'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2010/03/tech-tutte-matrix-and-sufficiency-of.html' title='[TECH] Tutte matrix and Sufficiency of Perfect Matching.'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-634980229881488917</id><published>2010-03-09T15:31:00.000-08:00</published><updated>2010-03-09T15:47:44.613-08:00</updated><title type='text'>[LIFE] Keeping the PACE of productivity is very hard.</title><content type='html'>This is the first of the posts I'll start writing some thing different from Technology. Spring break started last Friday (03/05/2010). I'm back to the out-of-core assembly project. Well I had this idea of out-of-core de Bruijn graph construction for a long time and in fact we did demonstrate the efficiency in parallel context. However the main focus has been to format the bi-directed de Bruijn graph in the format required by &lt;a href="http://www.ebi.ac.uk/~zerbino/velvet/"&gt;Velvet&lt;/a&gt;. I started of this quest some time mid October and finally I had a complete algorithm which generates the 'Graph' file in Velvet format. I was very happy last night when I got that but soon realized that there is a lot of difference in the number of CONTIGS. Went home with full of despair that I'm totally stupid. Today I came back and started it again. Productivity is something I strive for. KARMA is something I really believe in. However it seems to me that keeping up with the PACE of productivity is something very hard, the harder you try to focus the harder it might become. I strongly feel that continuous non-stop productivity is only possible when it becomes a HABIT rather than MOTIVATION. It might start off initially as MOTIVATION, but cultivating it as a HABIT is something on the lines of KARMA YOGA. Finally a true KARMA YOGI seems to be a person for whom continuous productivity is a HABIT rather than anything else.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-634980229881488917?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/634980229881488917/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=634980229881488917&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/634980229881488917'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/634980229881488917'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2010/03/life-keeping-pace-of-productivity-is.html' title='[LIFE] Keeping the PACE of productivity is very hard.'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-624124135277284730</id><published>2010-02-01T19:09:00.000-08:00</published><updated>2010-02-01T19:23:35.483-08:00</updated><title type='text'>[TECH] An efficient External sorting API</title><content type='html'>&lt;p&gt;
Sorting is one of the most fundamental operation on data. Very efficient algorithms exists to perform this operation. Most of the programming languages are shipped with some sorting API with them. Most of them are in-memory sorting algorithms. However I find all these APIs are so bloated which are unfortunately by produces of abusing and overusing the object oriented concepts. On the other hand the bloated code may run fine as long as the input size is bounded by some constant -- which is most of the case for many applications. Any way I guess I'm getting into a little off-topic but if you are interested see the flames between C++ and C hackers on the Linux kernel mailing list &lt;a href="http://kerneltrap.org/node/2067"&gt;here&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;
On the other hand most of these programming APIs lack a solid External sorting algorithms. External sorting is * THE MOST * fundamental operation especially when you want to build algorithm on monster and massive datasets.  You can try my new -- well old but wrapped in a new API, External sort please get it  &lt;a href="http://bazaar.launchpad.net/~vamsi-krishnak/%2Bjunk/BuildVelvetGraph/annotate/head%3A/ExternalSort.c"&gt; here &lt;/a&gt;. I'll try to post some examples how to use if when I get more time.
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-624124135277284730?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/624124135277284730/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=624124135277284730&amp;isPopup=true' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/624124135277284730'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/624124135277284730'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2010/02/tech-efficient-external-sorting-api.html' title='[TECH] An efficient External sorting API'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-7443438098051066947</id><published>2010-01-30T13:12:00.000-08:00</published><updated>2010-02-01T13:01:15.204-08:00</updated><title type='text'>Rounding An Integer To The Next Maximal Mutliple Of A Given Radix Power</title><content type='html'>Let &lt;!-- MATH
 $(\ldots d_3d_2d_1)_b$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="90" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img1.png"
 ALT="$ (\ldots d_3d_2d_1)_b$"&gt;&lt;/SPAN&gt; be the modulo-&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="11" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img2.png"
 ALT="$ b$"&gt;&lt;/SPAN&gt; representation of an integer &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="16" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img3.png"
 ALT="$ A$"&gt;&lt;/SPAN&gt;, where each &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="18" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img4.png"
 ALT="$ d_i$"&gt;&lt;/SPAN&gt;
is a symbol/digit corresponding to values &lt;!-- MATH
 $\{0,1,2\ldots b-1\}$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="116" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img5.png"
 ALT="$ \{0,1,2\ldots b-1\}$"&gt;&lt;/SPAN&gt;. Often we are encountered with 
problems where we need to find smallest integer &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="54" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img6.png"
 ALT="$ A' \geq A$"&gt;&lt;/SPAN&gt; such that &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="39" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img7.png"
 ALT="$ A'\vert b^y$"&gt;&lt;/SPAN&gt; (i.e. &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="19" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img8.png"
 ALT="$ b^y$"&gt;&lt;/SPAN&gt; divides &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="21" HEIGHT="15" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img9.png"
 ALT="$ A'$"&gt;&lt;/SPAN&gt;
without any reminder), where &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="51" HEIGHT="35" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img10.png"
 ALT="$ y\in I^+$"&gt;&lt;/SPAN&gt;. Some of the very common applications include rounding the number
of bits required to represent a data structure to the nearest byte (i.e. power of &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="20" HEIGHT="17" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img11.png"
 ALT="$ 2^y$"&gt;&lt;/SPAN&gt;).  
Before we see how to address this problem its worth while to understand the following interesting property of 
modulo representation. Given a modulo-&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="11" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img2.png"
 ALT="$ b$"&gt;&lt;/SPAN&gt; representation of &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="16" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img3.png"
 ALT="$ A$"&gt;&lt;/SPAN&gt; we can get corresponding modulo-&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="19" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img8.png"
 ALT="$ b^y$"&gt;&lt;/SPAN&gt; 
representation of &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="16" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img3.png"
 ALT="$ A$"&gt;&lt;/SPAN&gt; by replacing every group of &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="13" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img12.png"
 ALT="$ y$"&gt;&lt;/SPAN&gt; digits (in modulo-&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="11" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img2.png"
 ALT="$ b$"&gt;&lt;/SPAN&gt; representation), by the 
corresponding digit (i.e. &lt;!-- MATH
 $d_{i_y}\times b^{y-1} + d_{i_{y-1}}\times b^{y-2} \ldots d_{i_1}$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="223" HEIGHT="34" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img13.png"
 ALT="$ d_{i_y}\times b^{y-1} + d_{i_{y-1}}\times b^{y-2} \ldots d_{i_1}$"&gt;&lt;/SPAN&gt;) in modulo-&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="19" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img8.png"
 ALT="$ b^y$"&gt;&lt;/SPAN&gt;. 
For instance if we would like to convert an integer &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="16" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img3.png"
 ALT="$ A$"&gt;&lt;/SPAN&gt; in binary (i.e. &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="40" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img14.png"
 ALT="$ b=2$"&gt;&lt;/SPAN&gt;) representation to hexa-decimal 
representation (&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="55" HEIGHT="16" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img15.png"
 ALT="$ b^y = 2^4$"&gt;&lt;/SPAN&gt;). We start from left to right and replace every &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="24" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img16.png"
 ALT="$ 4-$"&gt;&lt;/SPAN&gt;bits with the corresponding
digit in hexa-decimal system. For example if we see &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="36" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img17.png"
 ALT="$ 1101$"&gt;&lt;/SPAN&gt; we will replace it with digit &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="18" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img18.png"
 ALT="$ D$"&gt;&lt;/SPAN&gt;, &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="36" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img19.png"
 ALT="$ 1110$"&gt;&lt;/SPAN&gt; by 
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="17" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img20.png"
 ALT="$ E$"&gt;&lt;/SPAN&gt; and so on. So the hexa-decimal system is providing us with a one-one function 
&lt;!-- MATH
 $H: \{0,1\}^4 \rightarrow \{0,1,2\ldots A,B,C,D,E,F\}$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="291" HEIGHT="34" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img21.png"
 ALT="$ H: \{0,1\}^4 \rightarrow \{0,1,2\ldots A,B,C,D,E,F\}$"&gt;&lt;/SPAN&gt; for every &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="24" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img16.png"
 ALT="$ 4-$"&gt;&lt;/SPAN&gt;bit string, in fact we can use any
one-one function here when we move for modulo &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="12" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img22.png"
 ALT="$ 2$"&gt;&lt;/SPAN&gt; representation to modulo &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="19" HEIGHT="16" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img23.png"
 ALT="$ 2^4$"&gt;&lt;/SPAN&gt;. However the one-one
function &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="19" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img24.png"
 ALT="$ H$"&gt;&lt;/SPAN&gt; has become a standard for module &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="19" HEIGHT="16" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img23.png"
 ALT="$ 2^4$"&gt;&lt;/SPAN&gt; system.

&lt;P&gt;
So coming back to our original problem given the modulo-&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="11" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img2.png"
 ALT="$ b$"&gt;&lt;/SPAN&gt; representation &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="16" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img3.png"
 ALT="$ A$"&gt;&lt;/SPAN&gt;, we would
like to round &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="16" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img3.png"
 ALT="$ A$"&gt;&lt;/SPAN&gt; to &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="21" HEIGHT="15" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img9.png"
 ALT="$ A'$"&gt;&lt;/SPAN&gt; , where &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="21" HEIGHT="15" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img9.png"
 ALT="$ A'$"&gt;&lt;/SPAN&gt; is the smallest multiple of &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="19" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img8.png"
 ALT="$ b^y$"&gt;&lt;/SPAN&gt; such that &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="54" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img6.png"
 ALT="$ A' \geq A$"&gt;&lt;/SPAN&gt;.
To accomplish this task we need to examine the first (from right) &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="13" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img12.png"
 ALT="$ y$"&gt;&lt;/SPAN&gt; digits in the modulo-&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="11" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img2.png"
 ALT="$ b$"&gt;&lt;/SPAN&gt;
representation of &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="16" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img3.png"
 ALT="$ A$"&gt;&lt;/SPAN&gt;. In fact the value of in those &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="13" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img12.png"
 ALT="$ y$"&gt;&lt;/SPAN&gt; bits is the reminder we get when we
divide &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="16" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img3.png"
 ALT="$ A$"&gt;&lt;/SPAN&gt; by &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="19" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img8.png"
 ALT="$ b^y$"&gt;&lt;/SPAN&gt;, so if &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="17" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img25.png"
 ALT="$ V$"&gt;&lt;/SPAN&gt; is the value in those &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="13" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img12.png"
 ALT="$ y$"&gt;&lt;/SPAN&gt; bits then &lt;!-- MATH
 $A' = A + (b^y-V)$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="132" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img26.png"
 ALT="$ A' = A + (b^y-V)$"&gt;&lt;/SPAN&gt;. When 
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="40" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img14.png"
 ALT="$ b=2$"&gt;&lt;/SPAN&gt; we can elegantly use the bit-wise operators to accomplish this. So if some one gives
an integer &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="19" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img27.png"
 ALT="$ X$"&gt;&lt;/SPAN&gt; and ask to find a smallest &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="59" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img28.png"
 ALT="$ X'\geq X$"&gt;&lt;/SPAN&gt; which is a multiple of &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="20" HEIGHT="17" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img11.png"
 ALT="$ 2^y$"&gt;&lt;/SPAN&gt; then we
use the following C-statement to accomplish this &lt;B&gt;&lt;!-- MATH
 $X += ((1\ll y)-(x\&amp;((1\ll y)-1)))\&amp;((1\ll y)-1)$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="370" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img29.png"
 ALT="$ X += ((1\ll y)-(x\&amp;amp;((1\ll y)-1)))\&amp;amp;((1\ll y)-1)$"&gt;&lt;/SPAN&gt;&lt;/B&gt;. 
Where &lt;B&gt;&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="40" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/ROUND-2010/img30.png"
 ALT="$ \&amp;amp;,\ll $"&gt;&lt;/SPAN&gt;&lt;/B&gt; are the standard bit-wise operators in C.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-7443438098051066947?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/7443438098051066947/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=7443438098051066947&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/7443438098051066947'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/7443438098051066947'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2010/01/rounding-integer-to-next-maximal.html' title='Rounding An Integer To The Next Maximal Mutliple Of A Given Radix Power'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-7964997070919967744</id><published>2009-12-24T17:53:00.000-08:00</published><updated>2009-12-24T18:02:07.039-08:00</updated><title type='text'>[TECH] An interesting problem on the mailing list [gdb@gnu.org]</title><content type='html'>Some one asked the following question of GDB mailing list.
&lt;pre&gt;
Hi, 

  I was wondering how come the call to "call cos(.2)" returns the wrong
answer in:

#include "math.h"
double    (*fcn)(double);
main() 
{
  double t;
  fcn = cos;
  t=cos(.2);
  t=cos(-.2);
}

(gdb) call cos(.2)
$16 = 104
(gdb) call fcn(.2)
$17 = 0.98006657784124163

Thanks,
-- 
View this message in context: &lt;a href="http://old.nabble.com/Why-%22call-cos%28.2%29%22-returns-garbage--tp26909516p26909516.html"&gt; http://old.nabble.com/Why-%22call-cos%28.2%29%22-returns-garbage--tp26909516p26909516.html &lt;/a&gt;
Sent from the Gnu - gdb - General mailing list archive at Nabble.com.
&lt;/pre&gt;

Here is my analysis.

&lt;pre&gt;
Hello,

Looks like 'gdb' is missing debug information about the function 'cos' , 
and the debugger implicitly assumes all the functions return an 'int' ,
 if the function is not compiled in debug mode.

I derive my explanation from the following test case.

1. Create a function 'double test_cos(double)' and compile it in optimized mode with -O3 using gcc
 "$gcc -c -O3 test1.c"

2. Complie the file containing the 'main' function in debug mode
"$gcc -g test.c test1.o -lm"

============[gdb a.out]====================

(gdb) list 0
1       #include "math.h"
2       #include "test1.h"
3       double    (*fcn)(double);
4       main()
5       {
6                double t;
7                 fcn = cos;
8                  t=cos(.2);
9                   t=cos(-.2);
10                      test_cos(.2);
(gdb) call fcn(0.2)
$4 = 0.98006657784124163
(gdb) call cos(0.2)
$5 = -1073792992
(gdb) call test_cos(0.2)
$6 = -1073792992
=====================================

============[test1.h]=================
#ifndef _test_1_h
#define _test_1_h
double test_cos(double);
#endif
====================================

============[test1.c]==================
#include "math.h"
#include "test1.h"
double test_cos(double a){
        return cos(a);
}
====================================

============[test.c]==================
#include "math.h"
#include "test1.h"

double    (*fcn)(double);
main()
{
         double t;
          fcn = cos;
           t=cos(.2);
            t=cos(-.2);
                test_cos(.2);
}
===================================

May be the developers of gdb can you more details.

also
=======================================
(gdb) call cos
$6 = {text variable, no debug info} 0xc325d0 {cos}
=======================================


&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-7964997070919967744?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/7964997070919967744/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=7964997070919967744&amp;isPopup=true' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/7964997070919967744'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/7964997070919967744'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2009/12/tech-interesting-problem-on-mailing.html' title='[TECH] An interesting problem on the mailing list [gdb@gnu.org]'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-7416607222787496691</id><published>2009-12-23T19:33:00.000-08:00</published><updated>2009-12-23T19:49:39.649-08:00</updated><title type='text'>[TECH] Manipulating DNA sequences with bits</title><content type='html'>The alphabet of DNA sequences consists of 4 alphabets {A,T,G,C} and they exists in compliments -- A-T, G-C. Often in sequence assembly algorithms we need to squeeze these into bits for saving space since we have too many of them. For example a typical input to a sequence assembler consists of at least 10 million reads (string of fixed length, say 21). In my last post I briefly described the Sequence Assembly (SA) problem. As I pointed one of the basic operations on these reads would be to obtain a reverse compliment of a given read. For example our read is ATTACCAG , then its reverse compliment would be CTGGTAAT -- reverse the original sequence replace every symbol by its compliment (A-T, G-C). The following routines may be useful when we squeeze these symbols into bits using only 2bits per symbol. While using the bit-wise operators I realized that == operator has more
precedence than &amp; (bit-wise or). So if you a&amp;b==b then that will always be true, so we need to be more careful use (a&amp;b)==b.

&lt;pre&gt;&lt;span style=' color: Blue;'&gt;#define&lt;/span&gt; MASK_A &lt;span style=' color: Maroon;'&gt;3&lt;/span&gt;
&lt;span style=' color: Blue;'&gt;#define&lt;/span&gt; MASK_T &lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;
&lt;span style=' color: Blue;'&gt;#define&lt;/span&gt; MASK_G &lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;
&lt;span style=' color: Blue;'&gt;#define&lt;/span&gt; MASK_C &lt;span style=' color: Maroon;'&gt;2&lt;/span&gt;
&lt;span style=' color: Green;'&gt;/*Lets fix the maximum size of the read as 32 base pairs*/&lt;/span&gt;
typedef unsigned &lt;span style=' color: Blue;'&gt;long&lt;/span&gt; &lt;span style=' color: Blue;'&gt;long&lt;/span&gt; kmer_t;


&lt;span style=' color: Green;'&gt;/*Takes a read of length K and returns its bit represenation*/&lt;/span&gt;
kmer_t CreateBKmer(&lt;span style=' color: Blue;'&gt;char&lt;/span&gt; *kmer, unsigned &lt;span style=' color: Blue;'&gt;long&lt;/span&gt; K){
    unsigned &lt;span style=' color: Blue;'&gt;long&lt;/span&gt; i;
    unsigned &lt;span style=' color: Blue;'&gt;char&lt;/span&gt; bitc;
    &lt;span style=' color: Green;'&gt;/*A binary k-mer*/&lt;/span&gt;
    kmer_t bkmer = (kmer_t) &lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;; 
    &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(i=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;; i&amp;lt;K; i++){
        bkmer &amp;lt;&amp;lt;= &lt;span style=' color: Maroon;'&gt;2&lt;/span&gt;; 
        bkmer |= Char2Bit(kmer[i]);
    }
    &lt;span style=' color: Blue;'&gt;return&lt;/span&gt; bkmer;
}

&lt;span style=' color: Green;'&gt;/*Return the reverse compliment of the kmer_a*/&lt;/span&gt;
kmer_t ReverseCompliment(kmer_t a, unsigned &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; K){
    kmer_t rc=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;
    unsigned &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; i=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;
    &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(i=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;; i&amp;lt;K; i++){
        rc &amp;lt;&amp;lt;=&lt;span style=' color: Maroon;'&gt;2&lt;/span&gt;;
        rc |= (&lt;span style=' color: Maroon;'&gt;3&lt;/span&gt;-(a&amp;amp;&lt;span style=' color: Maroon;'&gt;3&lt;/span&gt;));
        a &amp;gt;&amp;gt;=&lt;span style=' color: Maroon;'&gt;2&lt;/span&gt;;
    }
    &lt;span style=' color: Blue;'&gt;return&lt;/span&gt; rc;
}
&lt;span style=' color: Green;'&gt;/*Print the ASCII equivalent of the underlying bits*/&lt;/span&gt;
&lt;span style=' color: Blue;'&gt;void&lt;/span&gt; PrintKmer(kmer_t a, unsigned &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; K, FILE *ptr){
    &lt;span style=' color: Blue;'&gt;char&lt;/span&gt; ntide;
    kmer_t mask_a = MASK_A;
    kmer_t mask_t = MASK_T;
    kmer_t mask_g = MASK_G;
    kmer_t mask_c = MASK_C;

    mask_a &amp;lt;&amp;lt;= &lt;span style=' color: Maroon;'&gt;2&lt;/span&gt;*(K-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;); mask_t &amp;lt;&amp;lt;= &lt;span style=' color: Maroon;'&gt;2&lt;/span&gt;*(K-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;); 
    mask_g &amp;lt;&amp;lt;= &lt;span style=' color: Maroon;'&gt;2&lt;/span&gt;*(K-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;); mask_c &amp;lt;&amp;lt;= &lt;span style=' color: Maroon;'&gt;2&lt;/span&gt;*(K-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;);

    &lt;span style=' color: Blue;'&gt;do&lt;/span&gt;{
        &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;((a&amp;amp;mask_a) == mask_a){
            ntide = &lt;span style=' color: Maroon;'&gt;'A'&lt;/span&gt;;
        }&lt;span style=' color: Blue;'&gt;else&lt;/span&gt; &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;((a&amp;amp;mask_c) == mask_c){
            ntide = &lt;span style=' color: Maroon;'&gt;'C'&lt;/span&gt;;
        }&lt;span style=' color: Blue;'&gt;else&lt;/span&gt; &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;((a&amp;amp;mask_g) == mask_g){
            ntide = &lt;span style=' color: Maroon;'&gt;'G'&lt;/span&gt;;
        }&lt;span style=' color: Blue;'&gt;else&lt;/span&gt;{ &lt;span style=' color: Green;'&gt;/*This should be the last because T=0*/&lt;/span&gt;
            ntide = &lt;span style=' color: Maroon;'&gt;'T'&lt;/span&gt;;
        }
        fprintf(ptr, &lt;span style=' color: Maroon;'&gt;"%c"&lt;/span&gt;, ntide);
        mask_a &amp;gt;&amp;gt;=&lt;span style=' color: Maroon;'&gt;2&lt;/span&gt;; mask_t &amp;gt;&amp;gt;=&lt;span style=' color: Maroon;'&gt;2&lt;/span&gt;;
        mask_g &amp;gt;&amp;gt;=&lt;span style=' color: Maroon;'&gt;2&lt;/span&gt;; mask_c &amp;gt;&amp;gt;=&lt;span style=' color: Maroon;'&gt;2&lt;/span&gt;;
    }&lt;span style=' color: Blue;'&gt;while&lt;/span&gt;(mask_a); &lt;span style=' color: Green;'&gt;/*MASK_A = 3 */&lt;/span&gt;
    fprintf(ptr, &lt;span style=' color: Maroon;'&gt;"\n"&lt;/span&gt;);
}

inline &lt;span style=' color: Blue;'&gt;char&lt;/span&gt; Bit2Char(unsigned &lt;span style=' color: Blue;'&gt;char&lt;/span&gt; a){
    &lt;span style=' color: Blue;'&gt;switch&lt;/span&gt;(a){
        &lt;span style=' color: Blue;'&gt;case&lt;/span&gt; MASK_A:
            &lt;span style=' color: Blue;'&gt;return&lt;/span&gt; &lt;span style=' color: Maroon;'&gt;'A'&lt;/span&gt;;
        &lt;span style=' color: Blue;'&gt;case&lt;/span&gt; MASK_G: 
            &lt;span style=' color: Blue;'&gt;return&lt;/span&gt; &lt;span style=' color: Maroon;'&gt;'G'&lt;/span&gt;; 
        &lt;span style=' color: Blue;'&gt;case&lt;/span&gt; MASK_C:
            &lt;span style=' color: Blue;'&gt;return&lt;/span&gt; &lt;span style=' color: Maroon;'&gt;'C'&lt;/span&gt;;
        &lt;span style=' color: Blue;'&gt;case&lt;/span&gt; MASK_T:
            &lt;span style=' color: Blue;'&gt;return&lt;/span&gt; &lt;span style=' color: Maroon;'&gt;'T'&lt;/span&gt;;
    }
}

inline unsigned &lt;span style=' color: Blue;'&gt;char&lt;/span&gt; Char2Bit(&lt;span style=' color: Blue;'&gt;char&lt;/span&gt; c){
    &lt;span style=' color: Blue;'&gt;switch&lt;/span&gt;(c){
        &lt;span style=' color: Blue;'&gt;case&lt;/span&gt; &lt;span style=' color: Maroon;'&gt;'A'&lt;/span&gt;:
            &lt;span style=' color: Blue;'&gt;return&lt;/span&gt; MASK_A;
        &lt;span style=' color: Blue;'&gt;case&lt;/span&gt; &lt;span style=' color: Maroon;'&gt;'T'&lt;/span&gt;:
            &lt;span style=' color: Blue;'&gt;return&lt;/span&gt; MASK_T; 
        &lt;span style=' color: Blue;'&gt;case&lt;/span&gt; &lt;span style=' color: Maroon;'&gt;'G'&lt;/span&gt;:
            &lt;span style=' color: Blue;'&gt;return&lt;/span&gt; MASK_G;
        &lt;span style=' color: Blue;'&gt;case&lt;/span&gt; &lt;span style=' color: Maroon;'&gt;'C'&lt;/span&gt;:
            &lt;span style=' color: Blue;'&gt;return&lt;/span&gt; MASK_C; 
    }
}&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-7416607222787496691?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/7416607222787496691/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=7416607222787496691&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/7416607222787496691'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/7416607222787496691'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2009/12/tech-manipulating-dna-sequences-with.html' title='[TECH] Manipulating DNA sequences with bits'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-313917094437748445</id><published>2009-12-18T20:53:00.000-08:00</published><updated>2009-12-18T21:08:59.597-08:00</updated><title type='text'>[TECH] Loops in Bi-directed De Bruijn Graphs</title><content type='html'>De Bruijn graphs recently found applications in &lt;em&gt;Sequence Assembly&lt;/em&gt;(&lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img1.png" alt="$ SA$" height="14" width="27" align="BOTTOM" border="0"&gt;&lt;/span&gt;). 
&lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img1.png" alt="$ SA$" height="14" width="27" align="BOTTOM" border="0"&gt;&lt;/span&gt; problem is close to &lt;em&gt;Shortest Common super String&lt;/em&gt;(&lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img2.png" alt="$ SCS$" height="14" width="38" align="BOTTOM" border="0"&gt;&lt;/span&gt;) problem, however 
there are some fundamental differences. Given a set of input strings &lt;!-- MATH
 $S=\{s_1,s_2,s_3\ldots s_n\}$
 --&gt;
&lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img3.png" alt="$ S=\{s_1,s_2,s_3\ldots s_n\}$" height="32" width="150" align="MIDDLE" border="0"&gt;&lt;/span&gt;
strings the &lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img2.png" alt="$ SCS$" height="14" width="38" align="BOTTOM" border="0"&gt;&lt;/span&gt; problem outputs a string &lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img4.png" alt="$ s^*$" height="14" width="19" align="BOTTOM" border="0"&gt;&lt;/span&gt; such that every &lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img5.png" alt="$ s_i$" height="30" width="17" align="MIDDLE" border="0"&gt;&lt;/span&gt; is a sub-string in &lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img4.png" alt="$ s^*$" height="14" width="19" align="BOTTOM" border="0"&gt;&lt;/span&gt;

and &lt;!-- MATH
 $\nexists s': length(s') &lt; length(s^*)$
 --&gt;
&lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img6.png" alt="$ \nexists s': length(s') &amp;lt; length(s^*)$" height="32" width="201" align="MIDDLE" border="0"&gt;&lt;/span&gt;. On the other hand the input to the &lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img1.png" alt="$ SA$" height="14" width="27" align="BOTTOM" border="0"&gt;&lt;/span&gt; problem
is a set &lt;!-- MATH
 $R=\{r_1,r_2,r_3\ldots r_n\}$
 --&gt;
&lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img7.png" alt="$ R=\{r_1,r_2,r_3\ldots r_n\}$" height="32" width="150" align="MIDDLE" border="0"&gt;&lt;/span&gt; of strings, every &lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img8.png" alt="$ r_i$" height="30" width="17" align="MIDDLE" border="0"&gt;&lt;/span&gt; is a randomly chosen 
sub-string of a bigger string &lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img9.png" alt="$ G$" height="14" width="17" align="BOTTOM" border="0"&gt;&lt;/span&gt; - called the &lt;em&gt;genome&lt;/em&gt;. Unfortunately we do not
know what &lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img9.png" alt="$ G$" height="14" width="17" align="BOTTOM" border="0"&gt;&lt;/span&gt; is, so given &lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img10.png" alt="$ R$" height="14" width="16" align="BOTTOM" border="0"&gt;&lt;/span&gt; the &lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img1.png" alt="$ SA$" height="14" width="27" align="BOTTOM" border="0"&gt;&lt;/span&gt; problem asks to find the &lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img9.png" alt="$ G$" height="14" width="17" align="BOTTOM" border="0"&gt;&lt;/span&gt; such that we can
explain every &lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img8.png" alt="$ r_i$" height="30" width="17" align="MIDDLE" border="0"&gt;&lt;/span&gt;. Adding to the complexity of &lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img1.png" alt="$ SA$" height="14" width="27" align="BOTTOM" border="0"&gt;&lt;/span&gt; problem &lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img9.png" alt="$ G$" height="14" width="17" align="BOTTOM" border="0"&gt;&lt;/span&gt; may contain several
repeating regions and the direct appliction of &lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img2.png" alt="$ SCS$" height="14" width="38" align="BOTTOM" border="0"&gt;&lt;/span&gt; to solve &lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img1.png" alt="$ SA$" height="14" width="27" align="BOTTOM" border="0"&gt;&lt;/span&gt; problem would
result in collapsing the repeating regions in &lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img9.png" alt="$ G$" height="14" width="17" align="BOTTOM" border="0"&gt;&lt;/span&gt; - so we cannot directly reduce 
the &lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img1.png" alt="$ SA$" height="14" width="27" align="BOTTOM" border="0"&gt;&lt;/span&gt; problem to &lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img2.png" alt="$ SCS$" height="14" width="38" align="BOTTOM" border="0"&gt;&lt;/span&gt;. Also the string &lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img9.png" alt="$ G$" height="14" width="17" align="BOTTOM" border="0"&gt;&lt;/span&gt; is special string coming from the

&lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img11.png" alt="$ DNA$" height="14" width="44" align="BOTTOM" border="0"&gt;&lt;/span&gt; so its double stranded and each &lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img8.png" alt="$ r_i$" height="30" width="17" align="MIDDLE" border="0"&gt;&lt;/span&gt; may be originating from the forward or
reverse compliments of &lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img9.png" alt="$ G$" height="14" width="17" align="BOTTOM" border="0"&gt;&lt;/span&gt;.

&lt;IMG
 WIDTH="253" HEIGHT="275" ALIGN="RIGHT" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img19.png"
 ALT="\includegraphics[scale=0.5]{loops_debrujin.eps}"&gt; &lt;/IMG&gt;

&lt;p&gt;
A &lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img12.png" alt="$ k-$" height="30" width="25" align="MIDDLE" border="0"&gt;&lt;/span&gt;De Bruijn graph &lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img13.png" alt="$ B^k(R)$" height="35" width="49" align="MIDDLE" border="0"&gt;&lt;/span&gt; on a set of strings &lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img10.png" alt="$ R$" height="14" width="16" align="BOTTOM" border="0"&gt;&lt;/span&gt; is a graph whose vertices
correspond to the unique &lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img12.png" alt="$ k-$" height="30" width="25" align="MIDDLE" border="0"&gt;&lt;/span&gt;mers (a string of length &lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img14.png" alt="$ k$" height="14" width="13" align="BOTTOM" border="0"&gt;&lt;/span&gt;) from all the &lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img15.png" alt="$ r_i \in R$" height="30" width="48" align="MIDDLE" border="0"&gt;&lt;/span&gt; 
and whose edges correspond to a some &lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img16.png" alt="$ k+1-$" height="30" width="53" align="MIDDLE" border="0"&gt;&lt;/span&gt;mer in some &lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img17.png" alt="$ r_j \in R$" height="30" width="50" align="MIDDLE" border="0"&gt;&lt;/span&gt;. Also to consider
the double stranded-ness we also include a reverse compliment of every &lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img12.png" alt="$ k-$" height="30" width="25" align="MIDDLE" border="0"&gt;&lt;/span&gt;mer into
the graph &lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img13.png" alt="$ B^k(R)$" height="35" width="49" align="MIDDLE" border="0"&gt;&lt;/span&gt;. In the following simple example I show how a loop (i.e. both 
the forward and reverse compliments overlapping each other by &lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img18.png" alt="$ k-1$" height="30" width="40" align="MIDDLE" border="0"&gt;&lt;/span&gt;) can originate
into &lt;span class="MATH"&gt;&lt;img src="http://vamsi99.users.sourceforge.net/blg/LOOP-2009/img13.png" alt="$ B^k(R)$" height="35" width="49" align="MIDDLE" border="0"&gt;&lt;/span&gt;. This interesting situation seems to be referred to as &lt;em&gt;hairpin-loop&lt;/em&gt;.


&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-313917094437748445?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/313917094437748445/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=313917094437748445&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/313917094437748445'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/313917094437748445'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2009/12/tech-loops-in-bi-directed-de-bruijn.html' title='[TECH] Loops in Bi-directed De Bruijn Graphs'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-6317348968153805003</id><published>2009-12-12T20:52:00.000-08:00</published><updated>2009-12-12T20:57:31.950-08:00</updated><title type='text'>[TECH] Simplified Proof For The Application Of Freivalds' Technique to Verify Matrix Multiplication</title><content type='html'>We first give a simple and alternative proof for Theorem-&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="24" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/RAND-2009/img19.png"
 ALT="$ 7.2$"&gt;&lt;/SPAN&gt; in&amp;nbsp;[Randomized Algorithms, Motwani R. and Raghavan P., pp 162--163]. Later in Theorem&amp;nbsp;&lt;A HREF="#thm2"&gt;2&lt;/A&gt;
we show that the assumption on the &lt;EM&gt;uniformness&lt;/EM&gt; is not necessary. 
&lt;BR&gt;
&lt;A NAME="thm1"&gt;&lt;/A&gt;&lt;IMG
 WIDTH="557" HEIGHT="54" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/RAND-2009/img20.png"
 ALT="\begin{theorem}
Let $A$,$B$\ and $C$\ be three $n\times n$\ matrices such that $...
...tribution. Then $P[AB\vec{r} = C\vec{r} \vert AB \neq C] \leq 1/2$
\end{theorem}"&gt;
&lt;BR&gt;
&lt;P&gt;&lt;/P&gt;
&lt;DIV&gt;&lt;I&gt;Proof&lt;/I&gt;.

Let &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="19" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/RAND-2009/img22.png"
 ALT="$ X$"&gt;&lt;/SPAN&gt; be a &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="43" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/RAND-2009/img4.png"
 ALT="$ n\times n$"&gt;&lt;/SPAN&gt; matrix and &lt;!-- MATH
 $\vec{x_1}, \vec{x_2}\ldots \vec{x_n}$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="93" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/RAND-2009/img23.png"
 ALT="$ \vec{x_1}, \vec{x_2}\ldots \vec{x_n}$"&gt;&lt;/SPAN&gt; be the column vectors of &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="19" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/RAND-2009/img22.png"
 ALT="$ X$"&gt;&lt;/SPAN&gt;.
Then &lt;!-- MATH
 $X\vec{r} = \sum_{i=1}^{n}r_i\vec{x_1}$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="121" HEIGHT="34" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/RAND-2009/img24.png"
 ALT="$ X\vec{r} = \sum_{i=1}^{n}r_i\vec{x_1}$"&gt;&lt;/SPAN&gt;. This means that multiplying a vector with a matrix is linear
combination of the columns, the coefficient &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="17" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/RAND-2009/img25.png"
 ALT="$ r_i$"&gt;&lt;/SPAN&gt; is the &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="23" HEIGHT="20" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/RAND-2009/img26.png"
 ALT="$ i^{th}$"&gt;&lt;/SPAN&gt; component of &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="13" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/RAND-2009/img27.png"
 ALT="$ \vec{r}$"&gt;&lt;/SPAN&gt;. Since &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="13" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/RAND-2009/img27.png"
 ALT="$ \vec{r}$"&gt;&lt;/SPAN&gt;
is a boolean and &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="17" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/RAND-2009/img25.png"
 ALT="$ r_i$"&gt;&lt;/SPAN&gt; acts as an indicator variable on the selection of column &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="21" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/RAND-2009/img28.png"
 ALT="$ \vec{x_i}$"&gt;&lt;/SPAN&gt;. So if &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="13" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/RAND-2009/img27.png"
 ALT="$ \vec{r}$"&gt;&lt;/SPAN&gt;
is chosen from a uniform distribution &lt;!-- MATH
 $P[r_i=0] = P[r_i=1] = 1/2$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="196" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/RAND-2009/img29.png"
 ALT="$ P[r_i=0] = P[r_i=1] = 1/2$"&gt;&lt;/SPAN&gt;. 

&lt;P&gt;
Now let &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="64" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/RAND-2009/img30.png"
 ALT="$ D=AB$"&gt;&lt;/SPAN&gt; and &lt;!-- MATH
 $\vec{d_1},\vec{d_2}\ldots \vec{d_n}$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="90" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/RAND-2009/img31.png"
 ALT="$ \vec{d_1},\vec{d_2}\ldots \vec{d_n}$"&gt;&lt;/SPAN&gt; be the column vectors of &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="18" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/RAND-2009/img32.png"
 ALT="$ D$"&gt;&lt;/SPAN&gt;, similarly 
let &lt;!-- MATH
 $\vec{c_1},\vec{c_2}\ldots \vec{c_n}$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="86" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/RAND-2009/img33.png"
 ALT="$ \vec{c_1},\vec{c_2}\ldots \vec{c_n}$"&gt;&lt;/SPAN&gt; be the column vectors of &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="17" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/RAND-2009/img3.png"
 ALT="$ C$"&gt;&lt;/SPAN&gt;. Let
&lt;!-- MATH
 $Y =\{\vec{d_j} | \vec{d_j}\neq \vec{c_j}$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="121" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/RAND-2009/img34.png"
 ALT="$ Y =\{\vec{d_j} \vert \vec{d_j}\neq \vec{c_j}$"&gt;&lt;/SPAN&gt;, clearly &lt;!-- MATH
 $|Y| \geq 1$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="55" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/RAND-2009/img35.png"
 ALT="$ \vert Y\vert \geq 1$"&gt;&lt;/SPAN&gt; since &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="51" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/RAND-2009/img36.png"
 ALT="$ C\neq D$"&gt;&lt;/SPAN&gt;. Then
&lt;!-- MATH
 $P[AB\vec{r} = C\vec{r} | AB \neq C] = \displaystyle\Pi_{\vec{d_i}\notin Y}P[r_i] = (1/2)^{n-|Y|} \leq 1/2$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="405" HEIGHT="38" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/RAND-2009/img37.png"
 ALT="$ P[AB\vec{r} = C\vec{r} \vert AB \neq C] = \displaystyle\Pi_{\vec{d_i}\notin Y}P[r_i] = (1/2)^{n-\vert Y\vert} \leq 1/2$"&gt;&lt;/SPAN&gt;
since &lt;!-- MATH
 $1 \leq |Y|\leq n-1$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="113" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/RAND-2009/img38.png"
 ALT="$ 1 \leq \vert Y\vert\leq n-1$"&gt;&lt;/SPAN&gt;.  Intuitively this means we select our random vector &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="13" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/RAND-2009/img27.png"
 ALT="$ \vec{r}$"&gt;&lt;/SPAN&gt; such that
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="46" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/RAND-2009/img39.png"
 ALT="$ r_i=0$"&gt;&lt;/SPAN&gt; for all &lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="50" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/RAND-2009/img40.png"
 ALT="$ d_i \in Y$"&gt;&lt;/SPAN&gt;, such a selection will always ensure &lt;!-- MATH
 $AB\vec{r} = C\vec{r}$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="80" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/RAND-2009/img41.png"
 ALT="$ AB\vec{r} = C\vec{r}$"&gt;&lt;/SPAN&gt; even though
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="63" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/RAND-2009/img42.png"
 ALT="$ AB\neq C$"&gt;&lt;/SPAN&gt;.
 &lt;IMG
 WIDTH="4" HEIGHT="15" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/RAND-2009/img21.png"
 ALT="$ \qedsymbol$"&gt;
&lt;/DIV&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;
&lt;BR&gt;
&lt;A NAME="thm2"&gt;&lt;/A&gt;&lt;IMG
 WIDTH="555" HEIGHT="74" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/RAND-2009/img43.png"
 ALT="\begin{theorem}
Let $A$,$B$\ and $C$\ be three $n \times n$\ matrices. Let $\vec...
...$f(r)$\ is an arbitrary probability density/distribution
function.
\end{theorem}"&gt;
&lt;BR&gt;
&lt;P&gt;&lt;/P&gt;
&lt;DIV&gt;&lt;I&gt;Proof&lt;/I&gt;.

Continuing with the proof of Theorem-&amp;nbsp;&lt;A HREF="#thm1"&gt;1&lt;/A&gt; , &lt;!-- MATH
 $P[AB\vec{r} = C\vec{r}|AB\neq C] = \displaystyle\Pi_{\vec{d_i}\notin Y} P[r=r_i] \leq f(r)$
 --&gt;
&lt;SPAN CLASS="MATH"&gt;&lt;IMG
 WIDTH="345" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/RAND-2009/img44.png"
 ALT="$ P[AB\vec{r} = C\vec{r}\vert AB\neq C] = \displaystyle\Pi_{\vec{d_i}\notin Y} P[r=r_i] \leq f(r)$"&gt;&lt;/SPAN&gt;.
 &lt;IMG
 WIDTH="4" HEIGHT="15" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/RAND-2009/img21.png"
 ALT="$ \qedsymbol$"&gt;
&lt;/DIV&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;
&lt;BR&gt;
&lt;IMG
 WIDTH="555" HEIGHT="34" ALIGN="BOTTOM" BORDER="0"
 SRC="http://vamsi99.users.sourceforge.net/blg/RAND-2009/img45.png"
 ALT="\begin{corollary}
There always exists an $\Theta(n^2)$\ time Monte Carlo algorit...
...creasing error probability, for the
problem to check if $AB=C$.
\end{corollary}"&gt;
&lt;BR&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-6317348968153805003?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/6317348968153805003/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=6317348968153805003&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/6317348968153805003'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/6317348968153805003'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2009/12/tech-awe-first-give-simple-and.html' title='[TECH] Simplified Proof For The Application Of Freivalds&apos; Technique to Verify Matrix Multiplication'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-1258513595832558519</id><published>2009-12-04T22:37:00.000-08:00</published><updated>2009-12-04T22:39:31.332-08:00</updated><title type='text'>[TECH] Parallel sorting of binary keys</title><content type='html'>I have just released the beta of parallel sorting using MPI. Feel free to use it visit the web page 
&lt;a href="http://par-bin-sort.sourceforge.net/usage.html"&gt;http://par-bin-sort.sourceforge.net/usage.html&lt;/a&gt; from more details.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-1258513595832558519?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/1258513595832558519/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=1258513595832558519&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/1258513595832558519'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/1258513595832558519'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2009/12/tech-parallel-sorting-of-binary-keys.html' title='[TECH] Parallel sorting of binary keys'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-5601885333618840854</id><published>2009-11-11T13:48:00.000-08:00</published><updated>2009-11-11T13:59:11.322-08:00</updated><title type='text'>[PHIL] My original quote "The more you learn the more stupid you feel"</title><content type='html'>I was drinking coffee today and met a friend who was asking me how I was doing my research. I inadvertently replied her "The more I learn the more stupid I feel". Then I came back to my office and was proving a theorem that the cardinality of the optimal edge cover |C| is exactly |V|-|M|. After that I recalled the statement I made, and restated it as follows "IF you are more learned THEN more stupid you feel". From this its clear that learning more or wiseness is a subset of feeling stupid. So if you never feel stupid and always feel that you the genius who landed on this earth then its sufficient that your complexity class is far away from the complexity class of wiseness.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-5601885333618840854?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/5601885333618840854/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=5601885333618840854&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/5601885333618840854'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/5601885333618840854'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2009/11/phil-my-original-quote-more-you-learn.html' title='[PHIL] My original quote &quot;The more you learn the more stupid you feel&quot;'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-5912744664017595936</id><published>2009-09-20T13:05:00.000-07:00</published><updated>2009-09-20T13:10:41.086-07:00</updated><title type='text'>[TECH] Border Length Minimization Solver</title><content type='html'>BLM (Border Length Minimization ) is a combinatorial optimization problem which belongs to the same class the QAP (Quadratic Assignment Problem). We now have a new result which indeed proves that BLM problem is NP-hard on any simple connected grid. We are developing a BLM solver which can give good results in practice. I'm now using Launchpad for all the development of this project. The latest commits can be kept track at &lt;a href="https://code.launchpad.net/~vamsi-krishnak/blm-solve/trunk"&gt;https://code.launchpad.net/~vamsi-krishnak/blm-solve/trunk&lt;/a&gt; .&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-5912744664017595936?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/5912744664017595936/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=5912744664017595936&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/5912744664017595936'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/5912744664017595936'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2009/09/tech-border-length-minimization-solver.html' title='[TECH] Border Length Minimization Solver'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-4390177840185241545</id><published>2009-09-01T21:50:00.000-07:00</published><updated>2009-09-01T21:58:20.038-07:00</updated><title type='text'>Algebraic methods for Combinatorial counting.</title><content type='html'>I started reading Knuth's Volume-4 series - you can get it 
here&amp;nbsp;&lt;TT&gt;&lt;A NAME="tex2html1"
  HREF="http://www.cs.utsa.edu/~wagner/knuth/"&gt;http://www.cs.utsa.edu/~wagner/knuth/&lt;/A&gt;&lt;/TT&gt;. The chapter
&lt;EM&gt;Introduction to Combinatorial Searching&lt;/EM&gt; starts off with 
the analysis of some of the fundamental combinatorial objects such
as &lt;EM&gt;Langford pairs&lt;/EM&gt;. I came across an interesting exercise which 
asks to prove a statement on how to count these Langford pairs. I infact
spend some time on this problem and finally the solution seemed extremely
elegant. Before that let me quicky define what a Langford pair is.

&lt;P&gt;
&lt;B&gt;Langford Pair:&lt;/B&gt; Given a multi set &lt;!-- MATH
 $S = \{1,1,2,2,3,3\ldots n,n\}$
 --&gt;
&lt;IMG
 WIDTH="185" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img1.png"
 ALT="$ S = \{1,1,2,2,3,3\ldots n,n\}$"&gt;
 of &lt;IMG
 WIDTH="22" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img2.png"
 ALT="$ 2n$"&gt;

 integers - every integer &lt;!-- MATH
 $1\leq i \leq n$
 --&gt;
&lt;IMG
 WIDTH="70" HEIGHT="29" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img3.png"
 ALT="$ 1\leq i \leq n$"&gt;
 is repeated exactly twice.  A Langford pair &lt;IMG
 WIDTH="9" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img4.png"
 ALT="$ l$"&gt;
 is a permutation &lt;IMG
 WIDTH="14" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img5.png"
 ALT="$ \pi$"&gt;
 of &lt;IMG
 WIDTH="15" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img6.png"
 ALT="$ S$"&gt;
, with a property that there are exactly &lt;IMG
 WIDTH="40" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img7.png"
 ALT="$ i \in S$"&gt;
 elements between &lt;IMG
 WIDTH="10" HEIGHT="17" ALIGN="BOTTOM" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img8.png"
 ALT="$ i$"&gt;

 and its copy, &lt;!-- MATH
 $1\leq i \leq n$
 --&gt;
&lt;IMG
 WIDTH="70" HEIGHT="29" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img3.png"
 ALT="$ 1\leq i \leq n$"&gt;
. (e.g. for &lt;IMG
 WIDTH="43" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img9.png"
 ALT="$ n=3$"&gt;
 &lt;!-- MATH
 $L = \{ 3,1,2,1,3,2 \}$
 --&gt;
&lt;IMG
 WIDTH="135" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img10.png"
 ALT="$ L = \{ 3,1,2,1,3,2 \}$"&gt;
, we can see that &lt;IMG
 WIDTH="12" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img11.png"
 ALT="$ 1$"&gt;
 and its copy has exactly &lt;IMG
 WIDTH="12" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img11.png"
 ALT="$ 1$"&gt;
 element between them. Also observe the property of &lt;IMG
 WIDTH="12" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img12.png"
 ALT="$ 2$"&gt;

 and &lt;IMG
 WIDTH="12" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img13.png"
 ALT="$ 3$"&gt;
) Having defined what a Langford pair is we now ask the question how can we 
count. The exercise I was talking about initially asks to prove the 
following. 

&lt;P&gt;

&lt;UL&gt;
&lt;LI&gt;Let &lt;IMG
 WIDTH="24" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img14.png"
 ALT="$ L_n$"&gt;
 denote all the possible Langford pairs which can be 
formed from set &lt;!-- MATH
 $S=\{1,1,2,2,3,3\ldots n,n\}$
 --&gt;
&lt;IMG
 WIDTH="185" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img1.png"
 ALT="$ S = \{1,1,2,2,3,3\ldots n,n\}$"&gt;
.
&lt;/LI&gt;
&lt;LI&gt;Let &lt;!-- MATH
 $f(x_1,x_2,\ldots ,x_{2n}) = \displaystyle\Pi_{k=1}^{n}(x_kx_{n+k}
\displaystyle\sum_{j=1}^{2n-k-1}x_jx_{j+k+1})$
 --&gt;

&lt;IMG
 WIDTH="364" HEIGHT="68" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img15.png"
 ALT="$ f(x_1,x_2,\ldots ,x_{2n}) = \displaystyle\Pi_{k=1}^{n}(x_kx_{n+k}
\displaystyle\sum_{j=1}^{2n-k-1}x_jx_{j+k+1})$"&gt;

&lt;/LI&gt;
&lt;LI&gt;Let &lt;!-- MATH
 $Y=\{-1,+1\}^{2n}$
 --&gt;
&lt;IMG
 WIDTH="117" HEIGHT="34" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img16.png"
 ALT="$ Y=\{-1,+1\}^{2n}$"&gt;

&lt;/LI&gt;
&lt;LI&gt;Show that &lt;!-- MATH
 $\displaystyle\sum_{y \in Y}f(x_1,x_2,\ldots x_{2n}) = 2^{2n+1}L_n$
 --&gt;
&lt;IMG
 WIDTH="226" HEIGHT="55" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img17.png"
 ALT="$ \displaystyle\sum_{y \in Y}f(x_1,x_2,\ldots x_{2n}) = 2^{2n+1}L_n$"&gt;


&lt;P&gt;
&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;
Looking at the problem first, I was a little unclear what is the intuition 
behind defining such a function (i.e. &lt;!-- MATH
 $f(x_1,\ldots x_{2n})$
 --&gt;
&lt;IMG
 WIDTH="95" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img18.png"
 ALT="$ f(x_1,\ldots x_{2n})$"&gt;
). After careful
thought and analysis I understood that the function &lt;!-- MATH
 $f(x_1,\ldots x_{2n})$
 --&gt;
&lt;IMG
 WIDTH="95" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img18.png"
 ALT="$ f(x_1,\ldots x_{2n})$"&gt;

was defined so cleverly that the total number of Langford pairs can be 
found algebraically. This quickly reminded me about the 
&lt;EM&gt;generating functions&lt;/EM&gt; , where we use an algebraic expression to count 
possible partitions of a natural number. Let me first explain the 
intuition behind that algebraic formulation of function 
&lt;!-- MATH
 $f(x_1,x_2\ldots x_{2n})$
 --&gt;
&lt;IMG
 WIDTH="113" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img19.png"
 ALT="$ f(x_1,x_2\ldots x_{2n})$"&gt;
.

&lt;P&gt;

&lt;UL&gt;
&lt;LI&gt;Consider a Langford permutation &lt;IMG
 WIDTH="9" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img4.png"
 ALT="$ l$"&gt;
, now consider
the positions of each integer &lt;!-- MATH
 $1\leq k \leq n$
 --&gt;
&lt;IMG
 WIDTH="73" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img20.png"
 ALT="$ 1\leq k \leq n$"&gt;
 occurs for the first time
from the left of the permutation. By the definition of the Langford pair 
if an integer &lt;IMG
 WIDTH="13" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img21.png"
 ALT="$ k$"&gt;
 appears at position &lt;IMG
 WIDTH="12" HEIGHT="29" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img22.png"
 ALT="$ j$"&gt;
 in the permutation, then none of the 
integers except &lt;IMG
 WIDTH="13" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img21.png"
 ALT="$ k$"&gt;
 can occur at position &lt;IMG
 WIDTH="67" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img23.png"
 ALT="$ j+k+1$"&gt;

 - which is towards the right. 
Also note that the integer &lt;IMG
 WIDTH="13" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img21.png"
 ALT="$ k$"&gt;
 can only occur at positions &lt;!-- MATH
 $1\leq j \leq 2n-k-1$
 --&gt;
&lt;IMG
 WIDTH="135" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img24.png"
 ALT="$ 1\leq j \leq 2n-k-1$"&gt;
.
Let &lt;!-- MATH
 $S=\{1,1,2,2,3,3,4,4,\}$
 --&gt;
&lt;IMG
 WIDTH="172" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img25.png"
 ALT="$ S=\{1,1,2,2,3,3,4,4,\}$"&gt;
, for example, in any Langford permutation of &lt;IMG
 WIDTH="15" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img6.png"
 ALT="$ S$"&gt;
, the
integer &lt;IMG
 WIDTH="12" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img26.png"
 ALT="$ 4$"&gt;
 can only occur at positions &lt;!-- MATH
 $1\leq j \leq 3$
 --&gt;

&lt;IMG
 WIDTH="70" HEIGHT="29" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img27.png"
 ALT="$ 1\leq j \leq 3$"&gt;
. Similarly integer &lt;IMG
 WIDTH="12" HEIGHT="13" ALIGN="BOTTOM" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img11.png"
 ALT="$ 1$"&gt;
 can
occur at positions &lt;!-- MATH
 $1\leq j \leq 6$
 --&gt;
&lt;IMG
 WIDTH="70" HEIGHT="29" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img28.png"
 ALT="$ 1\leq j \leq 6$"&gt;
. Now this explains the intuition behind &lt;!-- MATH
 $x_{j}x_{j+k+1}$
 --&gt;
&lt;IMG
 WIDTH="69" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img29.png"
 ALT="$ x_{j}x_{j+k+1}$"&gt;

in the definition of the function &lt;IMG
 WIDTH="47" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img30.png"
 ALT="$ f(\dots)$"&gt;
.

&lt;P&gt;
&lt;/LI&gt;
&lt;LI&gt;Let &lt;!-- MATH
 $P':\{1,2,3,\ldots n\}\rightarrow \{1,2,3,\ldots ,2n\}$
 --&gt;

&lt;IMG
 WIDTH="258" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img31.png"
 ALT="$ P':\{1,2,3,\ldots n\}\rightarrow \{1,2,3,\ldots ,2n\}$"&gt;
 be a function - we call
it a position map. Which maps every integer &lt;!-- MATH
 $1\leq k \leq n$
 --&gt;
&lt;IMG
 WIDTH="73" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img20.png"
 ALT="$ 1\leq k \leq n$"&gt;
 to a index/position in the permutation
&lt;!-- MATH
 $1\leq j \leq 2n$
 --&gt;
&lt;IMG
 WIDTH="79" HEIGHT="29" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img32.png"
 ALT="$ 1\leq j \leq 2n$"&gt;
. Let &lt;!-- MATH
 $P_l = \{1,2,3,\ldots 2n\}$
 --&gt;
&lt;IMG
 WIDTH="140" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img33.png"
 ALT="$ P_l = \{1,2,3,\ldots 2n\}$"&gt;
 and &lt;!-- MATH
 $P=\{P'(1),P'(1)+2,P'(2),P'(2)+3,\ldots,P'(n),P'(n)+n+1\}$
 --&gt;
&lt;IMG
 WIDTH="455" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img34.png"
 ALT="$ P=\{P'(1),P'(1)+2,P'(2),P'(2)+3,\ldots,P'(n),P'(n)+n+1\}$"&gt;
.
We now see that a position map &lt;IMG
 WIDTH="21" HEIGHT="15" ALIGN="BOTTOM" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img35.png"
 ALT="$ P'$"&gt;

 can generate a Langford permutation only if &lt;!-- MATH
 $|P_l\cap P| = 2n$
 --&gt;
&lt;IMG
 WIDTH="97" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img36.png"
 ALT="$ \vert P_l\cap P\vert = 2n$"&gt;
. 
In other words the position mapping function should map the integers &lt;!-- MATH
 $1\leq k \leq n$
 --&gt;
&lt;IMG
 WIDTH="73" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img20.png"
 ALT="$ 1\leq k \leq n$"&gt;
 in such a way
that, when we introduce the corresponding pairs - at positions &lt;IMG
 WIDTH="98" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img37.png"
 ALT="$ P'(k)+k+1$"&gt;
, we should not see any 
duplicates. Now all possible function mappings of &lt;IMG
 WIDTH="21" HEIGHT="15" ALIGN="BOTTOM" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img35.png"
 ALT="$ P'$"&gt;
 is described algebraically as follows.
&lt;P&gt;&lt;!-- MATH
 \begin{displaymath}
\begin{array}{l}
t(x_1,x_2\ldots x_{2n})= \\
(x_1x_3 + x_2x_5 + \ldots + x_{2n-2}x_{2n}) (x_1x_4+x_2x_5+\ldots +x_{2n-3}x_{2n}) \ldots (x_1x_{n+2}+x_2x_{n+3}\ldots x_{n-1}x_{2n})
\end{array}
\end{displaymath}
 --&gt;
&lt;/P&gt;
&lt;DIV ALIGN="CENTER"&gt;

&lt;IMG
 WIDTH="674" HEIGHT="45" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img38.png"
 ALT="\begin{displaymath}
\begin{array}{l}
t(x_1,x_2\ldots x_{2n})= \\
(x_1x_3 + x_2x...
... \ldots (x_1x_{n+2}+x_2x_{n+3}\ldots x_{n-1}x_{2n})
\end{array}\end{displaymath}"&gt;
&lt;/DIV&gt;&lt;P&gt;
&lt;/P&gt;
Now if we observe carefully every term in the expansion of the above algebraic expression represents every possible &lt;IMG
 WIDTH="17" HEIGHT="14" ALIGN="BOTTOM" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img39.png"
 ALT="$ P$"&gt;
 (see above).
More specifically every term in the above expansion is of the form &lt;!-- MATH
 $x_1^{a_1}x_2^{a_2}x_3^{a_3}\ldots x_{2n}^{a_{2n}}$
 --&gt;
&lt;IMG
 WIDTH="127" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img40.png"
 ALT="$ x_1^{a_1}x_2^{a_2}x_3^{a_3}\ldots x_{2n}^{a_{2n}}$"&gt;
 and 
&lt;!-- MATH
 $1\leq a_j \leq n, 1\leq j \leq 2n$
 --&gt;
&lt;IMG
 WIDTH="162" HEIGHT="29" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img41.png"
 ALT="$ 1\leq a_j \leq n, 1\leq j \leq 2n$"&gt;
. Now we are looking for all the possible terms which have &lt;!-- MATH
 $a_j = 1 , 1\leq j \leq 2n$
 --&gt;
&lt;IMG
 WIDTH="131" HEIGHT="29" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img42.png"
 ALT="$ a_j = 1 , 1\leq j \leq 2n$"&gt;
,
every such term represents a Langford pair.


&lt;P&gt;
&lt;/LI&gt;
&lt;LI&gt;We now have seen how a clever algebraic expression can help us in counting difficult combinatorial objects. But we are still
not done - why? . Because we need to filter out all the terms which don't satisfy &lt;!-- MATH
 $a_j=1, 1\leq j \leq 2n$
 --&gt;
&lt;IMG
 WIDTH="131" HEIGHT="29" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img42.png"
 ALT="$ a_j = 1 , 1\leq j \leq 2n$"&gt;
. How do we do that ?,
this is where the trick of &lt;EM&gt;odd&lt;/EM&gt; , &lt;EM&gt;even&lt;/EM&gt; functions come into play. Now by making &lt;!-- MATH
 $x_j \in \{-1,1\}$
 --&gt;
&lt;IMG
 WIDTH="91" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img43.png"
 ALT="$ x_j \in \{-1,1\}$"&gt;
 we have a chance to 
wipe-out all terms which contain odd powers for some &lt;IMG
 WIDTH="20" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img44.png"
 ALT="$ x_j$"&gt;

. This is done by multiplying the expression &lt;!-- MATH
 $t(x_1,x_2,x_3\ldots, x_{2n})$
 --&gt;
&lt;IMG
 WIDTH="140" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img45.png"
 ALT="$ t(x_1,x_2,x_3\ldots, x_{2n})$"&gt;

by &lt;!-- MATH
 $e(x_1,x_2\ldots x_{2n})=x_1x_2x_3\dots x_{2n}$
 --&gt;
&lt;IMG
 WIDTH="229" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img46.png"
 ALT="$ e(x_1,x_2\ldots x_{2n})=x_1x_2x_3\dots x_{2n}$"&gt;
 by doing this every term in &lt;!-- MATH
 $e(x_1,\dots x_{2n})t(x_1,\dots ,x_{2n})$
 --&gt;
&lt;IMG
 WIDTH="186" HEIGHT="32" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img47.png"
 ALT="$ e(x_1,\dots x_{2n})t(x_1,\dots ,x_{2n})$"&gt;
 will have
at least one &lt;IMG
 WIDTH="20" HEIGHT="30" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img44.png"
 ALT="$ x_j$"&gt;
 with odd power except the Langford term which will be &lt;!-- MATH
 $x_1^2x_2^2\ldots x_{2n}^2$
 --&gt;

&lt;IMG
 WIDTH="85" HEIGHT="34" ALIGN="MIDDLE" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img48.png"
 ALT="$ x_1^2x_2^2\ldots x_{2n}^2$"&gt;
. Thus the summation on knocks out
all the terms except the Langford terms as follows.
&lt;P&gt;&lt;!-- MATH
 \begin{displaymath}
\begin{array}{l}
f(x_1,x_2\ldots x_{2n}) = e(x_1,x_2,\ldots x_{2n})t(x_1,x_2,\ldots x_{2n}) \\
\par
\rightarrow \displaystyle\sum_{(x_1,x_2,\ldots x_{2n} \in \{-1,1\}^{2n}}f(x_1,x_2\ldots x_{2n}) = 2^{2n} (\text{no.of Langford pairs})
\par
\end{array}
\end{displaymath}
 --&gt;
&lt;/P&gt;
&lt;DIV ALIGN="CENTER"&gt;
&lt;IMG
 WIDTH="460" HEIGHT="76" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/langford_pairs/img49.png"
 ALT="\begin{displaymath}
\begin{array}{l}
f(x_1,x_2\ldots x_{2n}) = e(x_1,x_2,\ldots ...
...x_{2n}) = 2^{2n} (\text{no.of Langford pairs})
\par
\end{array}\end{displaymath}"&gt;
&lt;/DIV&gt;&lt;P&gt;
&lt;/P&gt;

&lt;P&gt;
&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;

&lt;ADDRESS&gt;
Vamsi Kundeti
2009-09-02
&lt;/ADDRESS&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-4390177840185241545?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/4390177840185241545/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=4390177840185241545&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/4390177840185241545'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/4390177840185241545'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2009/09/algebraic-methods-for-combinatorial.html' title='Algebraic methods for Combinatorial counting.'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-8070973317412943774</id><published>2009-03-10T18:43:00.000-07:00</published><updated>2009-03-10T18:52:40.520-07:00</updated><title type='text'>[TECH] Maintaining a Load Factor (α) in Dynamic Data structures with constant (Θ(1)) amortized cost per operation.</title><content type='html'>&lt;em&gt;Accounting Method&lt;/em&gt; is an elegant technique for amortized analysis of the data structures. Most of us should
have encountered &lt;em&gt;Dynamic data structures&lt;/em&gt; (which need to expand and contract to maintain some invariant) at 
some point of time. A stack implementation is one example of a dynamic data structure. As we perform &lt;i&gt;pop&lt;/i&gt; 
operation on the stack eventually it become full (&lt;em&gt;over-flow&lt;/em&gt;), at this stage we might choose to increase 
(may be by doubling or some other heuristic) the size of the stack. We also want to handle the &lt;em&gt;under-flows&lt;/em&gt; 

i.e. if the number of elements in the stack is too small we might want to relocate the elements into a new stack (
with smaller size ). In general the dynamic data structures have a parameter called the &lt;em&gt;load factor&lt;/em&gt; &lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img1.png" alt="$\alpha$" width="15" align="bottom" border="0" height="14"&gt;
and our aim is to maintain that. One simple way to maintain this is to handle under-flows and over-flows on demand.
Unfortunately this will not give us a &lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img2.png" alt="$\Theta(1)$" width="40" align="middle" border="0" height="36"&gt; amortized cost per operation on the stack. However we can still
get &lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img2.png" alt="$\Theta(1)$" width="40" align="middle" border="0" height="36"&gt; amortized cost by avoiding this on demand expansion and compaction. 

&lt;p&gt;
Let &lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img3.png" alt="$N_i$" width="24" align="middle" border="0" height="32"&gt; denote the number of elements present on the stack after &lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img4.png" alt="$i$" width="10" align="bottom" border="0" height="18"&gt; operations (including &lt;em&gt;push&lt;/em&gt; and &lt;em&gt;pop&lt;/em&gt;). 
Let &lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img5.png" alt="$S_i$" width="20" align="middle" border="0" height="32"&gt; denote the allocated size of the stack after &lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img4.png" alt="$i$" width="10" align="bottom" border="0" height="18"&gt; operations. We Define a potential energy function 

&lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img6.png" alt="$\Phi$" width="17" align="bottom" border="0" height="15"&gt; as follows.
&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;
&lt;div align="center"&gt;
&lt;!-- MATH
 \begin{displaymath}
\Phi(i) = 2\times N_i - S_i
\end{displaymath}
 --&gt;

&lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img7.png" alt="\begin{displaymath}
\Phi(i) = 2\times N_i - S_i
\end{displaymath}" width="140" border="0" height="31"&gt;
&lt;/div&gt;
&lt;br clear="all"&gt;
&lt;p&gt;&lt;/p&gt;
Clearly &lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img8.png" alt="$\Phi(0) = 0$" width="71" align="middle" border="0" height="36"&gt;. 
The amortized cost of the &lt;em&gt;push&lt;/em&gt; operation which does not require an expansion of
the stack is as follows.
&lt;br&gt;&lt;p&gt;&lt;/p&gt;
&lt;div align="center"&gt;

&lt;!-- MATH
 \begin{displaymath}
\begin{array}{rcl}
          &amp; = &amp; \mbox{actual cost} + \mbox{potential change} \\
c^{1}_{i} &amp; = &amp; 1 + \Phi(i) - \Phi(i-1) \\
      &amp;=&amp; 1 + 2\times N_i - S_i - (2\times (N_i - 1)  - S_i) \\
   &amp;=&amp; 3 
\end{array}
\end{displaymath}
 --&gt;

&lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img9.png" alt="\begin{displaymath}
\begin{array}{rcl}
&amp;amp; = &amp;amp; \mbox{actual cost} + \mbox{potenti...
...s N_i - S_i - (2\times (N_i - 1) - S_i) \\
&amp;amp;=&amp;amp; 3
\end{array}\end{displaymath}" width="340" border="0" height="93"&gt;
&lt;/div&gt;
&lt;br clear="all"&gt;
&lt;p&gt;&lt;/p&gt;
The amortized cost of the &lt;em&gt;push&lt;/em&gt; operation which requires doubling of the array is
as follows.
&lt;br&gt;&lt;p&gt;&lt;/p&gt;
&lt;div align="center"&gt;
&lt;!-- MATH
 \begin{displaymath}
\begin{array}{rcl}
          &amp;=&amp; \mbox{cost of copying} + \mbox{potential change} \\
c^{2}_{i} &amp;=&amp; S_i/2 + (2\times S_i/2) - S_i) - (2\times(S_i/2 - 1) - S_i/2) \\
          &amp;=&amp; S_i/2 + (0) - (S_i/2-2) \\
    &amp;=&amp; 2
\end{array}
\end{displaymath}
 --&gt;

&lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img10.png" alt="\begin{displaymath}
\begin{array}{rcl}
&amp;amp;=&amp;amp; \mbox{cost of copying} + \mbox{poten...
... S_i/2) \\
&amp;amp;=&amp;amp; S_i/2 + (0) - (S_i/2-2) \\
&amp;amp;=&amp;amp; 2
\end{array}\end{displaymath}" width="430" border="0" height="93"&gt;
&lt;/div&gt;
&lt;br clear="all"&gt;

&lt;p&gt;&lt;/p&gt;
The amortized cost of the &lt;em&gt;pop&lt;/em&gt; 
&lt;br&gt;&lt;p&gt;&lt;/p&gt;
&lt;div align="center"&gt;
&lt;!-- MATH
 \begin{displaymath}
\begin{array}{rcl}
c^{3}_{i} &amp;=&amp; 1 + (2\times (N_i - 1) - S_i) - (2\times N_i - S_i) \\
       &amp;=&amp; -1
\end{array}
\end{displaymath}
 --&gt;

&lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img11.png" alt="\begin{displaymath}
\begin{array}{rcl}
c^{3}_{i} &amp;amp;=&amp;amp; 1 + (2\times (N_i - 1) - S_i) - (2\times N_i - S_i) \\
&amp;amp;=&amp;amp; -1
\end{array}\end{displaymath}" width="354" border="0" height="50"&gt;
&lt;/div&gt;
&lt;br clear="all"&gt;
&lt;p&gt;&lt;/p&gt;
From the above we can see that that amortized cost of all the operations is &lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img12.png" alt="$O(1)$" width="40" align="middle" border="0" height="36"&gt; when we use
the doubling heuristic for the stack.

&lt;p&gt;

&lt;/p&gt;&lt;h2&gt;&lt;a name="SECTION00001000000000000000"&gt;
(b)&lt;/a&gt;
&lt;/h2&gt;
Let the &lt;em&gt;load factor&lt;/em&gt; &lt;!-- MATH
 $\alpha = N_i/S_i$
 --&gt;
&lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img13.png" alt="$\alpha = N_i/S_i$" width="83" align="middle" border="0" height="36"&gt; and let &lt;!-- MATH
 $1-c = 1/2k, k\in \mathbb{R}, c \in (0,1)$
 --&gt;
&lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img14.png" alt="$1-c = 1/2k, k\in \mathbb{R}, c \in (0,1)$" width="227" align="middle" border="0" height="36"&gt;. We use the 
following heuristic to handle &lt;em&gt;expansion&lt;/em&gt; and &lt;em&gt;compaction&lt;/em&gt; of the array. 


&lt;p&gt;
"When &lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img15.png" alt="$\alpha=1$" width="47" align="bottom" border="0" height="14"&gt; (i.e. the array is full) increase the size of the array by &lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img16.png" alt="$k$" width="14" align="bottom" border="0" height="15"&gt; times. 
When &lt;!-- MATH
 $\alpha \leq 1/2k$
 --&gt;
&lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img17.png" alt="$\alpha \leq 1/2k$" width="74" align="middle" border="0" height="36"&gt; (i.e. the array about to under flow) reduce the size of the array
by half (&lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img18.png" alt="$1/2$" width="30" align="middle" border="0" height="36"&gt;)".

&lt;/p&gt;&lt;p&gt;
We define the following potential function and finally show that the amortized complexity of each of
the operations &lt;i&gt;push&lt;/i&gt;, &lt;i&gt;pop&lt;/i&gt; is &lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img12.png" alt="$O(1)$" width="40" align="middle" border="0" height="36"&gt;.

&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;
&lt;div align="center"&gt;
&lt;!-- MATH
 \begin{displaymath}
\begin{array}{rcl}
\Phi(i) &amp;=&amp; \left\{ \begin{array}{rl}
      k\times N_i - S_i &amp; \mbox{\bf If $\alpha \geq 1/k$} \\
      S_i/k - N_i &amp; \mbox{\bf If $1/2k \leq \alpha &lt; 1/k$} \\
        \end{array} 
   \right.
\end{array}
\end{displaymath}
 --&gt;

&lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img19.png" alt="\begin{displaymath}
\begin{array}{rcl}
\Phi(i) &amp;amp;=&amp;amp; \left\{ \begin{array}{rl}
k\...
...1/2k \leq \alpha &amp;lt; 1/k$} \\
\end{array}
\right.
\end{array}\end{displaymath}" width="341" border="0" height="50"&gt;
&lt;/div&gt;
&lt;br clear="all"&gt;
&lt;p&gt;&lt;/p&gt;

&lt;p&gt;
We now prove that the amortized cost of each operation is bounded by a constant. From the
previous problem (since the potential function is same as the previous problem when &lt;!-- MATH
 $\alpha \geq 1/k$
 --&gt;
&lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img20.png" alt="$\alpha \geq 1/k$" width="66" align="middle" border="0" height="36"&gt;) 
we can observe that &lt;i&gt;push&lt;/i&gt; operation when &lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img15.png" alt="$\alpha=1$" width="47" align="bottom" border="0" height="14"&gt; (&lt;em&gt;expansion&lt;/em&gt;) has an amortized cost of 

&lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img21.png" alt="$2$" width="13" align="bottom" border="0" height="14"&gt;. We can also observe that whenever expansion does not occur the amortized cost of the push operation
is &lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img22.png" alt="$3$" width="13" align="bottom" border="0" height="14"&gt;. So we will concentrate on the other possible situations. We use the notation &lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img23.png" alt="$\alpha_i$" width="21" align="middle" border="0" height="31"&gt; to 
indicate the load factor of the array after &lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img4.png" alt="$i$" width="10" align="bottom" border="0" height="18"&gt; operations on the array. 

&lt;/p&gt;&lt;p&gt;

&lt;/p&gt;&lt;h2&gt;&lt;a name="SECTION00002000000000000000"&gt;
Amortized cost of &lt;i&gt;push&lt;/i&gt; when &lt;!-- MATH
 $1/2k \leq \alpha_i &lt; 1/k$
 --&gt;
&lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img24.png" alt="$ 1/2k \leq \alpha_i &amp;lt; 1/k$" width="130" align="middle" border="0" height="36"&gt; &lt;/a&gt;
&lt;/h2&gt; 

&lt;br&gt;&lt;p&gt;&lt;/p&gt;
&lt;div align="center"&gt;
&lt;!-- MATH
 \begin{displaymath}
\begin{array}{rcl}
      &amp;=&amp; \mbox{actual cost} + \mbox{potential change} \\
 c^{4}_i &amp;=&amp; 1 + (S_i/k - N_i) - (S_{i-1}/k - N_{i-1}) \\
         &amp;=&amp; 1 + (S_i/k - N_i) - (S_{i}/k - (N_{i} -1)) \\
   &amp;=&amp; 0
\end{array}
\end{displaymath}
 --&gt;

&lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img25.png" alt="\begin{displaymath}
\begin{array}{rcl}
&amp;amp;=&amp;amp; \mbox{actual cost} + \mbox{potential...
...+ (S_i/k - N_i) - (S_{i}/k - (N_{i} -1)) \\
&amp;amp;=&amp;amp; 0
\end{array}\end{displaymath}" width="330" border="0" height="93"&gt;
&lt;/div&gt;
&lt;br clear="all"&gt;
&lt;p&gt;&lt;/p&gt;

&lt;p&gt;

&lt;/p&gt;&lt;h2&gt;&lt;a name="SECTION00003000000000000000"&gt;
Amortized cost of &lt;i&gt;push&lt;/i&gt; when &lt;!-- MATH
 $\alpha_i \geq 1/k$
 --&gt;

&lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img26.png" alt="$\alpha_i \geq 1/k$" width="71" align="middle" border="0" height="36"&gt;, &lt;!-- MATH
 $\alpha_{i-1} &lt; 1/k$
 --&gt;
&lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img27.png" alt="$\alpha_{i-1} &amp;lt; 1/k$" width="88" align="middle" border="0" height="36"&gt;&lt;/a&gt;
&lt;/h2&gt; 
&lt;br&gt;&lt;p&gt;&lt;/p&gt;
&lt;div align="center"&gt;
&lt;!-- MATH
 \begin{displaymath}
\begin{array}{rcl}
      &amp;=&amp; \mbox{actual cost} + \mbox{potential change} \\
c^{5}_i &amp;=&amp; 1 + (k\times N_i - S_i) - (S_{i-1}/k - N_{i-1}) \\
        &amp;&amp;   \mbox{note the change in $\Phi$ with change in $\alpha_{i-1}$}\\
  &amp;&amp; \mbox {also the size of array does not change and remains $S_{i-1}$} \\
        &amp;=&amp; 1 + (k\times N_i - S_{i-1}) - (S_{i-1}/k - (N_{i}-1)) \\
  &amp;=&amp; 1 + (k+1)\times N_i - \frac{(k+1)}{k}\times S_{i-1} -1 \\
  &amp;&amp; \mbox{We know $N_i = N_{i-1} +1$ } \\
  &amp;=&amp; (k+1)\times(N_{i-1} + 1) - \frac{k+1}{k}\times S_{i-1} \\
  &amp;&amp; \mbox{$N_{i-1} = \alpha_{i-1}\times S_{i-1}  , \alpha_{i-1} &lt; 1/k$} \\
  &amp;=&amp; (k+1) + (k+1)\alpha_{i-1}S_{i-1} - \frac{k+1}{k} S_{i-1} \\
  &amp;&lt;&amp; (k+1) + \frac{k+1}{k} S_{i-1} - \frac{k+1}{k} S_{i-1} \\
  &amp;&lt;&amp; (k+1)
\end{array}
\end{displaymath}
 --&gt;

&lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img28.png" alt="\begin{displaymath}
\begin{array}{rcl}
&amp;amp;=&amp;amp; \mbox{actual cost} + \mbox{potential...
...}{k} S_{i-1} - \frac{k+1}{k} S_{i-1} \\
&amp;amp;&amp;lt;&amp;amp; (k+1)
\end{array}\end{displaymath}" width="482" border="0" height="271"&gt;
&lt;/div&gt;
&lt;br clear="all"&gt;
&lt;p&gt;&lt;/p&gt;

&lt;p&gt;

&lt;/p&gt;&lt;h2&gt;&lt;a name="SECTION00004000000000000000"&gt;
Amortized cost of &lt;i&gt;pop&lt;/i&gt; when &lt;!-- MATH
 $1/2k &lt; \alpha_{i},\alpha_{i-1} &lt; 1/k$
 --&gt;

&lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img29.png" alt="$1/2k &amp;lt; \alpha_{i},\alpha_{i-1} &amp;lt; 1/k$" width="172" align="middle" border="0" height="36"&gt; &lt;/a&gt;
&lt;/h2&gt;
&lt;br&gt;&lt;p&gt;&lt;/p&gt;
&lt;div align="center"&gt;
&lt;!-- MATH
 \begin{displaymath}
\begin{array}{rcl}
       &amp;=&amp; \mbox{actual cost} + \mbox{potential change} \\
c^{6}_i &amp;=&amp; 1 + (S_i/k - N_i) - (S_{i-1}/k - N_{i-1}) \\
        &amp;=&amp; 1 + (S_{i-1}/k - (N_{i-1} -1 ) ) - (S_{i-1}/k - N_{i-1}) \\
  &amp;=&amp; 1 + 1 \\
        &amp;=&amp; 2
\end{array}
\end{displaymath}
 --&gt;

&lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img30.png" alt="\begin{displaymath}
\begin{array}{rcl}
&amp;amp;=&amp;amp; \mbox{actual cost} + \mbox{potential...
...) - (S_{i-1}/k - N_{i-1}) \\
&amp;amp;=&amp;amp; 1 + 1 \\
&amp;amp;=&amp;amp; 2
\end{array}\end{displaymath}" width="399" border="0" height="115"&gt;
&lt;/div&gt;
&lt;br clear="all"&gt;
&lt;p&gt;&lt;/p&gt;
&lt;h2&gt;&lt;a name="SECTION00005000000000000000"&gt;
Amortized cost of &lt;i&gt;pop&lt;/i&gt; when &lt;!-- MATH
 $\alpha_{i},\alpha_{i-1} \geq 1/k$
 --&gt;

&lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img31.png" alt="$\alpha_{i},\alpha_{i-1} \geq 1/k$" width="113" align="middle" border="0" height="36"&gt; &lt;/a&gt;
&lt;/h2&gt;
&lt;br&gt;&lt;p&gt;&lt;/p&gt;
&lt;div align="center"&gt;
&lt;!-- MATH
 \begin{displaymath}
\begin{array}{rcl}
      &amp;=&amp; \mbox{actual cost} + \mbox{potential change} \\
c^{7}_i &amp;=&amp; 1 + (k\times N_i - S_i) - (k\times N_{i-1} - S_{i-1}) \\
        &amp;=&amp; 1 + (k\times (N_{i-1} - 1) - S_{i-1}) - (k\times N_{i-1} - S_{i-1}) \\
  &amp;=&amp; 1-k
\end{array}
\end{displaymath}
 --&gt;

&lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img32.png" alt="\begin{displaymath}
\begin{array}{rcl}
&amp;amp;=&amp;amp; \mbox{actual cost} + \mbox{potential...
...S_{i-1}) - (k\times N_{i-1} - S_{i-1}) \\
&amp;amp;=&amp;amp; 1-k
\end{array}\end{displaymath}" width="424" border="0" height="93"&gt;
&lt;/div&gt;
&lt;br clear="all"&gt;
&lt;p&gt;&lt;/p&gt;
&lt;h2&gt;&lt;a name="SECTION00006000000000000000"&gt;
Amortized cost of &lt;i&gt;pop&lt;/i&gt; when &lt;!-- MATH
 $1/2k &lt; \alpha_{i} &lt; 1/k$
 --&gt;

&lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img33.png" alt="$1/2k &amp;lt; \alpha_{i} &amp;lt; 1/k$" width="130" align="middle" border="0" height="36"&gt; and &lt;!-- MATH
 $\alpha_{i-1} \geq 1/k$
 --&gt;
&lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img34.png" alt="$\alpha_{i-1} \geq 1/k$" width="88" align="middle" border="0" height="36"&gt; &lt;/a&gt;
&lt;/h2&gt;
&lt;br&gt;&lt;p&gt;&lt;/p&gt;
&lt;div align="center"&gt;
&lt;!-- MATH
 \begin{displaymath}
\begin{array}{rcl}
       &amp;=&amp; \mbox{actual cost} + \mbox{potential change} \\
c^{8}_i &amp;=&amp; 1 + (S_i/k - N_i) - (k\times N_{i-1} - S_{i-1}) \\
        &amp;=&amp; 1 + \frac{k+1}{k} S_{i-1} - (k+1)N_i + k \\
  &amp;=&amp; k+1 + \frac{k+1}{k} S_{i} - (k+1)N_i \\
  &amp;&amp;\mbox{Since size did not change $S_{i-1} = S_{i}$ and  $\alpha_{i} &lt; 1/k$} \\
  &amp;&lt;&amp; k+1 + \frac{k+1}{k} S_{i} - \frac{k+1}{k} S_{i} \\
  &amp;&lt;&amp; k+1
\end{array}
\end{displaymath}
 --&gt;

&lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img35.png" alt="\begin{displaymath}
\begin{array}{rcl}
&amp;amp;=&amp;amp; \mbox{actual cost} + \mbox{potential...
...ac{k+1}{k} S_{i} - \frac{k+1}{k} S_{i} \\
&amp;amp;&amp;lt;&amp;amp; k+1
\end{array}\end{displaymath}" width="435" border="0" height="160"&gt;
&lt;/div&gt;
&lt;br clear="all"&gt;
&lt;p&gt;&lt;/p&gt;
&lt;h2&gt;&lt;a name="SECTION00007000000000000000"&gt;
Amortized cost of &lt;i&gt;pop&lt;/i&gt; when &lt;!-- MATH
 $\alpha_{i-1} \leq 1/2k$
 --&gt;

&lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img36.png" alt="$\alpha_{i-1} \leq 1/2k$" width="97" align="middle" border="0" height="36"&gt; with &lt;em&gt;compaction&lt;/em&gt;&lt;/a&gt;
&lt;/h2&gt;
If the &lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img37.png" alt="$i^th$" width="26" align="bottom" border="0" height="17"&gt; operation is a &lt;i&gt;pop&lt;/i&gt; and we find that the load factor &lt;!-- MATH
 $\alpha \leq 1/2k$
 --&gt;
&lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img17.png" alt="$\alpha \leq 1/2k$" width="74" align="middle" border="0" height="36"&gt; then
we apply &lt;em&gt;compaction&lt;/em&gt;. Compaction reduces the size of the allocated array by &lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img18.png" alt="$1/2$" width="30" align="middle" border="0" height="36"&gt;. So after 
compaction &lt;!-- MATH
 $\alpha \geq 2(1/2k) =  1/k$
 --&gt;

&lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img38.png" alt="$\alpha \geq 2(1/2k) = 1/k$" width="147" align="middle" border="0" height="36"&gt;. The amortized cost of the &lt;i&gt;pop&lt;/i&gt; and compaction is 
as follows.
&lt;br&gt;&lt;p&gt;&lt;/p&gt;
&lt;div align="center"&gt;
&lt;!-- MATH
 \begin{displaymath}
\begin{array}{rcl}
       &amp;=&amp; \mbox{copying cost} + \mbox{potential change} \\
c^{9}_i &amp;=&amp; (N_{i} + 1) + (k\times N_i - S_i)  - (S_{i-1}/k - N_{i-1})\\
        &amp;=&amp; (N_{i} + 1) + (k\times N_i - S_{i-1}/2)  - (S_{i-1}/k - N_{i-1}) \\
  &amp;=&amp; (N_{i-1} - 1 + 1) + (k\times (N_{i-1} -1) - S_{i-1}/2) - (S_{i-1}/k - N_{i-1}) \\
  &amp;=&amp; ((k+2)N_{i-1}) - (k+2)/2k\times S_{i-1} - k \\
  &amp;&amp;\mbox{We know that $N_{i-1} = \alpha_{i-1}S_{i-1}$ and $\alpha_{i-1} \leq 1/2k$} \\
  &amp;\leq&amp; (k+2)/2k\times S_{i-1} - (k+2)/2k\times S_{i-1} - k \\
  &amp;\leq&amp; -k \\
  &amp;&lt;&amp; 1 \\
\end{array}
\end{displaymath}
 --&gt;

&lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img39.png" alt="\begin{displaymath}
\begin{array}{rcl}
&amp;amp;=&amp;amp; \mbox{copying cost} + \mbox{potentia...
.../2k\times S_{i-1} - k \\
&amp;amp;\leq&amp;amp; -k \\
&amp;amp;&amp;lt;&amp;amp; 1 \\
\end{array}\end{displaymath}" width="530" border="0" height="201"&gt;
&lt;/div&gt;
&lt;br clear="all"&gt;
&lt;p&gt;&lt;/p&gt;

&lt;p&gt;
We have proved that the amortized cost of both &lt;i&gt;push&lt;/i&gt; and &lt;i&gt;pop&lt;/i&gt; with all possible values
of the &lt;em&gt;load factor&lt;/em&gt; &lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img1.png" alt="$\alpha$" width="15" align="bottom" border="0" height="14"&gt; to be &lt;img src="http://trinity.engr.uconn.edu/%7Evamsik/blog1/img12.png" alt="$O(1)$" width="40" align="middle" border="0" height="36"&gt;.


&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-8070973317412943774?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/8070973317412943774/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=8070973317412943774&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/8070973317412943774'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/8070973317412943774'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2009/03/tech-maintaining-load-factor-in-dynamic.html' title='[TECH] Maintaining a Load Factor (&amp;alpha;) in Dynamic Data structures with constant (&amp;Theta;(1)) amortized cost per operation.'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-2830475359810418704</id><published>2009-03-10T17:31:00.000-07:00</published><updated>2009-03-10T18:21:20.010-07:00</updated><title type='text'>[TECH] Exponential function (e-μt) is the only unique solution satifying  R(x+t) = R(x)R(t)(semi-group property).</title><content type='html'>&lt;p&gt; Exponential function keeps popping up every where stochastic analysis. However it has a crucial property which is often exploited during the analysis. The property I'm referring to is &lt;b&gt;R(X+Y) = R(Y)R(Y)&lt;/b&gt; (e.g. &lt;b&gt;X&lt;/b&gt; and &lt;b&gt;Y&lt;/b&gt;) could be random variables). Now I prove a strong statement &lt;b&gt;&lt;i&gt;" R(X+Y) = R(X)R(Y) If and Only If R(x) = e&lt;sup&gt;-&amp;mu;t&lt;/sup&gt; where &amp;mu; is some constant&lt;/i&gt;&lt;/b&gt;. The reverse direction (&lt;==) is trivial because we can easily verify the fact by substituting &lt;b&gt;R(x)&lt;/b&gt; with &lt;b&gt;e&lt;sup&gt;-&amp;mu;t&lt;/sup&gt;&lt;/b&gt;. In the following we prove that other direction (==&gt;).
&lt;/p&gt;

&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://trinity.engr.uconn.edu/~vamsik/blog/img3.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 416px; height: 216px;" src="http://trinity.engr.uconn.edu/~vamsik/blog/img3.png" border="0" alt="" /&gt;&lt;/a&gt;

&lt;p&gt;
One may wonder how about function &lt;b&gt;a&lt;sup&gt;x&lt;/sup&gt;&lt;/b&gt; which also satisfies the semi-group property by inspection. However the &lt;b&gt;&amp;mu;&lt;/b&gt; takes care of that observe that &lt;b&gt;a&lt;sup&gt;x&lt;/sup&gt; = e&lt;sup&gt;ln(a)x&lt;/sup&gt;&lt;/b&gt;.
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-2830475359810418704?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/2830475359810418704/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=2830475359810418704&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/2830475359810418704'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/2830475359810418704'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2009/03/tech-exponential-function-e-is-only.html' title='[TECH] Exponential function (&lt;b&gt;e&lt;sup&gt;-&amp;mu;t&lt;/sup&gt;&lt;/b&gt;) is the only unique solution satifying  &lt;b&gt;R(x+t) = R(x)R(t)&lt;/b&gt;(&lt;i&gt;semi-group property&lt;/i&gt;).'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-8119023508361019574</id><published>2008-12-25T03:03:00.000-08:00</published><updated>2008-12-25T03:24:07.702-08:00</updated><title type='text'>[TECH] Simple comparision of real numbers</title><content type='html'>&lt;p&gt;
We know that the fixed precision representation of real numbers is done by mapping them into integer space &lt;b&gt;I&lt;/b&gt; from real space &lt;b&gt;R&lt;/b&gt;. However the underlying integer representation of the 32-bit floats and 64-bit doubles is a sign magnitude representation (that is the reason why we see &lt;b&gt;-0.00&lt;/b&gt; during output of some
numerical algorithms). People seem to be adding a constant to convert the underlying
sign magnitude form to 2's compliment. However following is a more logical conversion (since we know that 2's compliment is 1's compliment +1 , the motivation of 2's compliment is to avoid the -0 as we know). The following comparison routine compares two floating point numbers (add the tolerance in the terms of the number the real numbers to make it approximate comparison).
&lt;/p&gt;


&lt;pre&gt;&lt;span style=' color: Green;'&gt;/*Less than or greater than*/&lt;/span&gt;
&lt;span style=' color: Blue;'&gt;char&lt;/span&gt; CompareFloats(&lt;span style=' color: Blue;'&gt;float&lt;/span&gt; a, &lt;span style=' color: Blue;'&gt;float&lt;/span&gt; b){
    &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; aint = *(&lt;span style=' color: Blue;'&gt;int&lt;/span&gt; *)&amp;amp;a;
    &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; bint = *(&lt;span style=' color: Blue;'&gt;int&lt;/span&gt; *)&amp;amp;b;
    aint = (aint &amp;amp; (&lt;span style=' color: Maroon;'&gt;1UL&lt;/span&gt;&amp;lt;&amp;lt;&lt;span style=' color: Maroon;'&gt;31&lt;/span&gt;))? ~(aint^(&lt;span style=' color: Maroon;'&gt;1UL&lt;/span&gt;&amp;lt;&amp;lt;&lt;span style=' color: Maroon;'&gt;31&lt;/span&gt;))+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;:aint;
    bint = (bint &amp;amp; (&lt;span style=' color: Maroon;'&gt;1UL&lt;/span&gt;&amp;lt;&amp;lt;&lt;span style=' color: Maroon;'&gt;31&lt;/span&gt;))? ~(bint^(&lt;span style=' color: Maroon;'&gt;1UL&lt;/span&gt;&amp;lt;&amp;lt;&lt;span style=' color: Maroon;'&gt;31&lt;/span&gt;))+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;:bint;
    aint -= bint;
    printf(&lt;span style=' color: Maroon;'&gt;"%f %s %f \n"&lt;/span&gt;,a,(aint &amp;lt;&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;)?&lt;span style=' color: Maroon;'&gt;"&amp;lt;"&lt;/span&gt;:&lt;span style=' color: Maroon;'&gt;"&amp;gt;="&lt;/span&gt;,b);
    printf(&lt;span style=' color: Maroon;'&gt;"There are %d real numbers \n"&lt;/span&gt;,(aint&amp;lt;&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;)?-aint:aint);
    printf(&lt;span style=' color: Maroon;'&gt;"between %f and %f (in 32 bit float representation)\n"&lt;/span&gt;,a,b);
}


&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-8119023508361019574?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/8119023508361019574/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=8119023508361019574&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/8119023508361019574'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/8119023508361019574'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2008/12/tech-simple-comparision-of-real-numbers.html' title='[TECH] Simple comparision of real numbers'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-9217628361304477967</id><published>2008-12-18T20:22:00.001-08:00</published><updated>2008-12-18T20:30:55.093-08:00</updated><title type='text'>[TECH] Launchpad and Bazaar</title><content type='html'>&lt;p&gt;
I have now started to move all my development efforts to launchpad and bazaar. I really found launchpad a great place to maintain and release my work. I tried several alternatives before I moved to launchpad, I tried to use code.google but unfortunately its not as rich as launchpad and bazaar. I have released version 0.9 of libEditScript project whose aim to build a high performance and space efficient sequence alignment library. I have charted out the features for the next release, one thing I'm sure people would like to use is a JNI (Java Native Interface) so that people can use this space efficient code in their java code. I have seen that this problem of the need of edit script arises in several occasions, I have seen people using the space inefficient version O(n^2) of edit script computation. This is were we gain significantly in terms of the space saving. Also I have one more idea to make it more parallel in the sense I want to use some concurrent techniques to make this parallel, especially since I have circular queue I can easily use several threads to make this concurrent which I will add as a next step in the next release..
&lt;/p&gt;

&lt;p&gt;
Checkout the libEditScript at &lt;a href="https://launchpad.net/libeditscript"&gt;https://launchpad.net/libeditscript&lt;/a&gt;. Next in my list would be to make a release of the weightedmatching library.
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-9217628361304477967?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/9217628361304477967/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=9217628361304477967&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/9217628361304477967'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/9217628361304477967'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2008/12/tech-launchpad-and-bazaar.html' title='[TECH] Launchpad and Bazaar'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-7282983782402980254</id><published>2008-12-04T23:24:00.000-08:00</published><updated>2008-12-04T23:57:16.861-08:00</updated><title type='text'>[TECH] A non-recursive algorithm to compute the Edit Script in O(min(n1,n2)+log(min(n1,n2)) space</title><content type='html'>&lt;p&gt;
Recently I was working on an area efficient and synthesizable design to compute the edit script (minimum cost sequence of INSERT, DELETE and CHANGE) operations to transform string S&lt;sub&gt;1&lt;/sub&gt; to
S&lt;sub&gt;2&lt;/sub&gt;. After a little bit of thought I have the following idea to build a non-recursive
version of the &lt;a href="http://en.wikipedia.org/wiki/Hirschberg%27s_algorithm"&gt;Hirschberg's algorithm&lt;/a&gt;, since the algorithm is non-recursive we can build an efficient digital circuit with this idea. We use a simple circular queue and apply DFS (Depth First Search) and we can prove that the capacity of this queue at any stage of the algorithm is &amp;theta;(log(min(n&lt;sub&gt;1&lt;/sub&gt;,n&lt;sub&gt;2&lt;/sub&gt;)). The proof is simple we choose the geometrically decreasing string which has smaller length from the given strings(min(n&lt;sub&gt;1&lt;/sub&gt;,n&lt;sub&gt;2&lt;/sub&gt;)). Since we do a depth first search and the depth of subproblem tree is  &amp;theta;(log(min(n&lt;sub&gt;1&lt;/sub&gt;,n&lt;sub&gt;2&lt;/sub&gt;)), so we will have atmost &amp;theta;(log(min(n&lt;sub&gt;1&lt;/sub&gt;,n&lt;sub&gt;2&lt;/sub&gt;)) subproblems in the circular queue at any stage of the algorithm.
&lt;/p&gt;

&lt;p&gt;
The core non-recursive algorithm starts off with the initial problem and finds the minimum alignment split ('q') between (S&lt;sub&gt;1&lt;/sub&gt;[1.....n&lt;sub&gt;1&lt;/sub&gt;/2] and S&lt;sub&gt;2&lt;/sub&gt; creates
two sub problems and appends in the circular queue (currently it uses BFS). Download the linear
space implementation from &lt;a href="http://trinity.engr.uconn.edu/~vamsik/HirschbergAlgo.tgz"&gt;here&lt;/a&gt; Following is the outline of the core non recursive implementation.
&lt;/p&gt;


&lt;pre&gt;     &lt;span style=' color: Maroon;'&gt;91&lt;/span&gt;     CQueue bfs_list;
     &lt;span style=' color: Maroon;'&gt;92&lt;/span&gt;     ESSubProblem es_sub;
     &lt;span style=' color: Maroon;'&gt;93&lt;/span&gt; 
     &lt;span style=' color: Maroon;'&gt;94&lt;/span&gt;     InitializeCQ(&amp;amp;bfs_list,&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(ESSubProblem));
     &lt;span style=' color: Maroon;'&gt;95&lt;/span&gt;     &lt;span style=' color: Green;'&gt;/*Put the toplevel subproblem into the CQueue*/&lt;/span&gt;
     &lt;span style=' color: Maroon;'&gt;96&lt;/span&gt;     es_sub.sub_s1 = s1; es_sub.sub_n1 = n1;
     &lt;span style=' color: Maroon;'&gt;97&lt;/span&gt;     es_sub.sub_s2 = s2; es_sub.sub_n2 = n2;
     &lt;span style=' color: Maroon;'&gt;98&lt;/span&gt; 
     &lt;span style=' color: Maroon;'&gt;99&lt;/span&gt;     AppendCQ(&amp;amp;bfs_list,&amp;amp;es_sub);
    &lt;span style=' color: Maroon;'&gt;100&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;while&lt;/span&gt;(DequeueCQ(&amp;amp;bfs_list,&amp;amp;es_sub)){
    &lt;span style=' color: Maroon;'&gt;101&lt;/span&gt;         sub_s1 = es_sub.sub_s1; sub_s2 = es_sub.sub_s2;
    &lt;span style=' color: Maroon;'&gt;102&lt;/span&gt;         sub_n1 = es_sub.sub_n1; sub_n2 = es_sub.sub_n2;
    &lt;span style=' color: Maroon;'&gt;103&lt;/span&gt; 
    &lt;span style=' color: Maroon;'&gt;104&lt;/span&gt;         &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(sub_n1 &amp;lt;=&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;){
    &lt;span style=' color: Maroon;'&gt;105&lt;/span&gt;             &lt;span style=' color: Green;'&gt;/*If sub_n1 is 1 or 0 we cannot split it any more*/&lt;/span&gt;
    &lt;span style=' color: Maroon;'&gt;106&lt;/span&gt;             EditDistanceLS(sub_s1,sub_n1,sub_s2,sub_n2);
    &lt;span style=' color: Maroon;'&gt;107&lt;/span&gt;             i = sub_n1; j = sub_n2;
    &lt;span style=' color: Maroon;'&gt;108&lt;/span&gt;             &lt;span style=' color: Green;'&gt;/*Figure out the edit operations*/&lt;/span&gt;
    &lt;span style=' color: Maroon;'&gt;109&lt;/span&gt;             &lt;span style=' color: Blue;'&gt;while&lt;/span&gt;(i || j){
    &lt;span style=' color: Maroon;'&gt;110&lt;/span&gt;                 op = GetOp(i,j,(i?sub_s1[i-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;]:&lt;span style=' color: Maroon;'&gt;'\0'&lt;/span&gt;),
    &lt;span style=' color: Maroon;'&gt;111&lt;/span&gt;                     (j?sub_s2[j-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;]:&lt;span style=' color: Maroon;'&gt;'\0'&lt;/span&gt;));
    &lt;span style=' color: Maroon;'&gt;112&lt;/span&gt;                 &lt;span style=' color: Blue;'&gt;switch&lt;/span&gt;(op){
    &lt;span style=' color: Maroon;'&gt;113&lt;/span&gt;                     &lt;span style=' color: Blue;'&gt;case&lt;/span&gt; &lt;span style=' color: Maroon;'&gt;'I'&lt;/span&gt;:
    &lt;span style=' color: Maroon;'&gt;114&lt;/span&gt;                             EditScriptS2[(&amp;amp;sub_s2[j-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;]) - s2] = &lt;span style=' color: Maroon;'&gt;'I'&lt;/span&gt;;
    &lt;span style=' color: Maroon;'&gt;115&lt;/span&gt;                             j--;
    &lt;span style=' color: Maroon;'&gt;116&lt;/span&gt;                             &lt;span style=' color: Blue;'&gt;break&lt;/span&gt;;
    &lt;span style=' color: Maroon;'&gt;117&lt;/span&gt;                     &lt;span style=' color: Blue;'&gt;case&lt;/span&gt; &lt;span style=' color: Maroon;'&gt;'D'&lt;/span&gt;:
    &lt;span style=' color: Maroon;'&gt;118&lt;/span&gt;                             EditScriptS1[(&amp;amp;sub_s1[i-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;]) - s1] = &lt;span style=' color: Maroon;'&gt;'D'&lt;/span&gt;;
    &lt;span style=' color: Maroon;'&gt;119&lt;/span&gt;                             i--;
    &lt;span style=' color: Maroon;'&gt;120&lt;/span&gt;                             &lt;span style=' color: Blue;'&gt;break&lt;/span&gt;;
    &lt;span style=' color: Maroon;'&gt;121&lt;/span&gt;                     &lt;span style=' color: Blue;'&gt;case&lt;/span&gt; &lt;span style=' color: Maroon;'&gt;'C'&lt;/span&gt;:
    &lt;span style=' color: Maroon;'&gt;122&lt;/span&gt;                             EditScriptS1[(&amp;amp;sub_s1[i-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;]) - s1] =
    &lt;span style=' color: Maroon;'&gt;123&lt;/span&gt;                                 (sub_s1[i-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;] == sub_s2[j-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;])?&lt;span style=' color: Maroon;'&gt;':'&lt;/span&gt;:&lt;span style=' color: Maroon;'&gt;'C'&lt;/span&gt;;
    &lt;span style=' color: Maroon;'&gt;124&lt;/span&gt;                                 i--; j--;
    &lt;span style=' color: Maroon;'&gt;125&lt;/span&gt;                 }
    &lt;span style=' color: Maroon;'&gt;126&lt;/span&gt;             }
    &lt;span style=' color: Maroon;'&gt;127&lt;/span&gt;         }&lt;span style=' color: Blue;'&gt;else&lt;/span&gt; {
    &lt;span style=' color: Maroon;'&gt;128&lt;/span&gt;             &lt;span style=' color: Green;'&gt;/*Add the two subproblems*/&lt;/span&gt;
    &lt;span style=' color: Maroon;'&gt;129&lt;/span&gt;             q = FindMinSplit(sub_s1,sub_n1,sub_s2,sub_n2);
    &lt;span style=' color: Maroon;'&gt;130&lt;/span&gt;             &lt;span style=' color: Green;'&gt;/*SUB PROBLEM 1*/&lt;/span&gt;
    &lt;span style=' color: Maroon;'&gt;131&lt;/span&gt;             es_sub.sub_n1 = CELING(sub_n1,&lt;span style=' color: Maroon;'&gt;2&lt;/span&gt;);
    &lt;span style=' color: Maroon;'&gt;132&lt;/span&gt;             es_sub.sub_n2 = q;
    &lt;span style=' color: Maroon;'&gt;133&lt;/span&gt;             AppendCQ(&amp;amp;bfs_list,&amp;amp;es_sub);
    &lt;span style=' color: Maroon;'&gt;134&lt;/span&gt; 
    &lt;span style=' color: Maroon;'&gt;135&lt;/span&gt;             &lt;span style=' color: Green;'&gt;/*SUB PROBLEM 2*/&lt;/span&gt;
    &lt;span style=' color: Maroon;'&gt;136&lt;/span&gt;             es_sub.sub_s1 = &amp;amp;(sub_s1[CELING(sub_n1,&lt;span style=' color: Maroon;'&gt;2&lt;/span&gt;)]);
    &lt;span style=' color: Maroon;'&gt;137&lt;/span&gt;             es_sub.sub_s2 = &amp;amp;(sub_s2[q]);
    &lt;span style=' color: Maroon;'&gt;138&lt;/span&gt;             es_sub.sub_n1 = sub_n1/&lt;span style=' color: Maroon;'&gt;2&lt;/span&gt;;
    &lt;span style=' color: Maroon;'&gt;139&lt;/span&gt;             es_sub.sub_n2 = sub_n2-q;
    &lt;span style=' color: Maroon;'&gt;140&lt;/span&gt;             AppendCQ(&amp;amp;bfs_list,&amp;amp;es_sub);
    &lt;span style=' color: Maroon;'&gt;141&lt;/span&gt;         }
    &lt;span style=' color: Maroon;'&gt;142&lt;/span&gt;     }




&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-7282983782402980254?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/7282983782402980254/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=7282983782402980254&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/7282983782402980254'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/7282983782402980254'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2008/12/tech-non-recursive-algorithm-to-compute.html' title='[TECH] A non-recursive algorithm to compute the Edit Script in O(min(n&lt;sub&gt;1&lt;/sub&gt;,n&lt;sub&gt;2&lt;/sub&gt;)+log(min(n&lt;sub&gt;1&lt;/sub&gt;,n&lt;sub&gt;2&lt;/sub&gt;)) space'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-2843804848543401943</id><published>2008-10-24T11:26:00.000-07:00</published><updated>2008-10-24T11:47:08.699-07:00</updated><title type='text'>[TECH] A Graph with θ(log(n)) approximation ratio for greedy vertex cover</title><content type='html'>&lt;p&gt;
We know that the greedy algorithm (which picks the vertex with next highest degree) to solve the vertex cover problem is not optimal. However we have &lt;b&gt;2-Approximation&lt;/b&gt; algorithm for the vertex cover problem (based on a integer linear programming formulation). Actually it was not very straight forward to for me prove that the greedy algorithm has an approximation ratio greater than 2. However after some thinking the following construction indeed proves that the greedy algorithms approximation ratio is &gt; 2. In fact we can easily see (from the figure) that the greedy algorithm will first pick the node with highest degree i.e &lt;b&gt;n&lt;/b&gt; (the magenta). Then it deletes all the edges adjacent on the magenta node and continues and clearly the greedy algorithm will have all the nodes in the blue bounding box. However its clear that if we choose the nodes in the oval region we get a minimum vertex cover of size &lt;b&gt;n&lt;/b&gt;. The size of greedy vertex cover is &lt;b&gt;n/2 + n/3 + n/4 .... n/n &amp;asymp; &amp;theta;(nlog(n))&lt;/b&gt; (for large &lt;b&gt;n&lt;/b&gt;) and hence the approximation ratio for this graph is &lt;b&gt;&amp;theta;(log(n))&lt;/b&gt;.
&lt;/p&gt;
&lt;img src="http://trinity.engr.uconn.edu/~vamsik/greedy_cover.png"&gt; &lt;/img&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-2843804848543401943?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/2843804848543401943/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=2843804848543401943&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/2843804848543401943'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/2843804848543401943'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2008/10/tech-graph-with-approximation-ratio-for.html' title='[TECH] A Graph with &lt;b&gt;&amp;theta;(log(n))&lt;/b&gt; approximation ratio for greedy vertex cover'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-6901848923511996049</id><published>2008-10-16T14:48:00.000-07:00</published><updated>2008-10-16T15:25:48.882-07:00</updated><title type='text'>[TECH] On The Uniqueness Of a Perfect Match In Undirected Acyclic graphs.</title><content type='html'>&lt;p&gt;
I was studying about several results related to Tiling Theory. Tiling Theory adds formalism to the question &lt;i&gt;&lt;b&gt;" Given a simple rectangular region (R) can we find
a valid tiling by using tiles from a set (T) "&lt;/i&gt;&lt;/b&gt;. If our tile set (T) is a singleton set with a unit square then we can tile any region. However what if the the tile set contains only a 2x1 rectangle (domino)? what if the tile set contains a set of
polymino's (tetris game)?. Although the question may seem very simple there is a rich combinatorial work based on this question. In fact the study about the tiling problem originated from &lt;a href="http://en.wikipedia.org/wiki/Wang_tile"&gt; Wang's Conjecture &lt;/a&gt; about periodic tiling. Actually the algorithmic research about tiling theory was dormant for quite some time, even the proof for 2x1 dominoes is fairly recent see &lt;a href="http://www.cs.cmu.edu/~dsheehy/research/dominos.pdf"&gt; this &lt;/a&gt;. I was reading about the proof and was really impressed by its elegance. Often people consider simple things useless or don't have enough respect for simple facts, however I always find that good results are based on several very simple facts. In fact I would like to highlight simple ideas in every algorithm I study about. 
&lt;/p&gt;
&lt;p&gt;
In this proof to prove that the problem is NP-complete for 2x1 domino's a simple fact that &lt;b&gt;&lt;i&gt;" There is exactly only one perfect matching (if at all one exists) in a Tree "&lt;/b&gt;&lt;/i&gt; is used. This can be proved intuitively as follows.  
&lt;/p&gt;
&lt;p&gt;
Let &lt;b&gt;M&lt;/b&gt; be the perfect match in the Tree &lt;b&gt;T&lt;/b&gt;, if &lt;b&gt;M&lt;/b&gt; is not a unique perfect match then there should be some other perfect match lets call it &lt;b&gt;M&lt;sup&gt;'&lt;/sup&gt;&lt;/b&gt;. If we observe the leaf nodes in &lt;b&gt;T&lt;/b&gt; which have only
one edge adjacent on them so both &lt;b&gt;M&lt;/b&gt; and &lt;b&gt;M&lt;sup&gt;'&lt;/sup&gt;&lt;/b&gt; should agree
on the matched edges which have leaf nodes of &lt;b&gt;T&lt;/b&gt; as the vertices . We can now
delete all the leaf nodes and their adjacent edges and continue the argument until we don't have any leaf nodes. Thus from this argument its clear that both &lt;b&gt;M&lt;/b&gt; and &lt;b&gt;M&lt;sup&gt;'&lt;/sup&gt;&lt;/b&gt; are the same and hence there is only a unique perfect match if at all if one exists in a tree &lt;b&gt;T&lt;/b&gt;.
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-6901848923511996049?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/6901848923511996049/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=6901848923511996049&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/6901848923511996049'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/6901848923511996049'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2008/10/tech-on-uniqueness-of-perfect-match-in.html' title='[TECH] On The Uniqueness Of a Perfect Match In Undirected Acyclic graphs.'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-5875581469132446567</id><published>2008-10-15T18:26:00.000-07:00</published><updated>2008-10-15T19:01:58.159-07:00</updated><title type='text'>[TECH] Converting Market Matrix Sparse Representation to Row Compressed Sparse Representation</title><content type='html'>&lt;p&gt; I wanted to use some good benchmarks to illustrate the performance gains of the 
Fast Dual Update Algorithm for pre-ordering sparse matrices. University of Florida 
&lt;a href="http://www.cise.ufl.edu/research/sparse/matrices/"&gt; Sparse Library &lt;/a&gt; has
a rich collection of sparse matrices from various domains. Unfortunately all the matrices are in Market Matrix format but not in Row Compressed format which I currently
use.
&lt;/p&gt;

&lt;p&gt;
The following is a handy script which converts the Market Matrix format to Row Compressed Format &lt;a href="http://trinity.engr.uconn.edu/~vamsik/mm2rc.pl"&gt;mm2rc.pl&lt;/a&gt;. The script uses a simple logic based on external sorting.
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-5875581469132446567?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/5875581469132446567/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=5875581469132446567&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/5875581469132446567'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/5875581469132446567'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2008/10/tech-converting-market-matrix-sparse.html' title='[TECH] Converting Market Matrix Sparse Representation to Row Compressed Sparse Representation'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-3667020322892928032</id><published>2008-09-24T15:20:00.000-07:00</published><updated>2008-09-24T15:28:13.537-07:00</updated><title type='text'>[TECH] Computing Eigen Values and Eigen Vectors using LAPACK</title><content type='html'>&lt;p&gt;
I have used the LAPACK to compute the eigen values, till recently
I needed the eigen vectors both left and right. I thought this could
be really handy if you need to compute eigen values and eigen vectors.
Download both library and this file from &lt;a href="http://trinity.engr.uconn.edu/~vamsik/Saeed.tgz"&gt; here &lt;/a&gt;
&lt;/p&gt;
&lt;br&gt;
&lt;pre&gt;&lt;span style=' color: Green;'&gt;/*Computing both the eigen values and eigen vectors using LAPACK.
 *vamsi.krishnak (at) gmail (dot) com
 **/&lt;/span&gt;
#&lt;span style=' color: Blue;'&gt;include&lt;/span&gt; &lt;span style=' color: Maroon;'&gt;"f2c.h"&lt;/span&gt;
#&lt;span style=' color: Blue;'&gt;include&lt;/span&gt; &lt;span style=' color: Maroon;'&gt;"clapack.h"&lt;/span&gt;
#&lt;span style=' color: Blue;'&gt;include&lt;/span&gt;&amp;lt;stdio.h&amp;gt;
#&lt;span style=' color: Blue;'&gt;include&lt;/span&gt;&amp;lt;math.h&amp;gt;
#&lt;span style=' color: Blue;'&gt;include&lt;/span&gt;&amp;lt;malloc.h&amp;gt;
#&lt;span style=' color: Blue;'&gt;include&lt;/span&gt;&amp;lt;assert.h&amp;gt;

&lt;span style=' color: Blue;'&gt;int&lt;/span&gt; main(){
    integer dim=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;
    &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; i;
    doublereal *A = &lt;span style=' color: Blue;'&gt;NULL&lt;/span&gt;;
    real *eig_values = &lt;span style=' color: Blue;'&gt;NULL&lt;/span&gt;;
    real *work;
    &lt;span style=' color: Blue;'&gt;char&lt;/span&gt; JOBVL=&lt;span style=' color: Maroon;'&gt;'V'&lt;/span&gt;; &lt;span style=' color: Green;'&gt;/*Left eigen vectors*/&lt;/span&gt;
    &lt;span style=' color: Blue;'&gt;char&lt;/span&gt; JOBVR=&lt;span style=' color: Maroon;'&gt;'V'&lt;/span&gt;; &lt;span style=' color: Green;'&gt;/*No right eigen vectors*/&lt;/span&gt;
    integer iwork[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;];
    integer lwork,liwork=&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;,info,lda;
    doublereal *WR=&lt;span style=' color: Blue;'&gt;NULL&lt;/span&gt;;
    doublereal *WI=&lt;span style=' color: Blue;'&gt;NULL&lt;/span&gt;;
    doublereal *VL=&lt;span style=' color: Blue;'&gt;NULL&lt;/span&gt;;
    doublereal *VR=&lt;span style=' color: Blue;'&gt;NULL&lt;/span&gt;;
    integer LDVR=&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;
    integer LDVL=&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;
    integer LDA;
    doublereal *WORK=&lt;span style=' color: Blue;'&gt;NULL&lt;/span&gt;;
    integer LWORK;


    printf(&lt;span style=' color: Maroon;'&gt;"Please Enter the dimension of the array:\n"&lt;/span&gt;);
    scanf(&lt;span style=' color: Maroon;'&gt;"%d"&lt;/span&gt;,&amp;amp;dim); LDA=dim; lda=dim; LDVL=dim;LDVR=dim;
    printf(&lt;span style=' color: Maroon;'&gt;"Please enter the Matrix A\n"&lt;/span&gt;);
    eig_values = (real *) malloc(&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(real)*dim);
    lwork = &lt;span style=' color: Maroon;'&gt;10&lt;/span&gt;*dim; 
    work = (real *) malloc(&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(real)*lwork);
    A = (doublereal *) malloc(&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(doublereal)*(dim*dim));
    printf(&lt;span style=' color: Maroon;'&gt;"Please Enter the elements of the matrix\n"&lt;/span&gt;);
    i = &lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;
    
    &lt;span style=' color: Green;'&gt;/*Double real and imaginary parts*/&lt;/span&gt;
    WR = (doublereal *)malloc(&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(doublereal)*dim);
    WI = (doublereal *)malloc(&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(doublereal)*dim);
    VL = (doublereal *)malloc(&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(doublereal)*(dim*dim));
    VR = (doublereal *)malloc(&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(doublereal)*(dim*dim));
    LWORK = &lt;span style=' color: Maroon;'&gt;6&lt;/span&gt;*dim;
    WORK = (doublereal *)malloc(&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(doublereal)*LWORK);  
    assert(WI &amp;amp;&amp;amp; WR &amp;amp;&amp;amp; VL &amp;amp;&amp;amp; VR);
    &lt;span style=' color: Green;'&gt;/**************/&lt;/span&gt;
    &lt;span style=' color: Blue;'&gt;do&lt;/span&gt;{
        scanf(&lt;span style=' color: Maroon;'&gt;"%lf"&lt;/span&gt;,&amp;amp;A[i]);
        i++;
    }&lt;span style=' color: Blue;'&gt;while&lt;/span&gt;(i&amp;lt;(dim*dim));
    &lt;span style=' color: Green;'&gt;/*Compute the Eigen values*/&lt;/span&gt;
    &lt;span style=' color: Green;'&gt;//ssyev_("N","U",&amp;amp;dim,A,&amp;amp;dim,eig_values,work,&amp;amp;lwork/*,iwork,&amp;amp;liworki*/,&amp;amp;info);&lt;/span&gt;
    dgeev_(&amp;amp;JOBVL,&amp;amp;JOBVR,&amp;amp;dim,A,&amp;amp;LDA,WR,WI,VL,&amp;amp;LDVL,VR,&amp;amp;LDVR,WORK,&amp;amp;LWORK,&amp;amp;info);
    &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(!info){
        &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(i=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;i&amp;lt;dim;i++){
            printf(&lt;span style=' color: Maroon;'&gt;"%lf+i%lf\n"&lt;/span&gt;,WR[i],WI[i]);
        }
        printf(&lt;span style=' color: Maroon;'&gt;"===Right Eigen Vectors===\n"&lt;/span&gt;);
        &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; k; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; conj;
        &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(i=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;i&amp;lt;dim;i++){
            &lt;span style=' color: Green;'&gt;/*Print i^th right eigen vector*/&lt;/span&gt;
            &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(fabs(WI[i] &amp;gt; &lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;)){
                &lt;span style=' color: Green;'&gt;/*eigen vector i and eigen vector i+1*/&lt;/span&gt;
                &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(conj=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;conj&amp;lt;&lt;span style=' color: Maroon;'&gt;2&lt;/span&gt;;conj++){
                    printf(&lt;span style=' color: Maroon;'&gt;"[ "&lt;/span&gt;);
                    &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(k=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;k&amp;lt;dim;k++){
                        &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(!conj){
                            printf(&lt;span style=' color: Maroon;'&gt;"(%lf)+i(%lf) "&lt;/span&gt;,VL[i*dim+k],VL[(i+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;)*dim+k]);

                        }&lt;span style=' color: Blue;'&gt;else&lt;/span&gt;{
                            printf(&lt;span style=' color: Maroon;'&gt;"(%lf)-i(%lf) "&lt;/span&gt;,VL[i*dim+k],VL[(i+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;)*dim+k]);
                        }
                    }
                    printf(&lt;span style=' color: Maroon;'&gt;"  ]\n"&lt;/span&gt;);
                }
                i++;
            }&lt;span style=' color: Blue;'&gt;else&lt;/span&gt;{
                &lt;span style=' color: Green;'&gt;/*real eigen vector*/&lt;/span&gt;
                printf(&lt;span style=' color: Maroon;'&gt;"[  "&lt;/span&gt;);
                &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(k=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;k&amp;lt;dim;k++){
                    printf(&lt;span style=' color: Maroon;'&gt;"%lf "&lt;/span&gt;,VL[i*dim+k]);
                }
                printf(&lt;span style=' color: Maroon;'&gt;"] \n"&lt;/span&gt;);
            }
            printf(&lt;span style=' color: Maroon;'&gt;"\n"&lt;/span&gt;);
        }
    }
}
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-3667020322892928032?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/3667020322892928032/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=3667020322892928032&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/3667020322892928032'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/3667020322892928032'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2008/09/tech-computing-eigen-values-and-eigen.html' title='[TECH] Computing Eigen Values and Eigen Vectors using LAPACK'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-1739212780672221736</id><published>2008-09-18T22:04:00.000-07:00</published><updated>2008-09-18T22:06:55.116-07:00</updated><title type='text'>[TECH] Cauchy's Inequality [continued...]</title><content type='html'>&lt;p&gt;
Just adding the solution to one more problem continuing from last post.
&lt;/p&gt;
&lt;DIV ALIGN="CENTER"&gt;
&lt;IMG
 WIDTH="660" HEIGHT="456" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/cauchy/img2.png"
 ALT="\begin{displaymath}
\begin{array}{l}
{\text{{\bf Problem 3} A Crystallographic I...
...text{square on both sides to complete the proof}\\
\end{array}\end{displaymath}"&gt;
&lt;/DIV&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-1739212780672221736?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/1739212780672221736/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=1739212780672221736&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/1739212780672221736'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/1739212780672221736'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2008/09/tech-cauchys-inequality-continued.html' title='[TECH] Cauchy&apos;s Inequality [continued...]'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-5288331561492867923</id><published>2008-09-17T19:42:00.000-07:00</published><updated>2008-09-17T21:16:22.709-07:00</updated><title type='text'>[TECH] Cauchy's inequality a great tool for approximation algorithms</title><content type='html'>&lt;p&gt;
Its been really long since I made a post, all these day's I'm doing
a lot of theory and trying to come up with approximation algorithms to
the &lt;a href="http://www.springerlink.com/content/pqp7c7emyk7gmx3u/"&gt; Border 
Length Minimization Problem&lt;/a&gt;. After a long time I did prove the problem 
is NP-hard by reducing the T.S.P problem to the B.L.M.P problem. I'm now
trying to find some approximation algorithms for the problem. I thought
if I could strengthen my skills on inequalities it would be really great
and I found a great problem book for inequalities by &lt;a href="http://books.google.com/books?id=7Fm3r9jcbqYC&amp;dq=an+introduction+to+the+art+of+mathematical+inequalities&amp;pg=PP1&amp;ots=4r6Pyh5UR2&amp;sig=ge5SacdW2jxH0hcHkvleEKlGUQg&amp;hl=en&amp;sa=X&amp;oi=book_result&amp;resnum=4&amp;ct=result#PPP10,M1"&gt;Michael Steele&lt;/a&gt; which has a good collections of
problems on inequalities. In this post I provide my solutions to some of the problems
which seemed interesting.
&lt;/p&gt;

&lt;DIV ALIGN="CENTER"&gt;
&lt;IMG
 WIDTH="553" HEIGHT="540" BORDER="0"
 SRC="http://trinity.engr.uconn.edu/~vamsik/cauchy/img1.png"
 ALT="\begin{displaymath}
\begin{array}{lcl}
\multicolumn{3}{c}{\text{The following is...
...
\Rightarrow \text{L.H.S} \leq \sqrt{6} &amp;amp;&amp;amp; \\
\par
\end{array}\end{displaymath}"&gt;
&lt;/DIV&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-5288331561492867923?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/5288331561492867923/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=5288331561492867923&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/5288331561492867923'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/5288331561492867923'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2008/09/tech-cauchys-inequality-great-tool-for.html' title='[TECH] Cauchy&apos;s inequality a great tool for approximation algorithms'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-2038865810609091047</id><published>2008-07-16T18:51:00.000-07:00</published><updated>2008-07-16T19:27:51.440-07:00</updated><title type='text'>[TECH] The shopping problem is as hard as TSP.</title><content type='html'>&lt;p&gt;
&lt;b&gt; The Shopping Problem : &lt;/b&gt; Let &lt;b&gt;I={i&lt;sub&gt;1&lt;/sub&gt;,i&lt;sub&gt;2&lt;/sub&gt;...i&lt;sub&gt;k&lt;/sub&gt;}&lt;/b&gt; be the
items on your shopping list. Let &lt;b&gt;S = {s&lt;sub&gt;1&lt;/sub&gt;,s&lt;sub&gt;2&lt;/sub&gt;,....,s&lt;sub&gt;m&lt;/sub&gt;}&lt;/b&gt; be
the list of stores each store &lt;b&gt;s&lt;sub&gt;i&lt;/sub&gt;&lt;/b&gt; sells only a subset of the
items on your shopping list, and also the cost the items sold by the shops may
vary i.e item &lt;b&gt;i&lt;sub&gt;j&lt;/sub&gt;&lt;/b&gt; may be sold with different prices in different shops, so let &lt;b&gt;C[i,j]&lt;/b&gt; be the cost of item &lt;b&gt;i&lt;/b&gt; in store &lt;b&gt;j&lt;/b&gt;. Since
the shops are located in different places let &lt;b&gt;D[p,q]&lt;/b&gt; be the cost of reaching
store &lt;b&gt;q&lt;/b&gt; from store &lt;b&gt;p&lt;/b&gt;. So our aim is to start at home (H) and buy all
the items we want and return to home with minimum possible cost. As I mentioned in
the previous post this problem is was mentioned in Google Code Jam practice problems, 
however I did not see many submissions to this problem.
&lt;/p&gt;

&lt;p&gt;
Firstly the problem is NP-hard because if items sold by each of the stores are disjoint and they are singleton sets then we should visit all the stores in the right
order to minimize the total distance traveled, this is nothing by TSP. The following is the dynamic programming formulation for this problem. Let &lt;b&gt;S(V,j)&lt;/b&gt; be a optimal solution to buy all the items in set &lt;b&gt;V&lt;/b&gt; ending at store &lt;b&gt;j&lt;/b&gt;. Then
the following is the DP formulation. &lt;br&gt;
&lt;b&gt;S(V,j) = min { S(V-{k},p) + D[p,j] + C[k,j] } ; k \in V, 1&lt;=p&lt;=m &lt;/b&gt; 
&lt;b&gt; Final Answer = min { S(I,j) + D[j,Home] } &lt;/b&gt; Initialization of the
DP is simple you may want to look at the code below.
&lt;/p&gt;

&lt;p&gt;
Further complexity to the problem can be added by saying that the items are
classified as Perishable&lt;b&gt;P&lt;/b&gt; and Non-Perishable&lt;b&gt;N&lt;/b&gt;. So when ever you 
buy a perishable item you need to go back home to put in the refrigerator. The
above DP formulation can be extended to this easily as follows. Let &lt;b&gt;S(V,j,P)&lt;/b&gt; 
be the optimal sub problem of shopping all the items in the set &lt;b&gt;V&lt;/b&gt; ending
at the store &lt;b&gt;j&lt;/b&gt; and having a Perishable item in the shopping cart, on the
same lines &lt;b&gt;S(V,j,N)&lt;/b&gt; optimal sub problem of shopping all the items in the
set &lt;b&gt;V&lt;/b&gt; ending at store &lt;b&gt;j&lt;/b&gt; with NO perishable item in the shopping cart.
Then the following formulation will give the optimal solution.&lt;br&gt;
&lt;pre&gt;
&lt;b&gt;S(V,j,P) = min {S(V-{k},p,P) + D[p,Home] + D[Home,j] + C[k,j] } or
              min {S(V-{k},p,N) + D[p,j] + C[k,j] } &lt;/b&gt;
If k is a perishable item
&lt;/pre&gt;

We can write similar formulations for Non-Perishable items also, get the &lt;a href="http://trinity.engr.uconn.edu/~vamsik/practice4.c"&gt;code here&lt;/a&gt; implementing
the shopping problem.


&lt;/p&gt;

&lt;pre&gt;&lt;span style='color: Teal; background-color: '&gt;  1&lt;/span&gt; &lt;span style=' color: Green;'&gt;/*Vamsi Kundeti (vamsi(dot)krishnak(at)gmail*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;  2&lt;/span&gt; #&lt;span style=' color: Blue;'&gt;include&lt;/span&gt;&amp;lt;stdio.h&amp;gt;
&lt;span style='color: Teal; background-color: '&gt;  3&lt;/span&gt; #&lt;span style=' color: Blue;'&gt;include&lt;/span&gt;&amp;lt;stdlib.h&amp;gt;
&lt;span style='color: Teal; background-color: '&gt;  4&lt;/span&gt; #&lt;span style=' color: Blue;'&gt;include&lt;/span&gt;&amp;lt;&lt;span style=' color: Blue;'&gt;string&lt;/span&gt;.h&amp;gt;
&lt;span style='color: Teal; background-color: '&gt;  5&lt;/span&gt; #&lt;span style=' color: Blue;'&gt;include&lt;/span&gt;&amp;lt;assert.h&amp;gt;
&lt;span style='color: Teal; background-color: '&gt;  6&lt;/span&gt; #&lt;span style=' color: Blue;'&gt;include&lt;/span&gt;&amp;lt;math.h&amp;gt;
&lt;span style='color: Teal; background-color: '&gt;  7&lt;/span&gt; #&lt;span style=' color: Blue;'&gt;include&lt;/span&gt; &lt;span style=' color: Maroon;'&gt;"List.h"&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;  8&lt;/span&gt; &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; **GRAPH;
&lt;span style='color: Teal; background-color: '&gt;  9&lt;/span&gt; &lt;span style=' color: Green;'&gt;//#define VERBOSE_MODE 1&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt; 10&lt;/span&gt; &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; item_bits;
&lt;span style='color: Teal; background-color: '&gt; 11&lt;/span&gt; &lt;span style=' color: Blue;'&gt;char&lt;/span&gt; **item_names;
&lt;span style='color: Teal; background-color: '&gt; 12&lt;/span&gt; &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; item_subset;
&lt;span style='color: Teal; background-color: '&gt; 13&lt;/span&gt; &lt;span style=' color: Green;'&gt;/*has a unsigned int indicating
&lt;span style='color: Teal; background-color: '&gt; 14&lt;/span&gt; *if this shop sells the item or not
&lt;span style='color: Teal; background-color: '&gt; 15&lt;/span&gt; */&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt; 16&lt;/span&gt; &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; *shop_sells;
&lt;span style='color: Teal; background-color: '&gt; 17&lt;/span&gt; &lt;span style=' color: Green;'&gt;/*dist[i][j] indicates the distance 
&lt;span style='color: Teal; background-color: '&gt; 18&lt;/span&gt;  *between i and j*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt; 19&lt;/span&gt; &lt;span style=' color: Blue;'&gt;double&lt;/span&gt; **dist;
&lt;span style='color: Teal; background-color: '&gt; 20&lt;/span&gt; &lt;span style=' color: Green;'&gt;/*cost[i][j] indicates the cost of
&lt;span style='color: Teal; background-color: '&gt; 21&lt;/span&gt; *item i in shop j
&lt;span style='color: Teal; background-color: '&gt; 22&lt;/span&gt; */&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt; 23&lt;/span&gt; &lt;span style=' color: Blue;'&gt;double&lt;/span&gt; **cost;
&lt;span style='color: Teal; background-color: '&gt; 24&lt;/span&gt; &lt;span style=' color: Green;'&gt;/*The number of the items*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt; 25&lt;/span&gt; &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; icount;
&lt;span style='color: Teal; background-color: '&gt; 26&lt;/span&gt; &lt;span style=' color: Green;'&gt;/*The number of test cases*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt; 27&lt;/span&gt; &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; tcount;
&lt;span style='color: Teal; background-color: '&gt; 28&lt;/span&gt; &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; caseno;
&lt;span style='color: Teal; background-color: '&gt; 29&lt;/span&gt; &lt;span style=' color: Green;'&gt;/*The number of shops**/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt; 30&lt;/span&gt; &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; scount;
&lt;span style='color: Teal; background-color: '&gt; 31&lt;/span&gt; &lt;span style=' color: Blue;'&gt;typedef&lt;/span&gt; &lt;span style=' color: Blue;'&gt;struct&lt;/span&gt; _pair_ {
&lt;span style='color: Teal; background-color: '&gt; 32&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; x;
&lt;span style='color: Teal; background-color: '&gt; 33&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; y;
&lt;span style='color: Teal; background-color: '&gt; 34&lt;/span&gt; }Coor;
&lt;span style='color: Teal; background-color: '&gt; 35&lt;/span&gt; Coor *shop_coor;
&lt;span style='color: Teal; background-color: '&gt; 36&lt;/span&gt; &lt;span style=' color: Blue;'&gt;void&lt;/span&gt; EnumSubSetsBFS(&lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; n);
&lt;span style='color: Teal; background-color: '&gt; 37&lt;/span&gt; &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; LookUpItem(&lt;span style=' color: Blue;'&gt;const&lt;/span&gt; &lt;span style=' color: Blue;'&gt;char&lt;/span&gt; *key){
&lt;span style='color: Teal; background-color: '&gt; 38&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; i=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;
&lt;span style='color: Teal; background-color: '&gt; 39&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(i=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;i&amp;lt;icount;i++){
&lt;span style='color: Teal; background-color: '&gt; 40&lt;/span&gt;         &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(!strcmp(key,item_names[i])){
&lt;span style='color: Teal; background-color: '&gt; 41&lt;/span&gt;             &lt;span style=' color: Blue;'&gt;return&lt;/span&gt; i+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;
&lt;span style='color: Teal; background-color: '&gt; 42&lt;/span&gt;         }
&lt;span style='color: Teal; background-color: '&gt; 43&lt;/span&gt;     }
&lt;span style='color: Teal; background-color: '&gt; 44&lt;/span&gt;     &lt;span style=' color: Green;'&gt;/*Ignore this item*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt; 45&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;return&lt;/span&gt; &lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;
&lt;span style='color: Teal; background-color: '&gt; 46&lt;/span&gt; }
&lt;span style='color: Teal; background-color: '&gt; 47&lt;/span&gt; &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; gas_price;
&lt;span style='color: Teal; background-color: '&gt; 48&lt;/span&gt; &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; perish;
&lt;span style='color: Teal; background-color: '&gt; 49&lt;/span&gt; &lt;span style=' color: Blue;'&gt;inline&lt;/span&gt; &lt;span style=' color: Blue;'&gt;char&lt;/span&gt; CheckPerish(&lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; i){
&lt;span style='color: Teal; background-color: '&gt; 50&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;return&lt;/span&gt; (perish &amp;amp; (&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;&amp;lt;&amp;lt;(i)))?&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;:&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;
&lt;span style='color: Teal; background-color: '&gt; 51&lt;/span&gt; }
&lt;span style='color: Teal; background-color: '&gt; 52&lt;/span&gt; &lt;span style=' color: Blue;'&gt;void&lt;/span&gt; ReadInput(&lt;span style=' color: Blue;'&gt;void&lt;/span&gt;){
&lt;span style='color: Teal; background-color: '&gt; 53&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; i,j;
&lt;span style='color: Teal; background-color: '&gt; 54&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; len;
&lt;span style='color: Teal; background-color: '&gt; 55&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; icost;
&lt;span style='color: Teal; background-color: '&gt; 56&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;char&lt;/span&gt; item_buffer[&lt;span style=' color: Maroon;'&gt;64&lt;/span&gt;];
&lt;span style='color: Teal; background-color: '&gt; 57&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;char&lt;/span&gt; delim; 
&lt;span style='color: Teal; background-color: '&gt; 58&lt;/span&gt;     scanf(&lt;span style=' color: Maroon;'&gt;"%u"&lt;/span&gt;,&amp;amp;tcount);
&lt;span style='color: Teal; background-color: '&gt; 59&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;while&lt;/span&gt;(tcount--){
&lt;span style='color: Teal; background-color: '&gt; 60&lt;/span&gt;         perish=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;
&lt;span style='color: Teal; background-color: '&gt; 61&lt;/span&gt;         scanf(&lt;span style=' color: Maroon;'&gt;"%u %u %u"&lt;/span&gt;,&amp;amp;icount,&amp;amp;scount,&amp;amp;gas_price);
&lt;span style='color: Teal; background-color: '&gt; 62&lt;/span&gt;         assert(icount &amp;amp;&amp;amp; scount);
&lt;span style='color: Teal; background-color: '&gt; 63&lt;/span&gt;         &lt;span style=' color: Green;'&gt;/*Read the items to be bought*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt; 64&lt;/span&gt;         item_names = (&lt;span style=' color: Blue;'&gt;char&lt;/span&gt; **) malloc(&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(&lt;span style=' color: Blue;'&gt;char&lt;/span&gt; *)*icount);
&lt;span style='color: Teal; background-color: '&gt; 65&lt;/span&gt;         &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(i=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;i&amp;lt;icount;i++){
&lt;span style='color: Teal; background-color: '&gt; 66&lt;/span&gt;             scanf(&lt;span style=' color: Maroon;'&gt;"%s"&lt;/span&gt;,&amp;amp;item_buffer);
&lt;span style='color: Teal; background-color: '&gt; 67&lt;/span&gt;             len = strlen(item_buffer);
&lt;span style='color: Teal; background-color: '&gt; 68&lt;/span&gt;             len = (len &amp;gt; &lt;span style=' color: Maroon;'&gt;64&lt;/span&gt;)?&lt;span style=' color: Maroon;'&gt;64&lt;/span&gt;:len;
&lt;span style='color: Teal; background-color: '&gt; 69&lt;/span&gt;             item_names[i] = (&lt;span style=' color: Blue;'&gt;char&lt;/span&gt; *) malloc(&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(&lt;span style=' color: Blue;'&gt;char&lt;/span&gt;)*(len+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;));
&lt;span style='color: Teal; background-color: '&gt; 70&lt;/span&gt;             assert(memcpy(item_names[i],item_buffer,(len+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;))==item_names[i]);
&lt;span style='color: Teal; background-color: '&gt; 71&lt;/span&gt;             &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(len &amp;amp;&amp;amp; (item_names[i])[len-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;]==&lt;span style=' color: Maroon;'&gt;'!'&lt;/span&gt;){
&lt;span style='color: Teal; background-color: '&gt; 72&lt;/span&gt;                 perish = perish | (&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt; &amp;lt;&amp;lt; (i));
&lt;span style='color: Teal; background-color: '&gt; 73&lt;/span&gt;                 (item_names[i])[len-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;]=&lt;span style=' color: Maroon;'&gt;'\0'&lt;/span&gt;;
&lt;span style='color: Teal; background-color: '&gt; 74&lt;/span&gt;             }
&lt;span style='color: Teal; background-color: '&gt; 75&lt;/span&gt;         }
&lt;span style='color: Teal; background-color: '&gt; 76&lt;/span&gt;         shop_coor = (Coor *) malloc(&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(Coor)*(scount+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;));
&lt;span style='color: Teal; background-color: '&gt; 77&lt;/span&gt;         cost = (&lt;span style=' color: Blue;'&gt;double&lt;/span&gt; **) malloc(&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(&lt;span style=' color: Blue;'&gt;double&lt;/span&gt; *)*(scount+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;));
&lt;span style='color: Teal; background-color: '&gt; 78&lt;/span&gt;         shop_sells = (&lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; *)malloc(&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(&lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt;)*(scount+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;));
&lt;span style='color: Teal; background-color: '&gt; 79&lt;/span&gt;         shop_coor[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;].x = &lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;&lt;span style=' color: Maroon;'&gt;.0&lt;/span&gt;;
&lt;span style='color: Teal; background-color: '&gt; 80&lt;/span&gt;         shop_coor[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;].y = &lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;&lt;span style=' color: Maroon;'&gt;.0&lt;/span&gt;;
&lt;span style='color: Teal; background-color: '&gt; 81&lt;/span&gt;         &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(i=&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;i&amp;lt;scount+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;i++){
&lt;span style='color: Teal; background-color: '&gt; 82&lt;/span&gt;             cost[i] = (&lt;span style=' color: Blue;'&gt;double&lt;/span&gt; *) malloc(&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(&lt;span style=' color: Blue;'&gt;double&lt;/span&gt;)*icount);
&lt;span style='color: Teal; background-color: '&gt; 83&lt;/span&gt;             scanf(&lt;span style=' color: Maroon;'&gt;"%d %d"&lt;/span&gt;,&amp;amp;(shop_coor[i].x),&amp;amp;(shop_coor[i].y));
&lt;span style='color: Teal; background-color: '&gt; 84&lt;/span&gt;             shop_sells[i] = &lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;
&lt;span style='color: Teal; background-color: '&gt; 85&lt;/span&gt;             &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(j=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;j&amp;lt;icount;j++){
&lt;span style='color: Teal; background-color: '&gt; 86&lt;/span&gt;                 cost[i][j] = &lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;
&lt;span style='color: Teal; background-color: '&gt; 87&lt;/span&gt;             }
&lt;span style='color: Teal; background-color: '&gt; 88&lt;/span&gt;             &lt;span style=' color: Blue;'&gt;while&lt;/span&gt;(&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;){
&lt;span style='color: Teal; background-color: '&gt; 89&lt;/span&gt;                 scanf(&lt;span style=' color: Maroon;'&gt;" %[^:]:%u"&lt;/span&gt;,item_buffer,&amp;amp;icost);
&lt;span style='color: Teal; background-color: '&gt; 90&lt;/span&gt;                 &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(j=LookUpItem(item_buffer)){
&lt;span style='color: Teal; background-color: '&gt; 91&lt;/span&gt;                     cost[i][j-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;] = icost;
&lt;span style='color: Teal; background-color: '&gt; 92&lt;/span&gt;                     &lt;span style=' color: Green;'&gt;/*Also set the sells bit_set*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt; 93&lt;/span&gt;                     shop_sells[i] = shop_sells[i] | (&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;&amp;lt;&amp;lt;(j-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;));
&lt;span style='color: Teal; background-color: '&gt; 94&lt;/span&gt;                 }
&lt;span style='color: Teal; background-color: '&gt; 95&lt;/span&gt;                 scanf(&lt;span style=' color: Maroon;'&gt;"%c"&lt;/span&gt;,&amp;amp;delim);
&lt;span style='color: Teal; background-color: '&gt; 96&lt;/span&gt;                 &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(delim == &lt;span style=' color: Maroon;'&gt;'\n'&lt;/span&gt;){
&lt;span style='color: Teal; background-color: '&gt; 97&lt;/span&gt;                     &lt;span style=' color: Blue;'&gt;break&lt;/span&gt;;
&lt;span style='color: Teal; background-color: '&gt; 98&lt;/span&gt;                 }
&lt;span style='color: Teal; background-color: '&gt; 99&lt;/span&gt;             }
&lt;span style='color: Teal; background-color: '&gt;100&lt;/span&gt;         }
&lt;span style='color: Teal; background-color: '&gt;101&lt;/span&gt;         &lt;span style=' color: Green;'&gt;/*Now Compute the distance matrix*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;102&lt;/span&gt;         dist = (&lt;span style=' color: Blue;'&gt;double&lt;/span&gt; **)malloc(&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(&lt;span style=' color: Blue;'&gt;double&lt;/span&gt; *)*(scount+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;));
&lt;span style='color: Teal; background-color: '&gt;103&lt;/span&gt;         &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(i=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;i&amp;lt;scount+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;i++){
&lt;span style='color: Teal; background-color: '&gt;104&lt;/span&gt;             dist[i] = (&lt;span style=' color: Blue;'&gt;double&lt;/span&gt; *)malloc(&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(&lt;span style=' color: Blue;'&gt;double&lt;/span&gt;)*(scount+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;));
&lt;span style='color: Teal; background-color: '&gt;105&lt;/span&gt;             &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(j=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;j&amp;lt;scount+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;j++){
&lt;span style='color: Teal; background-color: '&gt;106&lt;/span&gt;                 dist[i][j] = sqrtf((shop_coor[i].x - shop_coor[j].x)*
&lt;span style='color: Teal; background-color: '&gt;107&lt;/span&gt;                     (shop_coor[i].x - shop_coor[j].x) +(shop_coor[i].y - shop_coor[j].y)*
&lt;span style='color: Teal; background-color: '&gt;108&lt;/span&gt;                         (shop_coor[i].y - shop_coor[j].y));
&lt;span style='color: Teal; background-color: '&gt;109&lt;/span&gt;             }
&lt;span style='color: Teal; background-color: '&gt;110&lt;/span&gt;         }
&lt;span style='color: Teal; background-color: '&gt;111&lt;/span&gt; &lt;span style=' color: Blue;'&gt;#if&lt;/span&gt; &lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;112&lt;/span&gt;         printf(&lt;span style=' color: Maroon;'&gt;"Items..\n"&lt;/span&gt;);
&lt;span style='color: Teal; background-color: '&gt;113&lt;/span&gt;         &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(i=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;i&amp;lt;icount;i++){
&lt;span style='color: Teal; background-color: '&gt;114&lt;/span&gt;             printf(&lt;span style=' color: Maroon;'&gt;"%s "&lt;/span&gt;,item_names[i]);
&lt;span style='color: Teal; background-color: '&gt;115&lt;/span&gt;         }
&lt;span style='color: Teal; background-color: '&gt;116&lt;/span&gt;         printf(&lt;span style=' color: Maroon;'&gt;"\n"&lt;/span&gt;);
&lt;span style='color: Teal; background-color: '&gt;117&lt;/span&gt;         printf(&lt;span style=' color: Maroon;'&gt;"Cost Matrix\n"&lt;/span&gt;);
&lt;span style='color: Teal; background-color: '&gt;118&lt;/span&gt;         &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(i=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;i&amp;lt;scount+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;i++){
&lt;span style='color: Teal; background-color: '&gt;119&lt;/span&gt;             printf(&lt;span style=' color: Maroon;'&gt;"(%d,%d)"&lt;/span&gt;,shop_coor[i].x,shop_coor[i].y);
&lt;span style='color: Teal; background-color: '&gt;120&lt;/span&gt;             &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(j=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;j&amp;lt;icount;j++){
&lt;span style='color: Teal; background-color: '&gt;121&lt;/span&gt;                 &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(cost[i][j]){
&lt;span style='color: Teal; background-color: '&gt;122&lt;/span&gt;                     printf(&lt;span style=' color: Maroon;'&gt;" %s[%c]:%lf"&lt;/span&gt;,item_names[j],((CheckPerish(j))?&lt;span style=' color: Maroon;'&gt;'P'&lt;/span&gt;:&lt;span style=' color: Maroon;'&gt;'U'&lt;/span&gt;),cost[i][j]);
&lt;span style='color: Teal; background-color: '&gt;123&lt;/span&gt;                 }
&lt;span style='color: Teal; background-color: '&gt;124&lt;/span&gt;             }
&lt;span style='color: Teal; background-color: '&gt;125&lt;/span&gt;             printf(&lt;span style=' color: Maroon;'&gt;"\n"&lt;/span&gt;);
&lt;span style='color: Teal; background-color: '&gt;126&lt;/span&gt;         }
&lt;span style='color: Teal; background-color: '&gt;127&lt;/span&gt;         printf(&lt;span style=' color: Maroon;'&gt;"\n"&lt;/span&gt;);
&lt;span style='color: Teal; background-color: '&gt;128&lt;/span&gt; &lt;span style=' color: Blue;'&gt;#endif&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;129&lt;/span&gt;         &lt;span style=' color: Green;'&gt;/*Make the call to the dynamic programming routine*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;130&lt;/span&gt;         EnumSubSetsBFS(icount);
&lt;span style='color: Teal; background-color: '&gt;131&lt;/span&gt; 
&lt;span style='color: Teal; background-color: '&gt;132&lt;/span&gt;         &lt;span style=' color: Green;'&gt;/*Freeup the stuff*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;133&lt;/span&gt;         &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(i=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;i&amp;lt;icount;i++){
&lt;span style='color: Teal; background-color: '&gt;134&lt;/span&gt;             free(item_names[i]); 
&lt;span style='color: Teal; background-color: '&gt;135&lt;/span&gt;         }
&lt;span style='color: Teal; background-color: '&gt;136&lt;/span&gt;         free(item_names);
&lt;span style='color: Teal; background-color: '&gt;137&lt;/span&gt;         free(shop_coor);
&lt;span style='color: Teal; background-color: '&gt;138&lt;/span&gt;         free(shop_sells);
&lt;span style='color: Teal; background-color: '&gt;139&lt;/span&gt;         &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(i=&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;i&amp;lt;scount+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;i++){
&lt;span style='color: Teal; background-color: '&gt;140&lt;/span&gt;             free(cost[i]);
&lt;span style='color: Teal; background-color: '&gt;141&lt;/span&gt;         }
&lt;span style='color: Teal; background-color: '&gt;142&lt;/span&gt;         free(cost);
&lt;span style='color: Teal; background-color: '&gt;143&lt;/span&gt;         &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(i=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;i&amp;lt;scount+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;i++){
&lt;span style='color: Teal; background-color: '&gt;144&lt;/span&gt;             free(dist[i]);
&lt;span style='color: Teal; background-color: '&gt;145&lt;/span&gt;         }
&lt;span style='color: Teal; background-color: '&gt;146&lt;/span&gt;         free(dist);
&lt;span style='color: Teal; background-color: '&gt;147&lt;/span&gt;     }
&lt;span style='color: Teal; background-color: '&gt;148&lt;/span&gt; }
&lt;span style='color: Teal; background-color: '&gt;149&lt;/span&gt; 
&lt;span style='color: Teal; background-color: '&gt;150&lt;/span&gt; &lt;span style=' color: Blue;'&gt;void&lt;/span&gt; CreateGraph(&lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; *n){
&lt;span style='color: Teal; background-color: '&gt;151&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; i,j;
&lt;span style='color: Teal; background-color: '&gt;152&lt;/span&gt;     printf(&lt;span style=' color: Maroon;'&gt;"Enter the Graph Size\n"&lt;/span&gt;);
&lt;span style='color: Teal; background-color: '&gt;153&lt;/span&gt;     scanf(&lt;span style=' color: Maroon;'&gt;"%u"&lt;/span&gt;,n);
&lt;span style='color: Teal; background-color: '&gt;154&lt;/span&gt;     printf(&lt;span style=' color: Maroon;'&gt;"Enter the weighted graph\n"&lt;/span&gt;);
&lt;span style='color: Teal; background-color: '&gt;155&lt;/span&gt;     GRAPH = (&lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; **) malloc(&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(&lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; *)*(*n));
&lt;span style='color: Teal; background-color: '&gt;156&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(i=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;i&amp;lt;*n;i++){
&lt;span style='color: Teal; background-color: '&gt;157&lt;/span&gt;         GRAPH[i] = (&lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; *) malloc(&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(&lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt;)*(*n));
&lt;span style='color: Teal; background-color: '&gt;158&lt;/span&gt;         &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(j=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;j&amp;lt;*n;j++){
&lt;span style='color: Teal; background-color: '&gt;159&lt;/span&gt;             scanf(&lt;span style=' color: Maroon;'&gt;"%u"&lt;/span&gt;,&amp;amp;(GRAPH[i][j]));
&lt;span style='color: Teal; background-color: '&gt;160&lt;/span&gt;         }
&lt;span style='color: Teal; background-color: '&gt;161&lt;/span&gt;     }
&lt;span style='color: Teal; background-color: '&gt;162&lt;/span&gt; }
&lt;span style='color: Teal; background-color: '&gt;163&lt;/span&gt; 
&lt;span style='color: Teal; background-color: '&gt;164&lt;/span&gt; 
&lt;span style='color: Teal; background-color: '&gt;165&lt;/span&gt; &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; subset_count=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;
&lt;span style='color: Teal; background-color: '&gt;166&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; main(){
&lt;span style='color: Teal; background-color: '&gt;167&lt;/span&gt;     &lt;span style=' color: Green;'&gt;/*Create the Graph*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;168&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; n;
&lt;span style='color: Teal; background-color: '&gt;169&lt;/span&gt;     caseno=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;
&lt;span style='color: Teal; background-color: '&gt;170&lt;/span&gt;     ReadInput();
&lt;span style='color: Teal; background-color: '&gt;171&lt;/span&gt;     &lt;span style=' color: Green;'&gt;//EnumSubSetsBFS(n);&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;172&lt;/span&gt; 
&lt;span style='color: Teal; background-color: '&gt;173&lt;/span&gt; }
&lt;span style='color: Teal; background-color: '&gt;174&lt;/span&gt; &lt;span style=' color: Green;'&gt;/*Returns the new tail of the list*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;175&lt;/span&gt; &lt;span style=' color: Blue;'&gt;inline&lt;/span&gt; List* ListAppend(List **tail,&lt;span style=' color: Blue;'&gt;void&lt;/span&gt; *_data){
&lt;span style='color: Teal; background-color: '&gt;176&lt;/span&gt;     List *new_node = (List *)malloc(&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(new_node)*&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;);
&lt;span style='color: Teal; background-color: '&gt;177&lt;/span&gt;     assert(new_node);
&lt;span style='color: Teal; background-color: '&gt;178&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(!(*tail)){
&lt;span style='color: Teal; background-color: '&gt;179&lt;/span&gt;         (*tail) = new_node;
&lt;span style='color: Teal; background-color: '&gt;180&lt;/span&gt;         (*tail)-&amp;gt;_data = _data;
&lt;span style='color: Teal; background-color: '&gt;181&lt;/span&gt;         (*tail)-&amp;gt;next = &lt;span style=' color: Blue;'&gt;NULL&lt;/span&gt;;
&lt;span style='color: Teal; background-color: '&gt;182&lt;/span&gt;         &lt;span style=' color: Blue;'&gt;return&lt;/span&gt; *tail;
&lt;span style='color: Teal; background-color: '&gt;183&lt;/span&gt;     }
&lt;span style='color: Teal; background-color: '&gt;184&lt;/span&gt;     new_node-&amp;gt;_data = _data;
&lt;span style='color: Teal; background-color: '&gt;185&lt;/span&gt;     new_node-&amp;gt;next = &lt;span style=' color: Blue;'&gt;NULL&lt;/span&gt;;
&lt;span style='color: Teal; background-color: '&gt;186&lt;/span&gt;     (*tail)-&amp;gt;next = new_node;
&lt;span style='color: Teal; background-color: '&gt;187&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;return&lt;/span&gt; new_node;
&lt;span style='color: Teal; background-color: '&gt;188&lt;/span&gt; }
&lt;span style='color: Teal; background-color: '&gt;189&lt;/span&gt; &lt;span style=' color: Blue;'&gt;typedef&lt;/span&gt; &lt;span style=' color: Blue;'&gt;struct&lt;/span&gt; _subset_{
&lt;span style='color: Teal; background-color: '&gt;190&lt;/span&gt;     &lt;span style=' color: Green;'&gt;/*if i^th bit is set then subset has i^th
&lt;span style='color: Teal; background-color: '&gt;191&lt;/span&gt;      *element*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;192&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; ebits;
&lt;span style='color: Teal; background-color: '&gt;193&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; max; &lt;span style=' color: Green;'&gt;/*Maximum element in the subset*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;194&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; size; &lt;span style=' color: Green;'&gt;/*Size of subset*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;195&lt;/span&gt;     &lt;span style=' color: Green;'&gt;/*Pointer to the sub-problem S({},i,0) S({},i,1)*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;196&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;void&lt;/span&gt; *sub_problem;
&lt;span style='color: Teal; background-color: '&gt;197&lt;/span&gt; }SubSet;
&lt;span style='color: Teal; background-color: '&gt;198&lt;/span&gt; 
&lt;span style='color: Teal; background-color: '&gt;199&lt;/span&gt; &lt;span style=' color: Green;'&gt;/*Enumerate the Subset using BFS, n is 
&lt;span style='color: Teal; background-color: '&gt;200&lt;/span&gt;  *the set size [1,2...n] */&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;201&lt;/span&gt; &lt;span style=' color: Blue;'&gt;void&lt;/span&gt; EnumSubSetsBFS(&lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; n){
&lt;span style='color: Teal; background-color: '&gt;202&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; check_sub_set,k,i,j;
&lt;span style='color: Teal; background-color: '&gt;203&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; current_level = &lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;
&lt;span style='color: Teal; background-color: '&gt;204&lt;/span&gt;     List *bfs_list = &lt;span style=' color: Blue;'&gt;NULL&lt;/span&gt;;
&lt;span style='color: Teal; background-color: '&gt;205&lt;/span&gt;     List *tail = &lt;span style=' color: Blue;'&gt;NULL&lt;/span&gt;; List *free_node,*ptr;
&lt;span style='color: Teal; background-color: '&gt;206&lt;/span&gt;     SubSet *sub_set,*new_sub_set;
&lt;span style='color: Teal; background-color: '&gt;207&lt;/span&gt;     SubSet *one_sets = &lt;span style=' color: Blue;'&gt;NULL&lt;/span&gt;;
&lt;span style='color: Teal; background-color: '&gt;208&lt;/span&gt; 
&lt;span style='color: Teal; background-color: '&gt;209&lt;/span&gt;     one_sets = (SubSet *)malloc(&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(SubSet)*icount); 
&lt;span style='color: Teal; background-color: '&gt;210&lt;/span&gt;     assert(one_sets);
&lt;span style='color: Teal; background-color: '&gt;211&lt;/span&gt;     &lt;span style=' color: Green;'&gt;/*Add the 1-subsets i=items*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;212&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(i=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;i&amp;lt;icount;i++){
&lt;span style='color: Teal; background-color: '&gt;213&lt;/span&gt;         one_sets[i].ebits = &lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;; one_sets[i].ebits |= (&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;&amp;lt;&amp;lt;i);
&lt;span style='color: Teal; background-color: '&gt;214&lt;/span&gt;         one_sets[i].max = i; one_sets[i].size = &lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;
&lt;span style='color: Teal; background-color: '&gt;215&lt;/span&gt;         &lt;span style=' color: Green;'&gt;/****SUBPROBLEM SPECIFIC*****/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;216&lt;/span&gt;         one_sets[i].sub_problem = (&lt;span style=' color: Blue;'&gt;double&lt;/span&gt; **)malloc(&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(&lt;span style=' color: Blue;'&gt;double&lt;/span&gt; *)*&lt;span style=' color: Maroon;'&gt;2&lt;/span&gt;);
&lt;span style='color: Teal; background-color: '&gt;217&lt;/span&gt;         &lt;span style=' color: Green;'&gt;/* Perishable S({i},X,0) */&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;218&lt;/span&gt;         ((&lt;span style=' color: Blue;'&gt;double&lt;/span&gt; **)one_sets[i].sub_problem)[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;] = (&lt;span style=' color: Blue;'&gt;double&lt;/span&gt; *) malloc(&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(&lt;span style=' color: Blue;'&gt;double&lt;/span&gt;)*(scount+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;));
&lt;span style='color: Teal; background-color: '&gt;219&lt;/span&gt;         &lt;span style=' color: Green;'&gt;/* Unperishable S({i},X,1) */&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;220&lt;/span&gt;         ((&lt;span style=' color: Blue;'&gt;double&lt;/span&gt; **)one_sets[i].sub_problem)[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;] = (&lt;span style=' color: Blue;'&gt;double&lt;/span&gt; *) malloc(&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(&lt;span style=' color: Blue;'&gt;double&lt;/span&gt;)*(scount+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;));
&lt;span style='color: Teal; background-color: '&gt;221&lt;/span&gt;         &lt;span style=' color: Blue;'&gt;double&lt;/span&gt; **sub_problem_i = (&lt;span style=' color: Blue;'&gt;double&lt;/span&gt; **)one_sets[i].sub_problem;
&lt;span style='color: Teal; background-color: '&gt;222&lt;/span&gt; 
&lt;span style='color: Teal; background-color: '&gt;223&lt;/span&gt;         &lt;span style=' color: Green;'&gt;/*j is the shop*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;224&lt;/span&gt;         &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(j=&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;j&amp;lt;scount+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;j++){
&lt;span style='color: Teal; background-color: '&gt;225&lt;/span&gt;             &lt;span style=' color: Green;'&gt;/*if item i can be bought at shop j
&lt;span style='color: Teal; background-color: '&gt;226&lt;/span&gt;              *depending on perishable or not initialize sub_problem[0] 
&lt;span style='color: Teal; background-color: '&gt;227&lt;/span&gt;              *sub_problem[1]
&lt;span style='color: Teal; background-color: '&gt;228&lt;/span&gt;              */&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;229&lt;/span&gt;              sub_problem_i[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][j] = HUGE_VAL; sub_problem_i[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][j] = HUGE_VAL;
&lt;span style='color: Teal; background-color: '&gt;230&lt;/span&gt;              &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(shop_sells[j]&amp;amp;(&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;&amp;lt;&amp;lt;i)){
&lt;span style='color: Teal; background-color: '&gt;231&lt;/span&gt;                  &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(CheckPerish(i)){
&lt;span style='color: Teal; background-color: '&gt;232&lt;/span&gt;                      sub_problem_i[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][j] = dist[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][j]*(gas_price) + cost[j][i];
&lt;span style='color: Teal; background-color: '&gt;233&lt;/span&gt;                  }&lt;span style=' color: Blue;'&gt;else&lt;/span&gt;{
&lt;span style='color: Teal; background-color: '&gt;234&lt;/span&gt;                      sub_problem_i[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][j] = dist[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][j]*(gas_price) + cost[j][i];
&lt;span style='color: Teal; background-color: '&gt;235&lt;/span&gt;                  }
&lt;span style='color: Teal; background-color: '&gt;236&lt;/span&gt;              }
&lt;span style='color: Teal; background-color: '&gt;237&lt;/span&gt; #ifdef VERBOSE_MODE
&lt;span style='color: Teal; background-color: '&gt;238&lt;/span&gt;             printf(&lt;span style=' color: Maroon;'&gt;"S({%u},%u,0) = %lf\n"&lt;/span&gt;,i+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;,j+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;,sub_problem_i[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][j]);
&lt;span style='color: Teal; background-color: '&gt;239&lt;/span&gt;             printf(&lt;span style=' color: Maroon;'&gt;"S({%u},%u,1) = %lf\n"&lt;/span&gt;,i+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;,j+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;,sub_problem_i[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][j]);
&lt;span style='color: Teal; background-color: '&gt;240&lt;/span&gt; &lt;span style=' color: Blue;'&gt;#endif&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;241&lt;/span&gt;         }
&lt;span style='color: Teal; background-color: '&gt;242&lt;/span&gt;         &lt;span style=' color: Green;'&gt;/*****************************/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;243&lt;/span&gt;         &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(!tail){
&lt;span style='color: Teal; background-color: '&gt;244&lt;/span&gt;             ListAppend(&amp;amp;bfs_list,(&lt;span style=' color: Blue;'&gt;void&lt;/span&gt; *)&amp;amp;(one_sets[i]));
&lt;span style='color: Teal; background-color: '&gt;245&lt;/span&gt;             tail = bfs_list;
&lt;span style='color: Teal; background-color: '&gt;246&lt;/span&gt;             &lt;span style=' color: Blue;'&gt;continue&lt;/span&gt;;
&lt;span style='color: Teal; background-color: '&gt;247&lt;/span&gt;         }
&lt;span style='color: Teal; background-color: '&gt;248&lt;/span&gt;         tail = ListAppend(&amp;amp;tail,(&lt;span style=' color: Blue;'&gt;void&lt;/span&gt; *)&amp;amp;(one_sets[i]));
&lt;span style='color: Teal; background-color: '&gt;249&lt;/span&gt;     }
&lt;span style='color: Teal; background-color: '&gt;250&lt;/span&gt; 
&lt;span style='color: Teal; background-color: '&gt;251&lt;/span&gt; 
&lt;span style='color: Teal; background-color: '&gt;252&lt;/span&gt; 
&lt;span style='color: Teal; background-color: '&gt;253&lt;/span&gt;     &lt;span style=' color: Green;'&gt;/*Now do the BFS*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;254&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;while&lt;/span&gt;(bfs_list){
&lt;span style='color: Teal; background-color: '&gt;255&lt;/span&gt;         sub_set = (SubSet *)bfs_list-&amp;gt;_data; 
&lt;span style='color: Teal; background-color: '&gt;256&lt;/span&gt;         free_node = bfs_list;
&lt;span style='color: Teal; background-color: '&gt;257&lt;/span&gt;         bfs_list=bfs_list-&amp;gt;next;
&lt;span style='color: Teal; background-color: '&gt;258&lt;/span&gt;         subset_count++;
&lt;span style='color: Teal; background-color: '&gt;259&lt;/span&gt;         assert(sub_set-&amp;gt;max &amp;lt; icount);
&lt;span style='color: Teal; background-color: '&gt;260&lt;/span&gt;         &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(i=((sub_set-&amp;gt;max)+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;);i&amp;lt;icount;i++){
&lt;span style='color: Teal; background-color: '&gt;261&lt;/span&gt;             new_sub_set = (SubSet *) malloc(&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(SubSet)*&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;);
&lt;span style='color: Teal; background-color: '&gt;262&lt;/span&gt;             new_sub_set-&amp;gt;size = (sub_set-&amp;gt;size)+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;
&lt;span style='color: Teal; background-color: '&gt;263&lt;/span&gt;             new_sub_set-&amp;gt;max = i;
&lt;span style='color: Teal; background-color: '&gt;264&lt;/span&gt;             new_sub_set-&amp;gt;ebits = (sub_set-&amp;gt;ebits | (&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;&amp;lt;&amp;lt;i));
&lt;span style='color: Teal; background-color: '&gt;265&lt;/span&gt;             &lt;span style=' color: Green;'&gt;/*This subset enumeration is critical to Subset based D.P*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;266&lt;/span&gt; 
&lt;span style='color: Teal; background-color: '&gt;267&lt;/span&gt;             &lt;span style=' color: Green;'&gt;/*****&amp;lt;begin&amp;gt;**SUBPROBLEM SPECIFIC******/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;268&lt;/span&gt;             &lt;span style=' color: Green;'&gt;/* S(X,j) = min_k {S(X-k,k) + d[k][j]}*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;269&lt;/span&gt;             ptr = free_node;
&lt;span style='color: Teal; background-color: '&gt;270&lt;/span&gt;             &lt;span style=' color: Blue;'&gt;double&lt;/span&gt; current_min = HUGE_VAL;
&lt;span style='color: Teal; background-color: '&gt;271&lt;/span&gt;             &lt;span style=' color: Blue;'&gt;double&lt;/span&gt; **new_sub_problem;
&lt;span style='color: Teal; background-color: '&gt;272&lt;/span&gt;             &lt;span style=' color: Blue;'&gt;double&lt;/span&gt; **sub_problem; &lt;span style=' color: Blue;'&gt;double&lt;/span&gt; local_min;
&lt;span style='color: Teal; background-color: '&gt;273&lt;/span&gt;             &lt;span style=' color: Blue;'&gt;double&lt;/span&gt; local_min_perish,local_min_unperish;
&lt;span style='color: Teal; background-color: '&gt;274&lt;/span&gt;             &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; k1,perish,shop1;
&lt;span style='color: Teal; background-color: '&gt;275&lt;/span&gt;             List *ptr_prev;
&lt;span style='color: Teal; background-color: '&gt;276&lt;/span&gt;             
&lt;span style='color: Teal; background-color: '&gt;277&lt;/span&gt;             new_sub_set-&amp;gt;sub_problem = (&lt;span style=' color: Blue;'&gt;double&lt;/span&gt; **) malloc(&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(&lt;span style=' color: Blue;'&gt;double&lt;/span&gt; *)*&lt;span style=' color: Maroon;'&gt;2&lt;/span&gt;);
&lt;span style='color: Teal; background-color: '&gt;278&lt;/span&gt;             ((&lt;span style=' color: Blue;'&gt;double&lt;/span&gt; **)new_sub_set-&amp;gt;sub_problem)[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;] = (&lt;span style=' color: Blue;'&gt;double&lt;/span&gt; *) malloc(&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(&lt;span style=' color: Blue;'&gt;double&lt;/span&gt;)*(scount+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;));
&lt;span style='color: Teal; background-color: '&gt;279&lt;/span&gt;             ((&lt;span style=' color: Blue;'&gt;double&lt;/span&gt; **)new_sub_set-&amp;gt;sub_problem)[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;] = (&lt;span style=' color: Blue;'&gt;double&lt;/span&gt; *) malloc(&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(&lt;span style=' color: Blue;'&gt;double&lt;/span&gt;)*(scount+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;));
&lt;span style='color: Teal; background-color: '&gt;280&lt;/span&gt;             new_sub_problem = (&lt;span style=' color: Blue;'&gt;double&lt;/span&gt; **)new_sub_set-&amp;gt;sub_problem;
&lt;span style='color: Teal; background-color: '&gt;281&lt;/span&gt; 
&lt;span style='color: Teal; background-color: '&gt;282&lt;/span&gt;             &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(perish=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;perish&amp;lt;=&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;perish++){
&lt;span style='color: Teal; background-color: '&gt;283&lt;/span&gt;                 &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(j=&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;j&amp;lt;scount+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;j++){
&lt;span style='color: Teal; background-color: '&gt;284&lt;/span&gt;                     &lt;span style=' color: Green;'&gt;/*Objective here is to fill up S({new_sub_set},j,0) 
&lt;span style='color: Teal; background-color: '&gt;285&lt;/span&gt;                      *and S({new_sub_set},j,1)*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;286&lt;/span&gt;                     ptr = free_node;
&lt;span style='color: Teal; background-color: '&gt;287&lt;/span&gt;                     current_min = HUGE_VAL;
&lt;span style='color: Teal; background-color: '&gt;288&lt;/span&gt;                     &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(k=&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;k&amp;lt;=new_sub_set-&amp;gt;size;k++){
&lt;span style='color: Teal; background-color: '&gt;289&lt;/span&gt;                         &lt;span style=' color: Blue;'&gt;do&lt;/span&gt;{
&lt;span style='color: Teal; background-color: '&gt;290&lt;/span&gt;                             check_sub_set = ((SubSet *)ptr-&amp;gt;_data)-&amp;gt;ebits; 
&lt;span style='color: Teal; background-color: '&gt;291&lt;/span&gt;                             check_sub_set ^= new_sub_set-&amp;gt;ebits; 
&lt;span style='color: Teal; background-color: '&gt;292&lt;/span&gt;                             k1 = (&lt;span style=' color: Blue;'&gt;int&lt;/span&gt;)log2(check_sub_set);
&lt;span style='color: Teal; background-color: '&gt;293&lt;/span&gt;                             ptr_prev = ptr;
&lt;span style='color: Teal; background-color: '&gt;294&lt;/span&gt;                             ptr=ptr-&amp;gt;next;
&lt;span style='color: Teal; background-color: '&gt;295&lt;/span&gt;                         }&lt;span style=' color: Blue;'&gt;while&lt;/span&gt;(check_sub_set &amp;amp; (check_sub_set-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;));
&lt;span style='color: Teal; background-color: '&gt;296&lt;/span&gt; 
&lt;span style='color: Teal; background-color: '&gt;297&lt;/span&gt;                         &lt;span style=' color: Green;'&gt;/*j is the shop and k1 is the item which you want
&lt;span style='color: Teal; background-color: '&gt;298&lt;/span&gt;                          *to buy at this shop, depending on
&lt;span style='color: Teal; background-color: '&gt;299&lt;/span&gt;                          *perishablity create the value of current min.
&lt;span style='color: Teal; background-color: '&gt;300&lt;/span&gt;                         */&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;301&lt;/span&gt;                         &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(!(shop_sells[j] &amp;amp; check_sub_set)){
&lt;span style='color: Teal; background-color: '&gt;302&lt;/span&gt;                              &lt;span style=' color: Blue;'&gt;continue&lt;/span&gt;; &lt;span style=' color: Green;'&gt;/*The shop don't sell this*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;303&lt;/span&gt;                         }
&lt;span style='color: Teal; background-color: '&gt;304&lt;/span&gt;                         sub_problem = (&lt;span style=' color: Blue;'&gt;double&lt;/span&gt; **)
&lt;span style='color: Teal; background-color: '&gt;305&lt;/span&gt;                             ((SubSet *)ptr_prev-&amp;gt;_data)-&amp;gt;sub_problem;
&lt;span style='color: Teal; background-color: '&gt;306&lt;/span&gt;                         &lt;span style=' color: Green;'&gt;/*item k1 is sold by shop j*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;307&lt;/span&gt;                         local_min = HUGE_VAL;
&lt;span style='color: Teal; background-color: '&gt;308&lt;/span&gt;                         &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;((perish &amp;amp;&amp;amp; !CheckPerish(k1)) 
&lt;span style='color: Teal; background-color: '&gt;309&lt;/span&gt;                                 || (!perish &amp;amp;&amp;amp; CheckPerish(k1))){
&lt;span style='color: Teal; background-color: '&gt;310&lt;/span&gt;                             &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(shop1=&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;shop1&amp;lt;scount+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;shop1++){
&lt;span style='color: Teal; background-color: '&gt;311&lt;/span&gt;                                 &lt;span style=' color: Green;'&gt;/*S{{new_sub_set}-{k1},shop1} + 
&lt;span style='color: Teal; background-color: '&gt;312&lt;/span&gt;                                 d(shop1,h) + d(h,j) + c[k1][j]*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;313&lt;/span&gt;                                 &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(j != shop1 || perish){
&lt;span style='color: Teal; background-color: '&gt;314&lt;/span&gt;                                     local_min_perish = 
&lt;span style='color: Teal; background-color: '&gt;315&lt;/span&gt;                                         sub_problem[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][shop1] + 
&lt;span style='color: Teal; background-color: '&gt;316&lt;/span&gt;                                         (dist[shop1][&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;] + dist[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][j])*
&lt;span style='color: Teal; background-color: '&gt;317&lt;/span&gt;                                             (gas_price) + cost[j][k1];
&lt;span style='color: Teal; background-color: '&gt;318&lt;/span&gt;                                 }&lt;span style=' color: Blue;'&gt;else&lt;/span&gt; &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(!perish){
&lt;span style='color: Teal; background-color: '&gt;319&lt;/span&gt;                                     local_min_perish = sub_problem[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][shop1] + 
&lt;span style='color: Teal; background-color: '&gt;320&lt;/span&gt;                                         cost[j][k1];
&lt;span style='color: Teal; background-color: '&gt;321&lt;/span&gt;                                 }
&lt;span style='color: Teal; background-color: '&gt;322&lt;/span&gt;                                 local_min_unperish = sub_problem[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][shop1] + 
&lt;span style='color: Teal; background-color: '&gt;323&lt;/span&gt;                                     (dist[shop1][j])*(gas_price) + cost[j][k1];
&lt;span style='color: Teal; background-color: '&gt;324&lt;/span&gt;                                 local_min_perish = 
&lt;span style='color: Teal; background-color: '&gt;325&lt;/span&gt;                                  (local_min_perish &amp;lt; local_min_unperish)? 
&lt;span style='color: Teal; background-color: '&gt;326&lt;/span&gt;                                     local_min_perish:local_min_unperish;
&lt;span style='color: Teal; background-color: '&gt;327&lt;/span&gt; 
&lt;span style='color: Teal; background-color: '&gt;328&lt;/span&gt;                                 &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(local_min_perish &amp;lt; local_min){
&lt;span style='color: Teal; background-color: '&gt;329&lt;/span&gt;                                     local_min = local_min_perish;
&lt;span style='color: Teal; background-color: '&gt;330&lt;/span&gt;                                 }
&lt;span style='color: Teal; background-color: '&gt;331&lt;/span&gt;                             }
&lt;span style='color: Teal; background-color: '&gt;332&lt;/span&gt;                         }
&lt;span style='color: Teal; background-color: '&gt;333&lt;/span&gt;                         &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(local_min &amp;lt; current_min){
&lt;span style='color: Teal; background-color: '&gt;334&lt;/span&gt;                             current_min = local_min; 
&lt;span style='color: Teal; background-color: '&gt;335&lt;/span&gt;                         }
&lt;span style='color: Teal; background-color: '&gt;336&lt;/span&gt;                     }
&lt;span style='color: Teal; background-color: '&gt;337&lt;/span&gt;                     new_sub_problem[perish][j] = current_min;
&lt;span style='color: Teal; background-color: '&gt;338&lt;/span&gt;                 }
&lt;span style='color: Teal; background-color: '&gt;339&lt;/span&gt;             }
&lt;span style='color: Teal; background-color: '&gt;340&lt;/span&gt; 
&lt;span style='color: Teal; background-color: '&gt;341&lt;/span&gt; #ifdef VERBOSE_MODE
&lt;span style='color: Teal; background-color: '&gt;342&lt;/span&gt;             printf(&lt;span style=' color: Maroon;'&gt;"Printing S(V,i) size=%u \n"&lt;/span&gt;,sub_set-&amp;gt;size);
&lt;span style='color: Teal; background-color: '&gt;343&lt;/span&gt;             &lt;span style=' color: Green;'&gt;/*Print SubSet*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;344&lt;/span&gt;             &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; i1;
&lt;span style='color: Teal; background-color: '&gt;345&lt;/span&gt;             &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(i1=&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;i1&amp;lt;scount+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;i1++){
&lt;span style='color: Teal; background-color: '&gt;346&lt;/span&gt;                 printf(&lt;span style=' color: Maroon;'&gt;"S({"&lt;/span&gt;);
&lt;span style='color: Teal; background-color: '&gt;347&lt;/span&gt;                 &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; j1;
&lt;span style='color: Teal; background-color: '&gt;348&lt;/span&gt;                 &lt;span style=' color: Green;'&gt;/*Get the elements back*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;349&lt;/span&gt;                 check_sub_set = new_sub_set-&amp;gt;ebits;
&lt;span style='color: Teal; background-color: '&gt;350&lt;/span&gt;                 &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(j1=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;j1&amp;lt;icount;j1++){
&lt;span style='color: Teal; background-color: '&gt;351&lt;/span&gt;                     &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(check_sub_set &amp;amp; (&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;&amp;lt;&amp;lt;j1)){
&lt;span style='color: Teal; background-color: '&gt;352&lt;/span&gt;                         printf(&lt;span style=' color: Maroon;'&gt;" %u "&lt;/span&gt;,j1+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;);
&lt;span style='color: Teal; background-color: '&gt;353&lt;/span&gt;                     }
&lt;span style='color: Teal; background-color: '&gt;354&lt;/span&gt;                 }
&lt;span style='color: Teal; background-color: '&gt;355&lt;/span&gt;                 printf(&lt;span style=' color: Maroon;'&gt;"},%u,0)=%lf\n"&lt;/span&gt;,i1+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;,((&lt;span style=' color: Blue;'&gt;double&lt;/span&gt; **)(new_sub_set-&amp;gt;sub_problem))[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][i1]);
&lt;span style='color: Teal; background-color: '&gt;356&lt;/span&gt;                 printf(&lt;span style=' color: Maroon;'&gt;"S({ABOVE},%u,1)=%lf\n"&lt;/span&gt;,i1+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;,((&lt;span style=' color: Blue;'&gt;double&lt;/span&gt; **)(new_sub_set-&amp;gt;sub_problem))[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][i1]);
&lt;span style='color: Teal; background-color: '&gt;357&lt;/span&gt;             }
&lt;span style='color: Teal; background-color: '&gt;358&lt;/span&gt; &lt;span style=' color: Blue;'&gt;#endif&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;359&lt;/span&gt; 
&lt;span style='color: Teal; background-color: '&gt;360&lt;/span&gt;             &lt;span style=' color: Green;'&gt;/**********&amp;lt;END&amp;gt;****************/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;361&lt;/span&gt;             tail = ListAppend(&amp;amp;tail,(&lt;span style=' color: Blue;'&gt;void&lt;/span&gt; *)new_sub_set);
&lt;span style='color: Teal; background-color: '&gt;362&lt;/span&gt;         }
&lt;span style='color: Teal; background-color: '&gt;363&lt;/span&gt; 
&lt;span style='color: Teal; background-color: '&gt;364&lt;/span&gt;         &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(sub_set-&amp;gt;size == icount){
&lt;span style='color: Teal; background-color: '&gt;365&lt;/span&gt;             &lt;span style=' color: Blue;'&gt;double&lt;/span&gt; final_answer=HUGE_VAL;
&lt;span style='color: Teal; background-color: '&gt;366&lt;/span&gt;             &lt;span style=' color: Blue;'&gt;double&lt;/span&gt; local_min; &lt;span style=' color: Blue;'&gt;double&lt;/span&gt; **sub_problem;
&lt;span style='color: Teal; background-color: '&gt;367&lt;/span&gt;             sub_problem = (&lt;span style=' color: Blue;'&gt;double&lt;/span&gt; **) sub_set-&amp;gt;sub_problem;
&lt;span style='color: Teal; background-color: '&gt;368&lt;/span&gt;             &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(j=&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;j&amp;lt;scount+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;j++){
&lt;span style='color: Teal; background-color: '&gt;369&lt;/span&gt;                 local_min = (sub_problem[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][j]&amp;lt;sub_problem[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][j])?
&lt;span style='color: Teal; background-color: '&gt;370&lt;/span&gt;                     sub_problem[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][j]:sub_problem[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][j];
&lt;span style='color: Teal; background-color: '&gt;371&lt;/span&gt;                 local_min += (dist[j][&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;])*(gas_price);
&lt;span style='color: Teal; background-color: '&gt;372&lt;/span&gt;                 &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(local_min &amp;lt; final_answer){
&lt;span style='color: Teal; background-color: '&gt;373&lt;/span&gt;                     final_answer = local_min;
&lt;span style='color: Teal; background-color: '&gt;374&lt;/span&gt;                 }
&lt;span style='color: Teal; background-color: '&gt;375&lt;/span&gt;             }
&lt;span style='color: Teal; background-color: '&gt;376&lt;/span&gt;             printf(&lt;span style=' color: Maroon;'&gt;"Case #%u: %0.7lf\n"&lt;/span&gt;,++caseno,final_answer);
&lt;span style='color: Teal; background-color: '&gt;377&lt;/span&gt;         }
&lt;span style='color: Teal; background-color: '&gt;378&lt;/span&gt; 
&lt;span style='color: Teal; background-color: '&gt;379&lt;/span&gt;         &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(!(sub_set &amp;gt;= one_sets &amp;amp;&amp;amp; sub_set &amp;lt;= &amp;amp;(one_sets[icount-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;]))){
&lt;span style='color: Teal; background-color: '&gt;380&lt;/span&gt;             free(((&lt;span style=' color: Blue;'&gt;double&lt;/span&gt; **)sub_set-&amp;gt;sub_problem)[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;]);
&lt;span style='color: Teal; background-color: '&gt;381&lt;/span&gt;             free(((&lt;span style=' color: Blue;'&gt;double&lt;/span&gt; **)sub_set-&amp;gt;sub_problem)[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;]);
&lt;span style='color: Teal; background-color: '&gt;382&lt;/span&gt;             free(sub_set-&amp;gt;sub_problem);
&lt;span style='color: Teal; background-color: '&gt;383&lt;/span&gt;             free(sub_set); 
&lt;span style='color: Teal; background-color: '&gt;384&lt;/span&gt;         }
&lt;span style='color: Teal; background-color: '&gt;385&lt;/span&gt;         free(free_node);
&lt;span style='color: Teal; background-color: '&gt;386&lt;/span&gt;     }
&lt;span style='color: Teal; background-color: '&gt;387&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(i=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;i&amp;lt;icount;i++){
&lt;span style='color: Teal; background-color: '&gt;388&lt;/span&gt;         free(((&lt;span style=' color: Blue;'&gt;double&lt;/span&gt; **)one_sets[i].sub_problem)[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;]);
&lt;span style='color: Teal; background-color: '&gt;389&lt;/span&gt;         free(((&lt;span style=' color: Blue;'&gt;double&lt;/span&gt; **)one_sets[i].sub_problem)[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;]);
&lt;span style='color: Teal; background-color: '&gt;390&lt;/span&gt;         free(one_sets[i].sub_problem);
&lt;span style='color: Teal; background-color: '&gt;391&lt;/span&gt;     }
&lt;span style='color: Teal; background-color: '&gt;392&lt;/span&gt;     free(one_sets);
&lt;span style='color: Teal; background-color: '&gt;393&lt;/span&gt; &lt;span style=' color: Green;'&gt;//    printf("SubsetCount=%u\n",subset_count);&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;394&lt;/span&gt; }
&lt;span style='color: Teal; background-color: '&gt;395&lt;/span&gt; &lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-2038865810609091047?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/2038865810609091047/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=2038865810609091047&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/2038865810609091047'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/2038865810609091047'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2008/07/tech-shopping-problem-is-as-hard-as-tsp.html' title='[TECH] The shopping problem is as hard as TSP.'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-9054680951916325923</id><published>2008-07-11T14:57:00.000-07:00</published><updated>2008-07-11T15:51:27.567-07:00</updated><title type='text'>[TECH] A O(log(n)) time and O(1) space algorithm to find out Nth Fibonacci number.</title><content type='html'>&lt;p&gt;
We often come across Fibonacci numbers in several contexts, if you see Knuth's "Concrete Mathematics" in the chapter on "Generating functions" one interesting example illustrates the possible brick patterns to build a wall whose width is 'n' using bricks of dimension 2x1. Also see the UVA problem &lt;a href="http://icpcres.ecs.baylor.edu/onlinejudge/index.php?option=com_onlinejudge&amp;page=show_problem&amp;problem=841"&gt;here&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
We know a simple dynamic programming based algorithm can lead us to a &lt;b&gt;O(n)&lt;/b&gt; time algorithm with &lt;b&gt;O(1)&lt;/b&gt;. But we can do much better than that in fact we can do it in &lt;b&gt;O(log(n))&lt;/b&gt; time and &lt;b&gt;O(1)&lt;/b&gt; space. We can rewrite the dynamic programming as matrix formulation as follows.
&lt;/p&gt;
&lt;p&gt;
&lt;!-- matrix expression begin --&gt;
&lt;table style="color:#000"&gt;&lt;tr&gt;
&lt;td&gt;&lt;table border=0 cellpadding=0 cellspacing=0px style="border-left:1px solid #000; border-right:1px solid #000; color:#000"&gt;&lt;tr&gt;
&lt;td style ="border-top:1px solid #000; border-bottom:1px solid #000;"&gt;&amp;nbsp&lt;/td&gt;&lt;td&gt;&lt;table border=0 cellpadding=0 cellspacing=0 style="color:#000;"&gt;
&lt;tr&gt;
&lt;td align="center" valign="center" width=30&gt;F&lt;sub&gt;n&lt;/sub&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align="center" valign="center" width=30&gt;F&lt;sub&gt;n-1&lt;/sub&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;&lt;/td&gt;&lt;td style ="border-top:1px solid #000; border-bottom:1px solid #000;"&gt;&amp;nbsp&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/td&gt;
&lt;td align="center" valign="center" width=30&gt;=&lt;/td&gt;
&lt;td&gt;&lt;table border=0 cellpadding=0 cellspacing=0px style="border-left:1px solid #000; border-right:1px solid #000; color:#000"&gt;&lt;tr&gt;
&lt;td style ="border-top:1px solid #000; border-bottom:1px solid #000;"&gt;&amp;nbsp&lt;/td&gt;&lt;td&gt;&lt;table border=0 cellpadding=0 cellspacing=0 style="color:#000;"&gt;
&lt;tr&gt;
&lt;td align="center" valign="center" width=30&gt;1&lt;/td&gt;
&lt;td align="center" valign="center" width=30&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align="center" valign="center" width=30&gt;1&lt;/td&gt;
&lt;td align="center" valign="center" width=30&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;&lt;/td&gt;&lt;td style ="border-top:1px solid #000; border-bottom:1px solid #000;"&gt;&amp;nbsp&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/td&gt;
&lt;td&gt;&lt;table border=0 cellpadding=0 cellspacing=0px style="border-left:1px solid #000; border-right:1px solid #000; color:#000"&gt;&lt;tr&gt;
&lt;td style ="border-top:1px solid #000; border-bottom:1px solid #000;"&gt;&amp;nbsp&lt;/td&gt;&lt;td&gt;&lt;table border=0 cellpadding=0 cellspacing=0 style="color:#000;"&gt;
&lt;tr&gt;
&lt;td align="center" valign="center" width=30&gt;F&lt;sub&gt;n-1&lt;/sub&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align="center" valign="center" width=30&gt;F&lt;sub&gt;n-2&lt;/sub&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;&lt;/td&gt;&lt;td style ="border-top:1px solid #000; border-bottom:1px solid #000;"&gt;&amp;nbsp&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
&lt;!-- matrix expression end --&gt;
This is really great we can get the &lt;b&gt;closed form&lt;/b&gt; for &lt;b&gt;F&lt;sub&gt;n&lt;/sub&gt;&lt;/b&gt;
by repeated substitution. In fact the following is the 
closed form for &lt;b&gt;F&lt;sub&gt;n&lt;/sub&gt;&lt;/b&gt; is as follows.
&lt;!-- matrix expression begin --&gt;
&lt;table style="color:#000"&gt;&lt;tr&gt;
&lt;td&gt;&lt;table border=0 cellpadding=0 cellspacing=0px style="border-left:1px solid #000; border-right:1px solid #000; color:#000"&gt;&lt;tr&gt;
&lt;td style ="border-top:1px solid #000; border-bottom:1px solid #000;"&gt;&amp;nbsp&lt;/td&gt;&lt;td&gt;&lt;table border=0 cellpadding=0 cellspacing=0 style="color:#000;"&gt;
&lt;tr&gt;
&lt;td align="center" valign="center" width=30&gt;F&lt;sub&gt;n&lt;/n&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align="center" valign="center" width=30&gt;F&lt;sub&gt;n-1&lt;/sub&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;&lt;/td&gt;&lt;td style ="border-top:1px solid #000; border-bottom:1px solid #000;"&gt;&amp;nbsp&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/td&gt;
&lt;td align="center" valign="center" width=30&gt;=&lt;/td&gt;
&lt;td&gt;&lt;table border=0 cellpadding=0 cellspacing=0px style="border-left:1px solid #000; border-right:1px solid #000; color:#000"&gt;&lt;tr&gt;
&lt;td style ="border-top:1px solid #000; border-bottom:1px solid #000;"&gt;&amp;nbsp&lt;/td&gt;&lt;td&gt;&lt;table border=0 cellpadding=0 cellspacing=0 style="color:#000;"&gt;
&lt;tr&gt;
&lt;td align="center" valign="center" width=30&gt;1&lt;/td&gt;
&lt;td align="center" valign="center" width=30&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align="center" valign="center" width=30&gt;1&lt;/td&gt;
&lt;td align="center" valign="center" width=30&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;&lt;/td&gt;&lt;td style ="border-top:1px solid #000; border-bottom:1px solid #000;"&gt;&amp;nbsp&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/td&gt;
&lt;td align="center" valign="center"&gt;&lt;table border=0 cellpadding=0 cellspacing=0px style="color:#000"&gt;
&lt;tr&gt;&lt;td&gt;&lt;sup&gt;n-1&lt;/sup&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&amp;nbsp&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&amp;nbsp&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;&lt;/td&gt;
&lt;td&gt;&lt;table border=0 cellpadding=0 cellspacing=0px style="border-left:1px solid #000; border-right:1px solid #000; color:#000"&gt;&lt;tr&gt;
&lt;td style ="border-top:1px solid #000; border-bottom:1px solid #000;"&gt;&amp;nbsp&lt;/td&gt;&lt;td&gt;&lt;table border=0 cellpadding=0 cellspacing=0 style="color:#000;"&gt;
&lt;tr&gt;
&lt;td align="center" valign="center" width=30&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align="center" valign="center" width=30&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;&lt;/td&gt;&lt;td style ="border-top:1px solid #000; border-bottom:1px solid #000;"&gt;&amp;nbsp&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;
&lt;!-- matrix expression end --&gt;
&lt;/p&gt;

&lt;p&gt;
So the problem of finding the &lt;b&gt;n&lt;sup&gt;th&lt;/sup&gt;&lt;/b&gt; Fibonacci number is reduces to 
evaluating &lt;b&gt;X&lt;sup&gt;n-1&lt;/sup&gt;&lt;/b&gt; where &lt;b&gt;X&lt;/b&gt; is a 2x2 matrix as shown above.
Now the question is how we can evaluate &lt;b&gt;X&lt;sup&gt;n-1&lt;/sup&gt;&lt;/b&gt; as efficiently as possible. In fact to compute any &lt;b&gt;a&lt;sup&gt;b&lt;/sup&gt;&lt;/b&gt; we need exactly &lt;b&gt;|&lt;sub&gt;_&lt;/sub&gt;log(n)&lt;sub&gt;_&lt;/sub&gt;|&lt;/b&gt; multiplications by making use of the
bit representation of &lt;b&gt;b = (2&lt;sup&gt;i&lt;sub&gt;1&lt;/sub&gt;&lt;/sup&gt; + 2&lt;sup&gt;i&lt;sub&gt;2&lt;/sub&gt;&lt;/sup&gt; ...)&lt;/b&gt; where &lt;b&gt;i&lt;sub&gt;j&lt;/sub&gt;&lt;/b&gt; are the positions of bits which have &lt;b&gt;1&lt;/b&gt; in 
the binary representation of &lt;b&gt;b&lt;/b&gt;. I used this trick to get a &lt;b&gt;O(log(n))&lt;/b&gt;
time and &lt;b&gt;O(1)&lt;/b&gt; time algorithm to compute the &lt;b&gt;n&lt;sup&gt;th&lt;/sup&gt;&lt;/b&gt; Fibonacci number. Please see the code below get this &lt;a href="http://trinity.engr.uconn.edu/~vamsik/LogFibonacci.c"&gt;here&lt;/a&gt;  
&lt;/p&gt;
&lt;pre&gt;&lt;span style='color: Teal; background-color: '&gt;  1&lt;/span&gt; &lt;span style=' color: Green;'&gt;/*Find the n^th fibonacci number in O(log(n)) 
&lt;span style='color: Teal; background-color: '&gt;  2&lt;/span&gt;  *time, using the following idea of matrix formulation 
&lt;span style='color: Teal; background-color: '&gt;  3&lt;/span&gt;  * 
&lt;span style='color: Teal; background-color: '&gt;  4&lt;/span&gt;  * [   F_n  ]    [ 1      1  ] [F_{n-1}]
&lt;span style='color: Teal; background-color: '&gt;  5&lt;/span&gt;  * [        ] = [         ] [       ]
&lt;span style='color: Teal; background-color: '&gt;  6&lt;/span&gt;  * [ F_{n-1}]    [ 1      0  ] [F_{n-2}]
&lt;span style='color: Teal; background-color: '&gt;  7&lt;/span&gt;  *
&lt;span style='color: Teal; background-color: '&gt;  8&lt;/span&gt;  * vamsik(at)engr(dot)uconn July 11, 2008
&lt;span style='color: Teal; background-color: '&gt;  9&lt;/span&gt;  */&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt; 10&lt;/span&gt; #&lt;span style=' color: Blue;'&gt;include&lt;/span&gt;&amp;lt;stdio.h&amp;gt;
&lt;span style='color: Teal; background-color: '&gt; 11&lt;/span&gt; #&lt;span style=' color: Blue;'&gt;include&lt;/span&gt;&amp;lt;stdlib.h&amp;gt;
&lt;span style='color: Teal; background-color: '&gt; 12&lt;/span&gt; &lt;span style=' color: Green;'&gt;/*Fib returns the n^th Fibonacci number*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt; 13&lt;/span&gt; &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; Fib(&lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; n){
&lt;span style='color: Teal; background-color: '&gt; 14&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; deg=&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;
&lt;span style='color: Teal; background-color: '&gt; 15&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; fib[&lt;span style=' color: Maroon;'&gt;2&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;2&lt;/span&gt;] = {{&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;,&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;},{&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;,&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;}};
&lt;span style='color: Teal; background-color: '&gt; 16&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; fibAns[&lt;span style=' color: Maroon;'&gt;2&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;2&lt;/span&gt;];
&lt;span style='color: Teal; background-color: '&gt; 17&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;char&lt;/span&gt; initAns=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;
&lt;span style='color: Teal; background-color: '&gt; 18&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; mul[&lt;span style=' color: Maroon;'&gt;4&lt;/span&gt;];
&lt;span style='color: Teal; background-color: '&gt; 19&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(n&amp;lt;=&lt;span style=' color: Maroon;'&gt;2&lt;/span&gt;){ &lt;span style=' color: Blue;'&gt;return&lt;/span&gt; (n&amp;lt;&lt;span style=' color: Maroon;'&gt;2&lt;/span&gt;)?n:&lt;span style=' color: Maroon;'&gt;2&lt;/span&gt;;}
&lt;span style='color: Teal; background-color: '&gt; 20&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;while&lt;/span&gt;(deg &amp;lt; n-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;){
&lt;span style='color: Teal; background-color: '&gt; 21&lt;/span&gt;          mul[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;] = fib[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;]*fib[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;] + fib[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;]*fib[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;];
&lt;span style='color: Teal; background-color: '&gt; 22&lt;/span&gt;          mul[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;] = fib[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;]*fib[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;] + fib[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;]*fib[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;];
&lt;span style='color: Teal; background-color: '&gt; 23&lt;/span&gt;          mul[&lt;span style=' color: Maroon;'&gt;2&lt;/span&gt;] = fib[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;]*fib[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;] + fib[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;]*fib[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;];
&lt;span style='color: Teal; background-color: '&gt; 24&lt;/span&gt;          mul[&lt;span style=' color: Maroon;'&gt;3&lt;/span&gt;] = fib[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;]*fib[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;] + fib[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;]*fib[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;];
&lt;span style='color: Teal; background-color: '&gt; 25&lt;/span&gt;          fib[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;] = mul[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;]; fib[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;] = mul[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;]; 
&lt;span style='color: Teal; background-color: '&gt; 26&lt;/span&gt;          fib[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;] = mul[&lt;span style=' color: Maroon;'&gt;2&lt;/span&gt;]; fib[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;] = mul[&lt;span style=' color: Maroon;'&gt;3&lt;/span&gt;];
&lt;span style='color: Teal; background-color: '&gt; 27&lt;/span&gt;          deg &amp;lt;&amp;lt;=&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;
&lt;span style='color: Teal; background-color: '&gt; 28&lt;/span&gt;          &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(deg &amp;amp; n-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;){ &lt;span style=' color: Green;'&gt;/*i^th bit set*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt; 29&lt;/span&gt;              &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(!initAns){
&lt;span style='color: Teal; background-color: '&gt; 30&lt;/span&gt;                  fibAns[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;] = fib[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;]; fibAns[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;] = fib[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;]; 
&lt;span style='color: Teal; background-color: '&gt; 31&lt;/span&gt;                  fibAns[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;] = fib[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;]; fibAns[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;] = fib[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;];
&lt;span style='color: Teal; background-color: '&gt; 32&lt;/span&gt;                 initAns=&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;
&lt;span style='color: Teal; background-color: '&gt; 33&lt;/span&gt;              }&lt;span style=' color: Blue;'&gt;else&lt;/span&gt;{
&lt;span style='color: Teal; background-color: '&gt; 34&lt;/span&gt;                  mul[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;] = fibAns[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;]*fib[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;] + fibAns[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;]*fib[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;];
&lt;span style='color: Teal; background-color: '&gt; 35&lt;/span&gt;                  mul[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;] = fibAns[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;]*fib[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;] + fibAns[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;]*fib[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;];
&lt;span style='color: Teal; background-color: '&gt; 36&lt;/span&gt;                  mul[&lt;span style=' color: Maroon;'&gt;2&lt;/span&gt;] = fibAns[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;]*fib[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;] + fibAns[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;]*fib[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;];
&lt;span style='color: Teal; background-color: '&gt; 37&lt;/span&gt;                  mul[&lt;span style=' color: Maroon;'&gt;3&lt;/span&gt;] = fibAns[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;]*fib[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;] + fibAns[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;]*fib[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;];
&lt;span style='color: Teal; background-color: '&gt; 38&lt;/span&gt;                  fibAns[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;] = mul[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;]; fibAns[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;] = mul[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;]; 
&lt;span style='color: Teal; background-color: '&gt; 39&lt;/span&gt;                  fibAns[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;] = mul[&lt;span style=' color: Maroon;'&gt;2&lt;/span&gt;]; fibAns[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;] = mul[&lt;span style=' color: Maroon;'&gt;3&lt;/span&gt;];
&lt;span style='color: Teal; background-color: '&gt; 40&lt;/span&gt;              }
&lt;span style='color: Teal; background-color: '&gt; 41&lt;/span&gt;          }
&lt;span style='color: Teal; background-color: '&gt; 42&lt;/span&gt;     }
&lt;span style='color: Teal; background-color: '&gt; 43&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(n-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt; &amp;amp; &lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;){
&lt;span style='color: Teal; background-color: '&gt; 44&lt;/span&gt;         &lt;span style=' color: Blue;'&gt;return&lt;/span&gt; fibAns[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;] + fibAns[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;];
&lt;span style='color: Teal; background-color: '&gt; 45&lt;/span&gt;     }
&lt;span style='color: Teal; background-color: '&gt; 46&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;return&lt;/span&gt; fibAns[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;];
&lt;span style='color: Teal; background-color: '&gt; 47&lt;/span&gt; }
&lt;span style='color: Teal; background-color: '&gt; 48&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; main(&lt;span style=' color: Blue;'&gt;int&lt;/span&gt; argc,&lt;span style=' color: Blue;'&gt;char&lt;/span&gt; **argv){
&lt;span style='color: Teal; background-color: '&gt; 49&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; n;
&lt;span style='color: Teal; background-color: '&gt; 50&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;while&lt;/span&gt;(&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;){
&lt;span style='color: Teal; background-color: '&gt; 51&lt;/span&gt;         scanf(&lt;span style=' color: Maroon;'&gt;"%u"&lt;/span&gt;,&amp;amp;n);
&lt;span style='color: Teal; background-color: '&gt; 52&lt;/span&gt;         &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(!n){
&lt;span style='color: Teal; background-color: '&gt; 53&lt;/span&gt;             exit(&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;);
&lt;span style='color: Teal; background-color: '&gt; 54&lt;/span&gt;         }
&lt;span style='color: Teal; background-color: '&gt; 55&lt;/span&gt;         printf(&lt;span style=' color: Maroon;'&gt;"%u\n"&lt;/span&gt;,n,Fib(n));
&lt;span style='color: Teal; background-color: '&gt; 56&lt;/span&gt;     }
&lt;span style='color: Teal; background-color: '&gt; 57&lt;/span&gt; }
&lt;span style='color: Teal; background-color: '&gt; 58&lt;/span&gt; &lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-9054680951916325923?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/9054680951916325923/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=9054680951916325923&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/9054680951916325923'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/9054680951916325923'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2008/07/tech-ologn-time-and-o1-space-algorithm.html' title='[TECH] A O(log(n)) time and O(1) space algorithm to find out Nth Fibonacci number.'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-9200973434598324398</id><published>2008-07-08T09:45:00.000-07:00</published><updated>2008-07-08T10:00:56.564-07:00</updated><title type='text'>[TECH] Illustration of how to use the BFS based subset enumeration algorithmic framework to solve TSP.</title><content type='html'>&lt;p&gt; In the previous post I posted on the idea of using BFS to enumerate the
subsets incrementally based on the size (see the previous post). The power of
this core framework is so immense let me show how we can implement the TSP based on
the framework. The extra code is between the lines 82-90 (TSP Initialization) and 113-175. The same core can be easily adapted to solve several sub-set based Dynamic programming optimizations like the job-scheduling, vehicle routing problem (VRP). If you have not looked into one of the &lt;a href="http://code.google.com/codejam/"&gt;Google Code Jam 2008 (practice) problems&lt;/a&gt; the problem#4 which is a shopping problem can be easily solved by this core framework. Check this code &lt;a href="http://trinity.engr.uconn.edu/~vamsik/TSP.C"&gt;TSP.C&lt;/a&gt; (use -std=c99 to compile).
&lt;/p&gt;

&lt;pre&gt;&lt;span style='color: Teal; background-color: '&gt;  1&lt;/span&gt; &lt;span style=' color: Green;'&gt;/*******************************
&lt;span style='color: Teal; background-color: '&gt;  2&lt;/span&gt;  * Subset Enumeration Algorithmic 
&lt;span style='color: Teal; background-color: '&gt;  3&lt;/span&gt;  * Framework and its illustration in 
&lt;span style='color: Teal; background-color: '&gt;  4&lt;/span&gt;  * finding TSP. 
&lt;span style='color: Teal; background-color: '&gt;  5&lt;/span&gt;  ******************************/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;  6&lt;/span&gt; #&lt;span style=' color: Blue;'&gt;include&lt;/span&gt;&amp;lt;stdio.h&amp;gt;
&lt;span style='color: Teal; background-color: '&gt;  7&lt;/span&gt; #&lt;span style=' color: Blue;'&gt;include&lt;/span&gt;&amp;lt;stdlib.h&amp;gt;
&lt;span style='color: Teal; background-color: '&gt;  8&lt;/span&gt; #&lt;span style=' color: Blue;'&gt;include&lt;/span&gt;&amp;lt;&lt;span style=' color: Blue;'&gt;string&lt;/span&gt;.h&amp;gt;
&lt;span style='color: Teal; background-color: '&gt;  9&lt;/span&gt; #&lt;span style=' color: Blue;'&gt;include&lt;/span&gt;&amp;lt;assert.h&amp;gt;
&lt;span style='color: Teal; background-color: '&gt; 10&lt;/span&gt; #&lt;span style=' color: Blue;'&gt;include&lt;/span&gt;&amp;lt;math.h&amp;gt;
&lt;span style='color: Teal; background-color: '&gt; 11&lt;/span&gt; #&lt;span style=' color: Blue;'&gt;include&lt;/span&gt; &lt;span style=' color: Maroon;'&gt;"List.h"&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt; 12&lt;/span&gt; &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; **GRAPH;
&lt;span style='color: Teal; background-color: '&gt; 13&lt;/span&gt; &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; subset_count=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;
&lt;span style='color: Teal; background-color: '&gt; 14&lt;/span&gt; &lt;span style=' color: Green;'&gt;//#define VERBOSE_MODE 1&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt; 15&lt;/span&gt; &lt;span style=' color: Blue;'&gt;void&lt;/span&gt; EnumSubSetsBFS(&lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; n);
&lt;span style='color: Teal; background-color: '&gt; 16&lt;/span&gt; 
&lt;span style='color: Teal; background-color: '&gt; 17&lt;/span&gt; &lt;span style=' color: Blue;'&gt;void&lt;/span&gt; CreateGraph(&lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; *n){
&lt;span style='color: Teal; background-color: '&gt; 18&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; i,j;
&lt;span style='color: Teal; background-color: '&gt; 19&lt;/span&gt;     printf(&lt;span style=' color: Maroon;'&gt;"Enter the Graph Size\n"&lt;/span&gt;);
&lt;span style='color: Teal; background-color: '&gt; 20&lt;/span&gt;     scanf(&lt;span style=' color: Maroon;'&gt;"%u"&lt;/span&gt;,n);
&lt;span style='color: Teal; background-color: '&gt; 21&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(*n&amp;gt;&lt;span style=' color: Maroon;'&gt;32&lt;/span&gt;){
&lt;span style='color: Teal; background-color: '&gt; 22&lt;/span&gt;         fprintf(stderr,&lt;span style=' color: Maroon;'&gt;"TODO: The Bitset currently supports only 32 bits\n"&lt;/span&gt;);
&lt;span style='color: Teal; background-color: '&gt; 23&lt;/span&gt;         exit(&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;);
&lt;span style='color: Teal; background-color: '&gt; 24&lt;/span&gt;     }
&lt;span style='color: Teal; background-color: '&gt; 25&lt;/span&gt;     printf(&lt;span style=' color: Maroon;'&gt;"Enter the weighted graph\n"&lt;/span&gt;);
&lt;span style='color: Teal; background-color: '&gt; 26&lt;/span&gt;     GRAPH = (&lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; **) malloc(&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(&lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; *)*(*n));
&lt;span style='color: Teal; background-color: '&gt; 27&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(i=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;i&amp;lt;*n;i++){
&lt;span style='color: Teal; background-color: '&gt; 28&lt;/span&gt;         GRAPH[i] = (&lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; *) malloc(&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(&lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt;)*(*n));
&lt;span style='color: Teal; background-color: '&gt; 29&lt;/span&gt;         &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(j=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;j&amp;lt;*n;j++){
&lt;span style='color: Teal; background-color: '&gt; 30&lt;/span&gt;             scanf(&lt;span style=' color: Maroon;'&gt;"%u"&lt;/span&gt;,&amp;amp;(GRAPH[i][j]));
&lt;span style='color: Teal; background-color: '&gt; 31&lt;/span&gt;         }
&lt;span style='color: Teal; background-color: '&gt; 32&lt;/span&gt;     }
&lt;span style='color: Teal; background-color: '&gt; 33&lt;/span&gt; }
&lt;span style='color: Teal; background-color: '&gt; 34&lt;/span&gt; 
&lt;span style='color: Teal; background-color: '&gt; 35&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; main(){
&lt;span style='color: Teal; background-color: '&gt; 36&lt;/span&gt;     &lt;span style=' color: Green;'&gt;/*Create the Graph*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt; 37&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; n;
&lt;span style='color: Teal; background-color: '&gt; 38&lt;/span&gt;     CreateGraph(&amp;amp;n);
&lt;span style='color: Teal; background-color: '&gt; 39&lt;/span&gt;     EnumSubSetsBFS(n);
&lt;span style='color: Teal; background-color: '&gt; 40&lt;/span&gt; 
&lt;span style='color: Teal; background-color: '&gt; 41&lt;/span&gt; }
&lt;span style='color: Teal; background-color: '&gt; 42&lt;/span&gt; &lt;span style=' color: Green;'&gt;/*Returns the new tail of the list*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt; 43&lt;/span&gt; &lt;span style=' color: Blue;'&gt;inline&lt;/span&gt; List* ListAppend(List **tail,&lt;span style=' color: Blue;'&gt;void&lt;/span&gt; *_data){
&lt;span style='color: Teal; background-color: '&gt; 44&lt;/span&gt;     List *new_node = (List *)malloc(&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(new_node)*&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;);
&lt;span style='color: Teal; background-color: '&gt; 45&lt;/span&gt;     assert(new_node);
&lt;span style='color: Teal; background-color: '&gt; 46&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(!(*tail)){
&lt;span style='color: Teal; background-color: '&gt; 47&lt;/span&gt;         (*tail) = new_node;
&lt;span style='color: Teal; background-color: '&gt; 48&lt;/span&gt;         (*tail)-&amp;gt;_data = _data;
&lt;span style='color: Teal; background-color: '&gt; 49&lt;/span&gt;         (*tail)-&amp;gt;next = &lt;span style=' color: Blue;'&gt;NULL&lt;/span&gt;;
&lt;span style='color: Teal; background-color: '&gt; 50&lt;/span&gt;         &lt;span style=' color: Blue;'&gt;return&lt;/span&gt; *tail;
&lt;span style='color: Teal; background-color: '&gt; 51&lt;/span&gt;     }
&lt;span style='color: Teal; background-color: '&gt; 52&lt;/span&gt;     new_node-&amp;gt;_data = _data;
&lt;span style='color: Teal; background-color: '&gt; 53&lt;/span&gt;     new_node-&amp;gt;next = &lt;span style=' color: Blue;'&gt;NULL&lt;/span&gt;;
&lt;span style='color: Teal; background-color: '&gt; 54&lt;/span&gt;     (*tail)-&amp;gt;next = new_node;
&lt;span style='color: Teal; background-color: '&gt; 55&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;return&lt;/span&gt; new_node;
&lt;span style='color: Teal; background-color: '&gt; 56&lt;/span&gt; }
&lt;span style='color: Teal; background-color: '&gt; 57&lt;/span&gt; &lt;span style=' color: Blue;'&gt;typedef&lt;/span&gt; &lt;span style=' color: Blue;'&gt;struct&lt;/span&gt; _subset_{
&lt;span style='color: Teal; background-color: '&gt; 58&lt;/span&gt;     &lt;span style=' color: Green;'&gt;/*if i^th bit is set then subset has i^th
&lt;span style='color: Teal; background-color: '&gt; 59&lt;/span&gt;      *element*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt; 60&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; ebits;
&lt;span style='color: Teal; background-color: '&gt; 61&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; max; &lt;span style=' color: Green;'&gt;/*Maximum element in the subset*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt; 62&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; size; &lt;span style=' color: Green;'&gt;/*Size of subset*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt; 63&lt;/span&gt;     &lt;span style=' color: Green;'&gt;/*Pointer to the sub-problem */&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt; 64&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;void&lt;/span&gt; *sub_problem;
&lt;span style='color: Teal; background-color: '&gt; 65&lt;/span&gt; }SubSet;
&lt;span style='color: Teal; background-color: '&gt; 66&lt;/span&gt; &lt;span style=' color: Green;'&gt;/*Enumerate the Subset using BFS, n is 
&lt;span style='color: Teal; background-color: '&gt; 67&lt;/span&gt;  *the set size [1,2...n] */&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt; 68&lt;/span&gt; &lt;span style=' color: Blue;'&gt;void&lt;/span&gt; EnumSubSetsBFS(&lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; n){
&lt;span style='color: Teal; background-color: '&gt; 69&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; check_sub_set,k,i,j;
&lt;span style='color: Teal; background-color: '&gt; 70&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; current_level = &lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;
&lt;span style='color: Teal; background-color: '&gt; 71&lt;/span&gt;     List *bfs_list = &lt;span style=' color: Blue;'&gt;NULL&lt;/span&gt;;
&lt;span style='color: Teal; background-color: '&gt; 72&lt;/span&gt;     List *tail = &lt;span style=' color: Blue;'&gt;NULL&lt;/span&gt;; List *free_node,*ptr;
&lt;span style='color: Teal; background-color: '&gt; 73&lt;/span&gt;     SubSet *sub_set,*new_sub_set;
&lt;span style='color: Teal; background-color: '&gt; 74&lt;/span&gt;     SubSet *one_sets = &lt;span style=' color: Blue;'&gt;NULL&lt;/span&gt;;
&lt;span style='color: Teal; background-color: '&gt; 75&lt;/span&gt; 
&lt;span style='color: Teal; background-color: '&gt; 76&lt;/span&gt;     one_sets = (SubSet *)malloc(&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(SubSet)*n); 
&lt;span style='color: Teal; background-color: '&gt; 77&lt;/span&gt;     assert(one_sets);
&lt;span style='color: Teal; background-color: '&gt; 78&lt;/span&gt;     &lt;span style=' color: Green;'&gt;/*Add the 1-subsets*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt; 79&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(i=&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;i&amp;lt;n;i++){
&lt;span style='color: Teal; background-color: '&gt; 80&lt;/span&gt;         one_sets[i].ebits = &lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;; one_sets[i].ebits |= (&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;&amp;lt;&amp;lt;i);
&lt;span style='color: Teal; background-color: '&gt; 81&lt;/span&gt;         one_sets[i].max = i; one_sets[i].size = &lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;
&lt;span style='color: Teal; background-color: '&gt; 82&lt;/span&gt;         &lt;span style=' color: Green;'&gt;/****SUBPROBLEM SPECIFIC*****/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt; 83&lt;/span&gt;         one_sets[i].sub_problem = (&lt;span style=' color: Blue;'&gt;float&lt;/span&gt; *)malloc(&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(&lt;span style=' color: Blue;'&gt;float&lt;/span&gt;)*n);
&lt;span style='color: Teal; background-color: '&gt; 84&lt;/span&gt;         &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(j=&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;j&amp;lt;n;j++){
&lt;span style='color: Teal; background-color: '&gt; 85&lt;/span&gt;             &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(i==j){ &lt;span style=' color: Blue;'&gt;continue&lt;/span&gt;; }
&lt;span style='color: Teal; background-color: '&gt; 86&lt;/span&gt;             &lt;span style=' color: Green;'&gt;/* TSP({i},j) */&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt; 87&lt;/span&gt;             ((&lt;span style=' color: Blue;'&gt;float&lt;/span&gt; *)one_sets[i].sub_problem)[j] = GRAPH[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][i]+GRAPH[i][j];
&lt;span style='color: Teal; background-color: '&gt; 88&lt;/span&gt;             printf(&lt;span style=' color: Maroon;'&gt;"S({%u},%u) = %f\n"&lt;/span&gt;,i+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;,j+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;,((&lt;span style=' color: Blue;'&gt;float&lt;/span&gt; *)one_sets[i].sub_problem)[j]);
&lt;span style='color: Teal; background-color: '&gt; 89&lt;/span&gt;         }
&lt;span style='color: Teal; background-color: '&gt; 90&lt;/span&gt;         &lt;span style=' color: Green;'&gt;/*****************************/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt; 91&lt;/span&gt;         &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(!tail){
&lt;span style='color: Teal; background-color: '&gt; 92&lt;/span&gt;             ListAppend(&amp;amp;bfs_list,(&lt;span style=' color: Blue;'&gt;void&lt;/span&gt; *)&amp;amp;(one_sets[i]));
&lt;span style='color: Teal; background-color: '&gt; 93&lt;/span&gt;             tail = bfs_list;
&lt;span style='color: Teal; background-color: '&gt; 94&lt;/span&gt;             &lt;span style=' color: Blue;'&gt;continue&lt;/span&gt;;
&lt;span style='color: Teal; background-color: '&gt; 95&lt;/span&gt;         }
&lt;span style='color: Teal; background-color: '&gt; 96&lt;/span&gt;         tail = ListAppend(&amp;amp;tail,(&lt;span style=' color: Blue;'&gt;void&lt;/span&gt; *)&amp;amp;(one_sets[i]));
&lt;span style='color: Teal; background-color: '&gt; 97&lt;/span&gt;     }
&lt;span style='color: Teal; background-color: '&gt; 98&lt;/span&gt;     &lt;span style=' color: Green;'&gt;/*Now do the BFS*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt; 99&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;while&lt;/span&gt;(bfs_list){
&lt;span style='color: Teal; background-color: '&gt;100&lt;/span&gt;         sub_set = (SubSet *)bfs_list-&amp;gt;_data; 
&lt;span style='color: Teal; background-color: '&gt;101&lt;/span&gt;         free_node = bfs_list;
&lt;span style='color: Teal; background-color: '&gt;102&lt;/span&gt;         bfs_list=bfs_list-&amp;gt;next;
&lt;span style='color: Teal; background-color: '&gt;103&lt;/span&gt;         subset_count++;
&lt;span style='color: Teal; background-color: '&gt;104&lt;/span&gt;         assert(sub_set-&amp;gt;max &amp;lt; n);
&lt;span style='color: Teal; background-color: '&gt;105&lt;/span&gt;         &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(i=((sub_set-&amp;gt;max)+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;);i&amp;lt;n;i++){
&lt;span style='color: Teal; background-color: '&gt;106&lt;/span&gt;             new_sub_set = (SubSet *) malloc(&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(SubSet)*&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;);
&lt;span style='color: Teal; background-color: '&gt;107&lt;/span&gt;             new_sub_set-&amp;gt;size = (sub_set-&amp;gt;size)+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;
&lt;span style='color: Teal; background-color: '&gt;108&lt;/span&gt;             new_sub_set-&amp;gt;max = i;
&lt;span style='color: Teal; background-color: '&gt;109&lt;/span&gt;             new_sub_set-&amp;gt;ebits = (sub_set-&amp;gt;ebits | (&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;&amp;lt;&amp;lt;i));
&lt;span style='color: Teal; background-color: '&gt;110&lt;/span&gt;             
&lt;span style='color: Teal; background-color: '&gt;111&lt;/span&gt;             
&lt;span style='color: Teal; background-color: '&gt;112&lt;/span&gt;             
&lt;span style='color: Teal; background-color: '&gt;113&lt;/span&gt;             &lt;span style=' color: Green;'&gt;/*****&amp;lt;begin&amp;gt;**SUBPROBLEM SPECIFIC******/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;114&lt;/span&gt;             &lt;span style=' color: Green;'&gt;/* S(X,j) = min_k {S(X-k,k) + d[k][j]}*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;115&lt;/span&gt;             ptr = free_node;
&lt;span style='color: Teal; background-color: '&gt;116&lt;/span&gt;             &lt;span style=' color: Blue;'&gt;float&lt;/span&gt; current_min = HUGE_VAL;
&lt;span style='color: Teal; background-color: '&gt;117&lt;/span&gt;             &lt;span style=' color: Blue;'&gt;float&lt;/span&gt; *new_sub_problem;
&lt;span style='color: Teal; background-color: '&gt;118&lt;/span&gt;             &lt;span style=' color: Blue;'&gt;float&lt;/span&gt; *sub_problem; &lt;span style=' color: Blue;'&gt;float&lt;/span&gt; local_min;
&lt;span style='color: Teal; background-color: '&gt;119&lt;/span&gt;             &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; k1,jstart,jend;
&lt;span style='color: Teal; background-color: '&gt;120&lt;/span&gt;             List *ptr_prev;
&lt;span style='color: Teal; background-color: '&gt;121&lt;/span&gt;             
&lt;span style='color: Teal; background-color: '&gt;122&lt;/span&gt;             new_sub_set-&amp;gt;sub_problem = (&lt;span style=' color: Blue;'&gt;float&lt;/span&gt; *) malloc(&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(&lt;span style=' color: Blue;'&gt;float&lt;/span&gt;)*n);
&lt;span style='color: Teal; background-color: '&gt;123&lt;/span&gt;             new_sub_problem = (&lt;span style=' color: Blue;'&gt;float&lt;/span&gt; *)new_sub_set-&amp;gt;sub_problem;
&lt;span style='color: Teal; background-color: '&gt;124&lt;/span&gt; 
&lt;span style='color: Teal; background-color: '&gt;125&lt;/span&gt;             &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(new_sub_set-&amp;gt;size == n-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;){
&lt;span style='color: Teal; background-color: '&gt;126&lt;/span&gt;                 jstart = &lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;; jend = &lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;
&lt;span style='color: Teal; background-color: '&gt;127&lt;/span&gt;             }&lt;span style=' color: Blue;'&gt;else&lt;/span&gt;{
&lt;span style='color: Teal; background-color: '&gt;128&lt;/span&gt;                 jstart = &lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;; jend = n;
&lt;span style='color: Teal; background-color: '&gt;129&lt;/span&gt;             }
&lt;span style='color: Teal; background-color: '&gt;130&lt;/span&gt; 
&lt;span style='color: Teal; background-color: '&gt;131&lt;/span&gt;             &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(j=jstart;j&amp;lt;jend;j++){
&lt;span style='color: Teal; background-color: '&gt;132&lt;/span&gt;                 ptr = free_node;
&lt;span style='color: Teal; background-color: '&gt;133&lt;/span&gt;                 current_min = HUGE_VAL;
&lt;span style='color: Teal; background-color: '&gt;134&lt;/span&gt;                 &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(new_sub_set-&amp;gt;ebits &amp;amp; (&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;&amp;lt;&amp;lt;j)){
&lt;span style='color: Teal; background-color: '&gt;135&lt;/span&gt;                     &lt;span style=' color: Green;'&gt;/*Avoid computation of redundant subproblems like
&lt;span style='color: Teal; background-color: '&gt;136&lt;/span&gt;                      *S({....,x_i,x_j,x_k,....},x_i) */&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;137&lt;/span&gt;                     new_sub_problem[j]=HUGE_VAL;
&lt;span style='color: Teal; background-color: '&gt;138&lt;/span&gt;                     &lt;span style=' color: Blue;'&gt;continue&lt;/span&gt;;
&lt;span style='color: Teal; background-color: '&gt;139&lt;/span&gt;                 }
&lt;span style='color: Teal; background-color: '&gt;140&lt;/span&gt; 
&lt;span style='color: Teal; background-color: '&gt;141&lt;/span&gt;                 &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(k=&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;k&amp;lt;=new_sub_set-&amp;gt;size;k++){
&lt;span style='color: Teal; background-color: '&gt;142&lt;/span&gt;                     &lt;span style=' color: Blue;'&gt;do&lt;/span&gt;{
&lt;span style='color: Teal; background-color: '&gt;143&lt;/span&gt;                         check_sub_set = ((SubSet *)ptr-&amp;gt;_data)-&amp;gt;ebits; 
&lt;span style='color: Teal; background-color: '&gt;144&lt;/span&gt;                         check_sub_set ^= new_sub_set-&amp;gt;ebits; 
&lt;span style='color: Teal; background-color: '&gt;145&lt;/span&gt;                         k1 = (&lt;span style=' color: Blue;'&gt;int&lt;/span&gt;)log2(check_sub_set);
&lt;span style='color: Teal; background-color: '&gt;146&lt;/span&gt;                         ptr_prev = ptr;
&lt;span style='color: Teal; background-color: '&gt;147&lt;/span&gt;                         ptr=ptr-&amp;gt;next;
&lt;span style='color: Teal; background-color: '&gt;148&lt;/span&gt;                     }&lt;span style=' color: Blue;'&gt;while&lt;/span&gt;(check_sub_set &amp;amp; (check_sub_set-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;));
&lt;span style='color: Teal; background-color: '&gt;149&lt;/span&gt;                     sub_problem = (&lt;span style=' color: Blue;'&gt;float&lt;/span&gt; *)((SubSet *)ptr_prev-&amp;gt;_data)-&amp;gt;sub_problem;
&lt;span style='color: Teal; background-color: '&gt;150&lt;/span&gt;                     local_min = sub_problem[k1] + GRAPH[k1][j];
&lt;span style='color: Teal; background-color: '&gt;151&lt;/span&gt; 
&lt;span style='color: Teal; background-color: '&gt;152&lt;/span&gt;                     &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(local_min &amp;lt; current_min){
&lt;span style='color: Teal; background-color: '&gt;153&lt;/span&gt;                         current_min = local_min; 
&lt;span style='color: Teal; background-color: '&gt;154&lt;/span&gt;                         new_sub_problem[j] = current_min;
&lt;span style='color: Teal; background-color: '&gt;155&lt;/span&gt;                     }
&lt;span style='color: Teal; background-color: '&gt;156&lt;/span&gt; 
&lt;span style='color: Teal; background-color: '&gt;157&lt;/span&gt;                 }
&lt;span style='color: Teal; background-color: '&gt;158&lt;/span&gt;             }
&lt;span style='color: Teal; background-color: '&gt;159&lt;/span&gt;             &lt;span style=' color: Green;'&gt;/*Print Solution to the Subproblem */&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;160&lt;/span&gt;             &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; i1,istart,iend;
&lt;span style='color: Teal; background-color: '&gt;161&lt;/span&gt;             &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; j1;
&lt;span style='color: Teal; background-color: '&gt;162&lt;/span&gt;             
&lt;span style='color: Teal; background-color: '&gt;163&lt;/span&gt;             &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(i1=jstart;i1&amp;lt;jend;i1++){
&lt;span style='color: Teal; background-color: '&gt;164&lt;/span&gt;                 check_sub_set = new_sub_set-&amp;gt;ebits;
&lt;span style='color: Teal; background-color: '&gt;165&lt;/span&gt;                 &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(check_sub_set &amp;amp; (&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;&amp;lt;&amp;lt;i1)){ &lt;span style=' color: Blue;'&gt;continue&lt;/span&gt;; }
&lt;span style='color: Teal; background-color: '&gt;166&lt;/span&gt;                 printf(&lt;span style=' color: Maroon;'&gt;"S(%u,{ "&lt;/span&gt;,i1+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;);
&lt;span style='color: Teal; background-color: '&gt;167&lt;/span&gt;                 &lt;span style=' color: Green;'&gt;/*Get the elements back*/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;168&lt;/span&gt;                 &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(j1=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;j1&amp;lt;n;j1++){
&lt;span style='color: Teal; background-color: '&gt;169&lt;/span&gt;                     &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(check_sub_set &amp;amp; (&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;&amp;lt;&amp;lt;j1)){
&lt;span style='color: Teal; background-color: '&gt;170&lt;/span&gt;                         printf(&lt;span style=' color: Maroon;'&gt;" %u "&lt;/span&gt;,j1+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;);
&lt;span style='color: Teal; background-color: '&gt;171&lt;/span&gt;                     }
&lt;span style='color: Teal; background-color: '&gt;172&lt;/span&gt;                 }
&lt;span style='color: Teal; background-color: '&gt;173&lt;/span&gt;                 printf(&lt;span style=' color: Maroon;'&gt;"})=%f\n"&lt;/span&gt;,((&lt;span style=' color: Blue;'&gt;float&lt;/span&gt; *)(new_sub_set-&amp;gt;sub_problem))[i1]);
&lt;span style='color: Teal; background-color: '&gt;174&lt;/span&gt;             }
&lt;span style='color: Teal; background-color: '&gt;175&lt;/span&gt;             &lt;span style=' color: Green;'&gt;/**********&amp;lt;END&amp;gt;***SUBPROBLEM SPECIFIC*************/&lt;/span&gt;
&lt;span style='color: Teal; background-color: '&gt;176&lt;/span&gt; 
&lt;span style='color: Teal; background-color: '&gt;177&lt;/span&gt; 
&lt;span style='color: Teal; background-color: '&gt;178&lt;/span&gt;             tail = ListAppend(&amp;amp;tail,(&lt;span style=' color: Blue;'&gt;void&lt;/span&gt; *)new_sub_set);
&lt;span style='color: Teal; background-color: '&gt;179&lt;/span&gt;         }
&lt;span style='color: Teal; background-color: '&gt;180&lt;/span&gt;         &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(!(sub_set &amp;gt;= one_sets &amp;amp;&amp;amp; sub_set &amp;lt;= &amp;amp;(one_sets[n-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;]))){
&lt;span style='color: Teal; background-color: '&gt;181&lt;/span&gt;             free(sub_set-&amp;gt;sub_problem);
&lt;span style='color: Teal; background-color: '&gt;182&lt;/span&gt;             free(sub_set); 
&lt;span style='color: Teal; background-color: '&gt;183&lt;/span&gt;         }
&lt;span style='color: Teal; background-color: '&gt;184&lt;/span&gt;         free(free_node);
&lt;span style='color: Teal; background-color: '&gt;185&lt;/span&gt;     }
&lt;span style='color: Teal; background-color: '&gt;186&lt;/span&gt;     &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(i=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;i&amp;lt;n;i++){
&lt;span style='color: Teal; background-color: '&gt;187&lt;/span&gt;         free(one_sets[i].sub_problem);
&lt;span style='color: Teal; background-color: '&gt;188&lt;/span&gt;     }
&lt;span style='color: Teal; background-color: '&gt;189&lt;/span&gt;     free(one_sets);
&lt;span style='color: Teal; background-color: '&gt;190&lt;/span&gt;     printf(&lt;span style=' color: Maroon;'&gt;"SubsetCount=%u\n"&lt;/span&gt;,subset_count);
&lt;span style='color: Teal; background-color: '&gt;191&lt;/span&gt; }
&lt;span style='color: Teal; background-color: '&gt;192&lt;/span&gt; &lt;/pre&gt;

&lt;pre&gt;
Sample Input.
---------test5.txt----------
5
0 3 1 5 4 
1 0 5 4 3 
5 4 0 2 1 
3 1 3 0 3 
5 2 4 1 0
---------------------
[vamsik@abadon ~]$ ./a.out &lt; test5.txt 
Enter the Graph Size
Enter the weighted graph
S({2},3) = 8.000000
S({2},4) = 7.000000
S({2},5) = 6.000000
S({3},2) = 5.000000
S({3},4) = 3.000000
S({3},5) = 2.000000
S({4},2) = 6.000000
S({4},3) = 8.000000
S({4},5) = 8.000000
S({5},2) = 6.000000
S({5},3) = 8.000000
S({5},4) = 5.000000
S(4,{  2  3 })=9.000000
S(5,{  2  3 })=8.000000
S(3,{  2  4 })=10.000000
S(5,{  2  4 })=9.000000
S(3,{  2  5 })=10.000000
S(4,{  2  5 })=7.000000
S(2,{  3  4 })=4.000000
S(5,{  3  4 })=6.000000
S(2,{  3  5 })=4.000000
S(4,{  3  5 })=3.000000
S(2,{  4  5 })=6.000000
S(3,{  4  5 })=8.000000
S(5,{  2  3  4 })=7.000000
S(4,{  2  3  5 })=8.000000
S(3,{  2  4  5 })=10.000000
S(2,{  3  4  5 })=4.000000
S(1,{  2  3  4  5 })=5.000000
SubsetCount=15
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-9200973434598324398?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/9200973434598324398/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=9200973434598324398&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/9200973434598324398'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/9200973434598324398'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2008/07/tech-illustration-of-how-to-use-bfs.html' title='[TECH] Illustration of how to use the BFS based subset enumeration algorithmic framework to solve TSP.'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-5577007657458269021</id><published>2008-07-04T19:09:00.000-07:00</published><updated>2008-07-04T20:01:51.959-07:00</updated><title type='text'>[TECH] A note on enumerating subsets using BFS.</title><content type='html'>&lt;p&gt; I have several things which I want to make a note on my blog, but unfortunately
I'm not getting enough time to write the blog posts. Any way.
&lt;/p&gt;

&lt;p&gt; Recently I came across several Dynamic Programming formulations which involve
subsets in the Subproblem for example take the TSP problem, the Subproblem &lt;b&gt;T(S-{j},j)&lt;/b&gt; is often used in the D.P formulation which indicates the optimal path starting from node &lt;b&gt;'1'&lt;/b&gt; and covering all the nodes in the subset &lt;b&gt;'S'&lt;/b&gt; and ending in node &lt;b&gt;'j'&lt;/b&gt;. Here &lt;b&gt;'S'&lt;/b&gt; is a &lt;b&gt;subset&lt;/b&gt; of &lt;b&gt;V&lt;/b&gt; (set of all the nodes/vertices's of the given graph.). The final answer for the TSP problem is found by finding a &lt;b&gt;'k'&lt;/b&gt; such that &lt;b&gt;T(V-{k},k) + d(k,1)&lt;/b&gt; is minimum.
&lt;/p&gt;

&lt;p&gt; If we observe we need a small algorithm framework which moves the solution from all the subsets of size &lt;b&gt;'1'&lt;/b&gt; to &lt;b&gt;'|V|'&lt;/b&gt;. In simple terms we need to enumerate the subsets in the order of their sizes. I found that a BFS can really help in enumerating the Subsets. The following code should be very handy in providing an enumeration framework and will be greatly useful to solve optimization problems which 
involve subsets in their D.P formulation.
&lt;/p&gt;
&lt;hr&gt;
&lt;div style='font-family: Courier New;'&gt;#&lt;span style=' color: Blue;'&gt;include&lt;/span&gt;&amp;lt;stdio.h&amp;gt; &lt;BR /&gt;#&lt;span style=' color: Blue;'&gt;include&lt;/span&gt;&amp;lt;stdlib.h&amp;gt; &lt;BR /&gt;#&lt;span style=' color: Blue;'&gt;include&lt;/span&gt;&amp;lt;&lt;span style=' color: Blue;'&gt;string&lt;/span&gt;.h&amp;gt; &lt;BR /&gt;#&lt;span style=' color: Blue;'&gt;include&lt;/span&gt;&amp;lt;assert.h&amp;gt; &lt;BR /&gt;#&lt;span style=' color: Blue;'&gt;include&lt;/span&gt;&amp;lt;math.h&amp;gt; &lt;BR /&gt;#&lt;span style=' color: Blue;'&gt;include&lt;/span&gt;&amp;nbsp;&lt;span style=' color: Maroon;'&gt;"List.h"&lt;/span&gt; &lt;BR /&gt;&lt;span style=' color: Blue;'&gt;#define&lt;/span&gt;&amp;nbsp;VERBOSE_MODE&amp;nbsp;&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt; &lt;BR /&gt; &lt;BR /&gt;&lt;span style=' color: Green;'&gt;/*Returns&amp;nbsp;the&amp;nbsp;new&amp;nbsp;tail&amp;nbsp;of&amp;nbsp;the&amp;nbsp;list*/&lt;/span&gt; &lt;BR /&gt;&lt;span style=' color: Blue;'&gt;inline&lt;/span&gt;&amp;nbsp;List*&amp;nbsp;ListAppend(List&amp;nbsp;**tail,&lt;span style=' color: Blue;'&gt;void&lt;/span&gt;&amp;nbsp;*_data){ &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;List&amp;nbsp;*new_node&amp;nbsp;=&amp;nbsp;(List&amp;nbsp;*)malloc(&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(new_node)*&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;); &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;assert(new_node); &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(!(*tail)){ &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(*tail)&amp;nbsp;=&amp;nbsp;new_node; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(*tail)-&amp;gt;_data&amp;nbsp;=&amp;nbsp;_data; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(*tail)-&amp;gt;next&amp;nbsp;=&amp;nbsp;&lt;span style=' color: Blue;'&gt;NULL&lt;/span&gt;; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=' color: Blue;'&gt;return&lt;/span&gt;&amp;nbsp;*tail; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;} &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;new_node-&amp;gt;_data&amp;nbsp;=&amp;nbsp;_data; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;new_node-&amp;gt;next&amp;nbsp;=&amp;nbsp;&lt;span style=' color: Blue;'&gt;NULL&lt;/span&gt;; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(*tail)-&amp;gt;next&amp;nbsp;=&amp;nbsp;new_node; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=' color: Blue;'&gt;return&lt;/span&gt;&amp;nbsp;new_node; &lt;BR /&gt;} &lt;BR /&gt;&lt;span style=' color: Blue;'&gt;typedef&lt;/span&gt;&amp;nbsp;&lt;span style=' color: Blue;'&gt;struct&lt;/span&gt;&amp;nbsp;_subset_{ &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=' color: Green;'&gt;/*if&amp;nbsp;i^th&amp;nbsp;bit&amp;nbsp;is&amp;nbsp;set&amp;nbsp;then&amp;nbsp;subset&amp;nbsp;has&amp;nbsp;i^th &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*element*/&lt;/span&gt; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt;&amp;nbsp;&lt;span style=' color: Blue;'&gt;int&lt;/span&gt;&amp;nbsp;ebits; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt;&amp;nbsp;&lt;span style=' color: Blue;'&gt;int&lt;/span&gt;&amp;nbsp;max;&amp;nbsp;&lt;span style=' color: Green;'&gt;/*Maximum&amp;nbsp;element&amp;nbsp;in&amp;nbsp;the&amp;nbsp;subset*/&lt;/span&gt; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt;&amp;nbsp;&lt;span style=' color: Blue;'&gt;int&lt;/span&gt;&amp;nbsp;size;&amp;nbsp;&lt;span style=' color: Green;'&gt;/*Size&amp;nbsp;of&amp;nbsp;subset*/&lt;/span&gt; &lt;BR /&gt;}SubSet; &lt;BR /&gt;&lt;span style=' color: Green;'&gt;/*Enumerate&amp;nbsp;the&amp;nbsp;Subset&amp;nbsp;using&amp;nbsp;BFS,&amp;nbsp;n&amp;nbsp;is&amp;nbsp; &lt;BR /&gt;&amp;nbsp;*the&amp;nbsp;set&amp;nbsp;size&amp;nbsp;[1,2...n]&amp;nbsp;*/&lt;/span&gt; &lt;BR /&gt;&lt;span style=' color: Blue;'&gt;void&lt;/span&gt;&amp;nbsp;EnumSubSetsBFS(&lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt;&amp;nbsp;&lt;span style=' color: Blue;'&gt;int&lt;/span&gt;&amp;nbsp;n){ &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt;&amp;nbsp;&lt;span style=' color: Blue;'&gt;int&lt;/span&gt;&amp;nbsp;i; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;List&amp;nbsp;*bfs_list&amp;nbsp;=&amp;nbsp;&lt;span style=' color: Blue;'&gt;NULL&lt;/span&gt;; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;List&amp;nbsp;*tail&amp;nbsp;=&amp;nbsp;&lt;span style=' color: Blue;'&gt;NULL&lt;/span&gt;;&amp;nbsp;List&amp;nbsp;*free_node; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SubSet&amp;nbsp;*sub_set,*new_sub_set; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SubSet&amp;nbsp;*one_sets&amp;nbsp;=&amp;nbsp;(SubSet&amp;nbsp;*)malloc(&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(SubSet)*n); &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt;&amp;nbsp;&lt;span style=' color: Blue;'&gt;int&lt;/span&gt;&amp;nbsp;current_level&amp;nbsp;=&amp;nbsp;&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=' color: Green;'&gt;/*Add&amp;nbsp;the&amp;nbsp;1-subsets*/&lt;/span&gt; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(i=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;i&amp;lt;n;i++){ &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;one_sets[i].ebits&amp;nbsp;=&amp;nbsp;&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;&amp;nbsp;one_sets[i].ebits&amp;nbsp;|=&amp;nbsp;(&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;&amp;lt;&amp;lt;i); &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;one_sets[i].max&amp;nbsp;=&amp;nbsp;i;&amp;nbsp;one_sets[i].size&amp;nbsp;=&amp;nbsp;&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(!tail){ &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ListAppend(&amp;amp;bfs_list,(&lt;span style=' color: Blue;'&gt;void&lt;/span&gt;&amp;nbsp;*)&amp;amp;(one_sets[i])); &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;tail&amp;nbsp;=&amp;nbsp;bfs_list; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=' color: Blue;'&gt;continue&lt;/span&gt;; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;} &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;tail&amp;nbsp;=&amp;nbsp;ListAppend(&amp;amp;tail,(&lt;span style=' color: Blue;'&gt;void&lt;/span&gt;&amp;nbsp;*)&amp;amp;(one_sets[i])); &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;} &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=' color: Green;'&gt;/*Now&amp;nbsp;do&amp;nbsp;the&amp;nbsp;BFS*/&lt;/span&gt; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=' color: Blue;'&gt;while&lt;/span&gt;(bfs_list){ &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sub_set&amp;nbsp;=&amp;nbsp;(SubSet&amp;nbsp;*)bfs_list-&amp;gt;_data;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;free_node&amp;nbsp;=&amp;nbsp;bfs_list; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bfs_list=bfs_list-&amp;gt;next; &lt;BR /&gt; &lt;BR /&gt;#ifdef&amp;nbsp;VERBOSE_MODE&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(sub_set-&amp;gt;size&amp;nbsp;!=&amp;nbsp;current_level){ &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;current_level&amp;nbsp;=&amp;nbsp;sub_set-&amp;gt;size; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;printf(&lt;span style=' color: Maroon;'&gt;"Printing&amp;nbsp;SubSets&amp;nbsp;of&amp;nbsp;Size&amp;nbsp;[%u]&amp;nbsp;\n"&lt;/span&gt;,current_level); &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;printf(&lt;span style=' color: Maroon;'&gt;"===============================\n"&lt;/span&gt;); &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;} &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=' color: Green;'&gt;/*print&amp;nbsp;this&amp;nbsp;set*/&lt;/span&gt; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;printf(&lt;span style=' color: Maroon;'&gt;"[&amp;nbsp;"&lt;/span&gt;); &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(i=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;i&amp;lt;n;i++){ &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(sub_set-&amp;gt;ebits&amp;nbsp;&amp;amp;&amp;nbsp;(&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;&amp;lt;&amp;lt;i)){ &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;printf(&lt;span style=' color: Maroon;'&gt;"%u&amp;nbsp;"&lt;/span&gt;,i); &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;} &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;} &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;printf(&lt;span style=' color: Maroon;'&gt;"]\n"&lt;/span&gt;); &lt;BR /&gt;&lt;span style=' color: Blue;'&gt;#endif&lt;/span&gt; &lt;BR /&gt; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;assert(sub_set-&amp;gt;max&amp;nbsp;&amp;lt;&amp;nbsp;n); &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(i=((sub_set-&amp;gt;max)+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;);i&amp;lt;n;i++){ &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;new_sub_set&amp;nbsp;=&amp;nbsp;(SubSet&amp;nbsp;*)&amp;nbsp;malloc(&lt;span style=' color: Blue;'&gt;sizeof&lt;/span&gt;(SubSet)*&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;); &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;new_sub_set-&amp;gt;size&amp;nbsp;=&amp;nbsp;(sub_set-&amp;gt;size)+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;new_sub_set-&amp;gt;max&amp;nbsp;=&amp;nbsp;i; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;new_sub_set-&amp;gt;ebits&amp;nbsp;=&amp;nbsp;(sub_set-&amp;gt;ebits&amp;nbsp;|&amp;nbsp;(&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;&amp;lt;&amp;lt;i)); &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;tail&amp;nbsp;=&amp;nbsp;ListAppend(&amp;amp;tail,(&lt;span style=' color: Blue;'&gt;void&lt;/span&gt;&amp;nbsp;*)new_sub_set); &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;} &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(!(sub_set&amp;nbsp;&amp;gt;=&amp;nbsp;one_sets&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;sub_set&amp;nbsp;&amp;lt;=&amp;nbsp;&amp;amp;(one_sets[n-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;]))){ &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;free(sub_set);&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;} &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;free(free_node); &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;} &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;free(one_sets); &lt;BR /&gt;} &lt;BR /&gt;&lt;span style=' color: Blue;'&gt;int&lt;/span&gt;&amp;nbsp;main(&lt;span style=' color: Blue;'&gt;int&lt;/span&gt;&amp;nbsp;argc,&lt;span style=' color: Blue;'&gt;char&lt;/span&gt;&amp;nbsp;**argv){ &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;EnumSubSetsBFS(&lt;span style=' color: Maroon;'&gt;5&lt;/span&gt;); &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=' color: Blue;'&gt;return&lt;/span&gt;&amp;nbsp;&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;; &lt;BR /&gt;}&lt;/div&gt;

&lt;/hr&gt;

&lt;p&gt;
Thanks to this &lt;a href="http://puzzleware.net/codehtmler/default.aspx"&gt;http://puzzleware.net/codehtmler/default.aspx&lt;/a&gt;
for converting my code.
&lt;/p&gt;

Cheers!
Vamsi.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-5577007657458269021?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/5577007657458269021/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=5577007657458269021&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/5577007657458269021'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/5577007657458269021'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2008/07/tech-note-on-enumerating-subsets-using.html' title='[TECH] A note on enumerating subsets using BFS.'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-9090634639737474256</id><published>2008-06-14T15:29:00.000-07:00</published><updated>2008-06-14T16:00:26.986-07:00</updated><title type='text'>[LIFE] It feels like I want to be a Grad student all my life.....Why does industry lack Passion?</title><content type='html'>&lt;p&gt;
When do you enjoy most being a grad student? from my experience I found the following
important facts.
&lt;ul&gt;
&lt;li&gt; Its passion which drives you, not Money. 
&lt;li&gt; When you start seeing the beauty behind what you study.
&lt;li&gt; When you have an advisor who is simply great!
&lt;/ul&gt;
I feel that industry industry lacks passion, the passion and drive which a graduate student has is simply missing in the Industy. I don't know the reason why this happens is money in the industry making people Complacent? . I wanted to write my own views in this post.
&lt;/p&gt;
&lt;p&gt; The first year I'm into my graduate studies. I always felt that that I should get of UCONN as soon as possible just by getting a M.S degree. But as things went on I really started liking to be a graduate student. I started setting up my own goals rather than some one giving me list of things, and as I started get deep into the field of Combinatorics and Algorithms I started to feel that I need more mathematics for my analysis and now I decided to apply for a M.S degree in Mathematics. My mindset had definitely changed I started to feel that "THERE IS NO SHORTCUT TO SUCCESS". My desire for doing quality work has been getting stronger and stronger and now I'm in a situation that I cannot imagine myself without a PhD and some real and original contribution Algorithmic theory. I guess the only time in your life when sky seems a limit is only during graduate student life. If you really want you can be extremely productive and much professional than any guy working in the industry.
&lt;p&gt;
&lt;p&gt; I think I have written soo much of code as a graduate student rather than in the industry, because in the industry when you have contributed to your project you feel good, your boss comes and praises you and then you start taking breaks and your productivity falls, you want to take breaks on weekends and I feel that people become very COMPLACENT once they get into industry. I find that passion and drive which a graduate has is totally lacking in industry. 
&lt;/p&gt;
&lt;p&gt;
I feel that one should not change if the environment around him keeps changing. I have so much of advice from my friends to apply for a big school for PhD rather than UCONN. I really don't understand why these guys are so afraid of life, I think these people have no confidence on them selfs but they feel secured only with TAG of a big school they think thats going to save them all the life. Lets take an example consider a PhD from the best university in the world call him X and consider a guy who is not at all a PhD and might have some undergraduate degree but has studied all the Volumes of Donald.E.Knuth and worked out all the exercises himself if far far far wiser than a a guy with a PhD from a top school with a mediocre dissertation.
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-9090634639737474256?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/9090634639737474256/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=9090634639737474256&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/9090634639737474256'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/9090634639737474256'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2008/06/life-it-feels-like-i-want-to-be-grad.html' title='[LIFE] It feels like I want to be a Grad student all my life.....Why does industry lack Passion?'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-1353999520593174046</id><published>2008-05-28T08:36:00.000-07:00</published><updated>2008-05-28T08:44:16.122-07:00</updated><title type='text'>[TECH] The C v C++ Flame which I have been looking for this time from *Linus*</title><content type='html'>&lt;p&gt; 
I was doing a Google search with keywords "C++ sucks" and found a flame on the git mailing list. Linus was totally angry by some guy who suggests that "git should have been written in c++ rather c". See the flame  &lt;a href ="http://thread.gmane.org/gmane.comp.version-control.git/57643/focus=57918"&gt;here&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
I have been looking for this kind of stuff from long time when I advocate that why I always stick to writing code in things like C,Perl and shell scripts. I feel that I have total control on the program if I write code in C in which I can deal with the virtual address's but unfortunately as the abstraction increases you cannot have the control on the actual code. I guess its not only me but *You cannot convince any hacker to use c++*
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-1353999520593174046?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/1353999520593174046/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=1353999520593174046&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/1353999520593174046'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/1353999520593174046'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2008/05/tech-c-v-c-flame-which-i-have-been.html' title='[TECH] The C v C++ Flame which I have been looking for this time from *Linus*'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-7753909486785500639</id><published>2008-04-29T16:29:00.000-07:00</published><updated>2008-07-04T19:53:53.311-07:00</updated><title type='text'>[TECH] A simple UNIX based algorithm to run a set of tasks in parallel.</title><content type='html'>&lt;p&gt;
Given a set of tasks &lt;b&gt;T={t&lt;sub&gt;1&lt;/sub&gt;,t&lt;sub&gt;2&lt;/sub&gt;....,t&lt;sub&gt;n&lt;/sub&gt;}&lt;/b&gt; such that these tasks can be run independently in parallel, however we have a limited set of resources and our constraint is &lt;b&gt;K&lt;/b&gt; which tells us the maximum number of process's which can run in parallel. Our problem now is to realize this in UNIX using standard system calls like &lt;b&gt;fork&lt;/b&gt; and &lt;b&gt;wait&lt;/b&gt;.
&lt;/p&gt;

&lt;p&gt; I came across this recently and I came across the same thing several times before. Some examples of the contexts which would need this are as follows.
&lt;ul&gt;
&lt;li&gt; Running test cases (regressions) in parallel, suppose we have several thousands of test cases for a product and we wish to run on a machine which can run &lt;b&gt;K&lt;/b&gt; tests at any given instance.
&lt;li&gt; Making builds in parallel
&lt;li&gt; Parallel crawling/web indexing (which was my motivation to write this)
&lt;/ul&gt; 
&lt;/p&gt;
&lt;p&gt; Download this &lt;a href="http://trinity.engr.uconn.edu/~vamsik/parallel_runner.pl"&gt;code&lt;/a&gt;&lt;/p&gt;
&lt;pre&gt;$#ARGV == &lt;span style=' color: Maroon;'&gt;1&lt;/span&gt; &lt;span style=' color: Blue;'&gt;or&lt;/span&gt; die(&lt;span style=' color: Maroon;'&gt;"USAGE: perl parallel_runner.pl {file_with_commands} {no.of.process's}"&lt;/span&gt;);
$command_file = $ARGV[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;];
open(CMD_FILE,$command_file) &lt;span style=' color: Blue;'&gt;or&lt;/span&gt; die(&lt;span style=' color: Maroon;'&gt;"$!"&lt;/span&gt;);
$max_process = $ARGV[&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;];
($max_process &amp;lt; &lt;span style=' color: Maroon;'&gt;256&lt;/span&gt;) &lt;span style=' color: Blue;'&gt;or&lt;/span&gt; die(&lt;span style=' color: Maroon;'&gt;"Too many process's....use less number"&lt;/span&gt;);
%child_hash;
$process_count = &lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;
&lt;span style=' color: Blue;'&gt;while&lt;/span&gt;(&amp;lt;CMD_FILE&amp;gt;){
 $cmd = $_;
 &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;($cmd =~ /^\#/){
  next;
 }
 &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;($process_count &amp;lt; $max_process){
  $pid = fork();
  &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;($pid &amp;lt; &lt;span style=' color: Maroon;'&gt;0&lt;/span&gt; ){
   die(&lt;span style=' color: Maroon;'&gt;"$! : RESOURCE ERRORS"&lt;/span&gt;);
  }elsif($pid == &lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;){
   system(&lt;span style=' color: Maroon;'&gt;"$cmd"&lt;/span&gt;);
   exit(&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;);
  }&lt;span style=' color: Blue;'&gt;else&lt;/span&gt;{
   $child_hash{$pid} = &lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;
   $process_count++;
  }
 }

 &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;($process_count==$max_process){
  $pid = wait();
  &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;($child_hash{$pid} == &lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;){
   $child_hash{$pid} = &lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;
  }elsif($pid == -&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;){
   print &lt;span style=' color: Maroon;'&gt;"No childs to wait?? Confused...quitting\n"&lt;/span&gt;;
   last;
  } 
  $process_count--;
 }
}
print &lt;span style=' color: Maroon;'&gt;"Done creating process's...now waiting for childs...\n"&lt;/span&gt;;
$i = &lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;
&lt;span style=' color: Blue;'&gt;while&lt;/span&gt;($i &amp;lt; $max_process){
 $pid = wait();
 &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;($pid == -&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;){
  last;
 }
 $i++;
}&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-7753909486785500639?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/7753909486785500639/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=7753909486785500639&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/7753909486785500639'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/7753909486785500639'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2008/04/tech-simple-unix-based-algorithm-to-run.html' title='[TECH] A simple UNIX based algorithm to run a set of tasks in parallel.'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-2996791822619202217</id><published>2008-04-23T17:13:00.000-07:00</published><updated>2008-04-26T15:53:26.240-07:00</updated><title type='text'>[TECH] Computing all the derivatives of a 'n' degree polynomial at point 'x=a' in O(nlog(n)) time.</title><content type='html'>&lt;p&gt;
I came across this problem recently, basically you are given a polynomial &lt;b&gt;f(x) = a&lt;sub&gt;n&lt;/sub&gt;x&lt;sup&gt;n&lt;/sup&gt;+a&lt;sub&gt;n-1&lt;/sub&gt;x&lt;sup&gt;n-1&lt;/sup&gt;+....a&lt;sub&gt;0&lt;/sub&gt;&lt;/b&gt; and you need to evaluate all its derivatives at a given point say &lt;b&gt;x=a&lt;/b&gt;. I guess one of the suggested algorithms for this problem runs in &lt;b&gt;O(nlog&lt;sup&gt;2&lt;/sup&gt;(n))&lt;/b&gt;. But I found an idea to solve this in just &lt;b&gt;O(nlog(n))&lt;/b&gt;. The following is the brief description of my algorithm 
&lt;/p&gt;

&lt;p&gt;
The idea is that we can post this as a simple multiplication of two &lt;b&gt;n&lt;/b&gt; degree polynomials, the coefficients resulting from the multiplication will be the evaluated derivatives at a given point &lt;b&gt;x=k&lt;/b&gt;. And as we might know that we can use &lt;b&gt;FFT&lt;/b&gt; to multiply two &lt;b&gt;n&lt;/b&gt;-degree polynomials in &lt;b&gt;O(nlog(n))&lt;/b&gt;
&lt;ul&gt;
&lt;li&gt; STEP1: Compute the values of &lt;b&gt;k&lt;sup&gt;2&lt;/sup&gt;,k&lt;sup&gt;3&lt;/sup&gt;....,k&lt;sup&gt;n&lt;/sup&gt;&lt;/b&gt; in &lt;b&gt;O(n)&lt;/b&gt; time. Also compute the values of &lt;b&gt;n!,(n-1)!,....2!&lt;/b&gt; incrementally. The runtime of this
step is &lt;b&gt;O(n)&lt;/b&gt;

&lt;li&gt; STEP2: Create polynomial &lt;b&gt;p(x) = (n!a&lt;sub&gt;n&lt;/sub&gt;)x&lt;sup&gt;n-1&lt;/sup&gt;+((n-1)!a&lt;sub&gt;n-1&lt;/sub&gt;)x&lt;sup&gt;n-2&lt;/sup&gt;+.....a&lt;sub&gt;1&lt;/sub&gt;&lt;/b&gt;.

&lt;li&gt; STEP 3: Create polynomial &lt;b&gt; g(x) = (k&lt;sup&gt;n-1&lt;/sup&gt;/(n-1)!)x+(k&lt;sup&gt;n-2&lt;/sup&gt;/(n-2)!)x&lt;sup&gt;2&lt;/sup&gt;+(k&lt;sup&gt;n-3&lt;/sup&gt;/(n-3)!)x&lt;sup&gt;3&lt;/sup&gt;+....
+kx&lt;sup&gt;n-1&lt;/sup&gt; &lt;/b&gt;.

&lt;li&gt; STEP 4: Multiply &lt;b&gt;p(x)&lt;/b&gt; and &lt;b&gt;g(x)&lt;/b&gt; using FFT in &lt;b&gt;O(nlog(n)&lt;/b&gt; time.

&lt;li&gt; STEP 5: Clearly coefficient of &lt;b&gt;x&lt;sup&gt;n-i+1&lt;/sup&gt;&lt;/b&gt; gives the value of &lt;b&gt;i&lt;sup&gt;th&lt;/sup&gt;&lt;/b&gt; derivative.

&lt;/ul&gt;

&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-2996791822619202217?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/2996791822619202217/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=2996791822619202217&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/2996791822619202217'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/2996791822619202217'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2008/04/tech-computing-all-derivatives-of-n.html' title='[TECH] Computing all the derivatives of a &apos;n&apos; degree polynomial at point &apos;x=a&apos; in &lt;b&gt;O(nlog(n))&lt;/b&gt; time.'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-7658327062811797182</id><published>2008-04-19T15:12:00.000-07:00</published><updated>2008-07-04T19:56:09.199-07:00</updated><title type='text'>[TECH] What does computing the edit distance between a string and its reverse tell us?</title><content type='html'>&lt;p&gt; I came across a problem recently which asks for the following "Given a string find out the minimum number of characters to be inserted to make it a palindrome, and also give the string". There might be several ways to solve this problem I have a simple algorithm to solve this problem in &lt;b&gt;O(n&lt;sup&gt;2&lt;/sup&gt;)&lt;/b&gt;. The observation is the following reccurence.
&lt;/p&gt;
&lt;p&gt;
Let LCS&lt;sup&gt;r&lt;/sup&gt;[x,y] = longest common sub sequence between &lt;b&gt;S&lt;sub&gt;1...x&lt;/sub&gt;&lt;/b&gt; and &lt;b&gt;S&lt;sup&gt;r&lt;/sup&gt;&lt;sub&gt;1...y&lt;/sub&gt;&lt;/b&gt; , where &lt;b&gt;S&lt;sup&gt;r&lt;/sup&gt;&lt;/b&gt; is the reverse of 
the string &lt;b&gt;S&lt;/b&gt;.&lt;br&gt;

Let &lt;b&gt;X=x&lt;sub&gt;1&lt;/sub&gt;x&lt;sub&gt;2&lt;/sub&gt;....x&lt;sub&gt;k&lt;/sub&gt;&lt;/b&gt; be the be the palindrome with minimum # of inserted characters to make it a palindrome, then &lt;b&gt;X&lt;/b&gt; has to be formed from &lt;b&gt;S&lt;/b&gt; as follows.&lt;br&gt;

1. Find a index &lt;b&gt;k&lt;/b&gt; in &lt;b&gt;S&lt;/b&gt; such that the cost of transforming &lt;b&gt;S[1..k]&lt;/b&gt; to &lt;b&gt;S[k+1...n]&lt;/b&gt; is minimum and the palindrome would be
&lt;b&gt; X = S'[1...k]S'&lt;sup&gt;r&lt;/sup&gt;[k+1...n] &lt;/b&gt; or &lt;b&gt; X = S'[1..k-1]S[k]S'&lt;sup&gt;r&lt;/sup&gt;[k+1..n]&lt;/b&gt; &lt;br&gt;

2. The index &lt;b&gt;k&lt;/b&gt; such that &lt;b&gt;LCS&lt;sup&gt;r&lt;/sup&gt;[k][len-k]&lt;/b&gt; is maximum.&lt;br&gt;
3. Get the code &lt;a href="http://trinity.engr.uconn.edu/~vamsik/ShortestPalindrome.c"&gt;
here &lt;/a&gt;
&lt;/p&gt;

&lt;pre&gt;&lt;span style=' color: Green;'&gt;/*Builds the LCS between the forward and backwards and finds
a index 'p' which will give minimum # of operations to transform
forward string to backward string.*/&lt;/span&gt;
&lt;span style=' color: Blue;'&gt;void&lt;/span&gt; FindLCSReverse(&lt;span style=' color: Blue;'&gt;char&lt;/span&gt; *str,&lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; len){
    &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; i,j;
    &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; current_min,max_lcs;
    &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; imax,jmax,palindex,palindex_r;
    &lt;span style=' color: Blue;'&gt;unsigned&lt;/span&gt; &lt;span style=' color: Blue;'&gt;int&lt;/span&gt; operations;
    &lt;span style=' color: Blue;'&gt;char&lt;/span&gt; path=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;
    &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(i=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;i&amp;lt;len;i++){
        LCS[i][&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;] = &lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;
    }
    &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(j=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;j&amp;lt;len;j++){
        LCS[&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;][j] = &lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;
    }
    &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(i=&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;i&amp;lt;len;i++){
        &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(j=&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;j&amp;lt;len;j++){
            &lt;span style=' color: Green;'&gt;/*use len-j to access other string*/&lt;/span&gt;
            &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(buf[i] == buf[len-j]){
                LCS[i][j] = LCS[i-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][j-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;]+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;
            }&lt;span style=' color: Blue;'&gt;else&lt;/span&gt;{
                LCS[i][j] = (LCS[i-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][j]&amp;gt;LCS[i][j-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;])?LCS[i-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][j]:LCS[i][j-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;];
            }
        }
    }
    &lt;span style=' color: Green;'&gt;/*Compute the p which gives minimum inserts to transform 
     *forward string to backward
     */&lt;/span&gt;
    max_lcs=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;
    imax=len-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;jmax=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;
    &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(i=len-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;i&amp;gt;=&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;i--){
        &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(LCS[i][len-i-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;] &amp;gt; max_lcs){
            max_lcs = LCS[i][len-i-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;];
            imax = i;
            jmax = len-i-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;
        }
        &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(i&amp;gt;&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt; &amp;amp;&amp;amp; LCS[i-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][len-i-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;] &amp;gt;= max_lcs){
            max_lcs = LCS[i-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][len-i-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;];
            imax = i-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;
            jmax = len-i-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;;
        }
    }
    &lt;span style=' color: Green;'&gt;/*Now find the actual string*/&lt;/span&gt;
    i=imax;
    j=jmax; 

    palindex_r=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;
    &lt;span style=' color: Blue;'&gt;while&lt;/span&gt;(i!=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt; || j!=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;){
        &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(i&amp;gt;&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt; &amp;amp;&amp;amp; j&amp;gt;&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;){
            &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(buf[i] == buf[len-j]){
                palindrome_rev[palindex_r++] = buf[i];
                i--; j--;
                &lt;span style=' color: Blue;'&gt;continue&lt;/span&gt;;
            }
            current_min = (LCS[i-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][j] &amp;gt; LCS[i][j-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;])?LCS[i-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][j]:LCS[i][j-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;];
            &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(current_min == LCS[i-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][j]){
                &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(current_min == LCS[i][j-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;] &amp;amp;&amp;amp; buf[i] &amp;lt; buf[len-j]){
                    palindrome_rev[palindex_r++] = buf[len-j];
                    j--;
                }&lt;span style=' color: Blue;'&gt;else&lt;/span&gt;{
                    palindrome_rev[palindex_r++] = buf[i];
                    i--;
                }
            }&lt;span style=' color: Blue;'&gt;else&lt;/span&gt; &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(current_min == LCS[i][j-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;]){
                &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(current_min == LCS[i-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;][j] &amp;amp;&amp;amp; buf[len-j] &amp;lt; buf[i]){
                    palindrome_rev[palindex_r++] = buf[i];
                    i--;
                }&lt;span style=' color: Blue;'&gt;else&lt;/span&gt;{
                    palindrome_rev[palindex_r++] = buf[len-j];
                    j--;
                }
            }
        }&lt;span style=' color: Blue;'&gt;else&lt;/span&gt; &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(j==&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;){
            palindrome_rev[palindex_r++] = buf[i];
            i--;
        }&lt;span style=' color: Blue;'&gt;else&lt;/span&gt; &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(i==&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;){
            palindrome_rev[palindex_r++] = buf[len-j];
            j--;
        }
        &lt;span style=' color: Green;'&gt;/*path=1 (left) path=2 (down) path=3 (diag)*/&lt;/span&gt;
    }

    &lt;span style=' color: Blue;'&gt;for&lt;/span&gt;(i=&lt;span style=' color: Maroon;'&gt;0&lt;/span&gt;;i&amp;lt;palindex_r;i++){
        palindrome[palindex_r-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;-i] = palindrome_rev[i];
    }
    palindrome_rev[palindex_r] = &lt;span style=' color: Maroon;'&gt;'\0'&lt;/span&gt;;
    palindrome[palindex_r] = &lt;span style=' color: Maroon;'&gt;'\0'&lt;/span&gt;;

    &lt;span style=' color: Green;'&gt;/*printf("imax = %u jmax = %u len=%u \n",imax,jmax,len);*/&lt;/span&gt;
    &lt;span style=' color: Blue;'&gt;if&lt;/span&gt;(imax+jmax==len-&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;){
        printf(&lt;span style=' color: Maroon;'&gt;"%s%s\n"&lt;/span&gt;,palindrome,palindrome_rev);
    }&lt;span style=' color: Blue;'&gt;else&lt;/span&gt;{
        printf(&lt;span style=' color: Maroon;'&gt;"%s%c%s\n"&lt;/span&gt;,palindrome,buf[imax+&lt;span style=' color: Maroon;'&gt;1&lt;/span&gt;],palindrome_rev);
    }
}&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-7658327062811797182?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/7658327062811797182/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=7658327062811797182&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/7658327062811797182'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/7658327062811797182'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2008/04/tech-what-does-computing-edit-distance.html' title='[TECH] What does computing the edit distance between a string and its reverse tell us?'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-3315804739392921740</id><published>2008-04-15T23:02:00.000-07:00</published><updated>2008-04-15T23:15:18.200-07:00</updated><title type='text'>[TECH] Reverse Engineering and Creating Crawler BOTS.</title><content type='html'>&lt;p&gt;
I have my share of pleasure reverse engineering the underlying details of SCOPUS. SCOPUS as you might know is the most popular scholarly database used for citation searching. I was trying to solve this problem "Given a research paper X produce a set of research papers in the same connected component of the CITATION GRAPH", Let me define a CITATION GRAPH (CITE(V,E)) , V = {set of all research papers} and E={(i,j)} set of all directed edges from research paper 'i' to 'j' such that paper 'j' refers paper 'i' in its references. This edge information comes from SCOPUS however SCOPUS gives only one level (depth 1) in the connected component of all related papers, my goal is to get all the related papers (related in the sense fall in the same connected component of the CITE graph).
&lt;/p&gt;
&lt;p&gt; 
The reverse engineering the underlying comes handy when we want to automate the process of searching all these from the browser ourself.
&lt;/p&gt;
&lt;p&gt; I'm too tired to explain the details of the program which I had written using perl+LWP to create a CRAWLER BOT which gets all the related papers but if you need similar stuff sure the code can help &lt;a href="http://dna.engr.uconn.edu/~vamsik/forward_scopus.pl"&gt; click here &lt;/a&gt;
&lt;/p&gt;

&lt;p&gt; Unfortunately I don't get enough time to write blogs but in past few weeks I had some very interesting technical stuff I want to write.
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-3315804739392921740?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/3315804739392921740/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=3315804739392921740&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/3315804739392921740'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/3315804739392921740'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2008/04/tech-reverse-engineering-and-creating.html' title='[TECH] Reverse Engineering and Creating Crawler BOTS.'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-6614780240677583009</id><published>2008-03-12T22:31:00.000-07:00</published><updated>2008-03-12T22:55:54.740-07:00</updated><title type='text'>[TECH] A simple algorithm to find the coefficient's of characteristic polynomial.</title><content type='html'>&lt;p&gt;
Its often the case that the we need coefficients of the characteristic polynomial (&lt;b&gt;xA = &amp;lambda;x&lt;/b&gt;) rather than just the Eigen values and Eigen vectors of the matrix &lt;b&gt;A&lt;/b&gt;, The following simple algorithm which can determine the coefficients of the polynomial from its roots (Eigen values) would be extremely handy, its a simple dynamic programming algorithm and also illustrates how quickly we can code
dynamic programming algorithms in Matlab because the matrices resize automatically.
&lt;/p&gt;
&lt;pre&gt;
&lt;font size=3&gt;

%
% eigen_poly_coeff: input 'A' should be a square matrix
% The program finds the eigen values of A, and constructs
% the caracteristic polynomial 
%
% output is the order of coefficients in the increasing 
% degree order.
%
function retval = eigen_poly_coeff (A)
v = eig(A)';
B = size(v);
coeff_matrix = eye(1,(B(1,2)+1));
coeff_matrix(1,1) = v(1,1)*-1;
coeff_matrix(1,2) = 1;

for i=3:1:(B(1,2)+1)
   coeff_matrix(1,i) = 1;
   for j=(i-1):-1:1
    coeff_matrix(1,j) = (coeff_matrix(1,j)*
                v(1,(i-1))*-1);
    if(j-1 &gt;=1)
      coeff_matrix(1,j) = 
             coeff_matrix(1,j)+coeff_matrix(1,j-1);
    end
   end
end
 retval = coeff_matrix;
endfunction


&lt;/font&gt;
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-6614780240677583009?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/6614780240677583009/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=6614780240677583009&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/6614780240677583009'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/6614780240677583009'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2008/03/tech-simple-algorithm-to-find.html' title='[TECH] A simple algorithm to find the coefficient&apos;s of characteristic polynomial.'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-1543533709134679865</id><published>2008-03-09T23:58:00.000-07:00</published><updated>2008-03-10T00:11:59.770-07:00</updated><title type='text'>[TECH] Algorithmic details of UNIX Sort command.</title><content type='html'>&lt;p&gt;
I happened to look at the algorithmic details of UNIX Sort, a LINUX version of
the classic UNIX sort is a part of GNU  &lt;a href="http://www.gnu.org/software/coreutils/"&gt;coreutils-6.9.90&lt;/a&gt;. This is classic
example of the standard External &lt;b&gt;R-Way&lt;/b&gt; merge , to sort a data of size &lt;b&gt;N&lt;/b&gt; bytes with a main memory size of &lt;b&gt;M&lt;/b&gt; so it creates &lt;b&gt;N/M&lt;/b&gt; runs and merges &lt;b&gt;R&lt;/b&gt; at a time, the number of passes through the data is &lt;b&gt;log(N/M)/log(R)&lt;/b&gt;
passes.In fact the lower bound(runtime) for external sorting is &lt;b&gt;&amp;Omega;((N/M)log(N/M)/log(R))&lt;/b&gt;. All the external memory sorting algorithms provided in the literature are optimal so the fight here is minimizing the constant before the number of passes.
&lt;/p&gt;

&lt;p&gt;
UNIX sort treats keys are lines (strings), the algorithm followed by
unix sort is in fact the R-Way merge. Let the input file size be
IN_SIZE. &lt;br&gt;

1. Choosing Run Size:&lt;br&gt;
--------------------------------&lt;br&gt;
The sizes of the initial runs are chosen from the total physical
memory (TOTAL_PHY) and available memory (AVAIL_PHY).
RUN_SIZE = (MAX(TOTAL_PHY/8,AVAIL_PHY))/2
&lt;br&gt;
maximum of 1/8th of TOTAL_PHY and AVAIL_PHY and divided by 2.
See function "default_sort_size (void)" in the code.&lt;br&gt;

2. Creating Runs:&lt;br&gt;
-------------------------&lt;br&gt;

Unix sort creates a temporary file for every run. So it creates
IN_SIZE/RUN_SIZE (celing) temporary files. Internally it uses merge
sort to sort internally it uses an optimization mentioned in Knuth
volume 3 (2nd edition), problem 5.2.4-23.&lt;br&gt;

3. Merging:&lt;br&gt;
----------------&lt;br&gt;

The number of runs merged at any time is hard coded in the program
see macro NMERGE , NMERGE is defined to be 16 so it merges
exactly 16 runs at any time.
&lt;br&gt;
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-1543533709134679865?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/1543533709134679865/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=1543533709134679865&amp;isPopup=true' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/1543533709134679865'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/1543533709134679865'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2008/03/tech-algorithmic-details-of-unix-sort.html' title='[TECH] Algorithmic details of UNIX Sort command.'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-2546570500893678201</id><published>2008-03-05T16:12:00.000-08:00</published><updated>2008-03-05T16:47:55.594-08:00</updated><title type='text'>[TECH] Sorting partially sorted sequences.</title><content type='html'>&lt;p&gt;
Partially Sorted Sequence: A sequence &lt;b&gt;k&lt;sub&gt;1&lt;/sub&gt;,k&lt;sub&gt;2&lt;/sub&gt;,...k&lt;sub&gt;n&lt;/sub&gt;&lt;/b&gt; of &lt;b&gt;n&lt;/b&gt; keys such that any key &lt;b&gt;k&lt;sub&gt;j&lt;/sub&gt;&lt;/b&gt; differs from its sorted position by atmost &lt;b&gt;d&lt;/b&gt; as an example for &lt;b&gt;d=3&lt;/b&gt; we have &lt;b&gt;3,5,6,1,2,4&lt;/b&gt;
I came across this problem recently, turns out that we can solve this problem in several ways in &lt;b&gt;O(nlog(d))&lt;/b&gt; time. I found an interesting and simple way to solve this problem, a simple observation reveals that the &lt;b&gt;smallest&lt;/b&gt; element
in the entire sequence of &lt;b&gt;n&lt;/b&gt; keys exists in the first &lt;b&gt;d&lt;/b&gt; keys.
&lt;/p&gt;
&lt;pre&gt;
&lt;font size=3&gt;
/*Build a heap(min) &lt;b&gt;H&lt;/b&gt; with first &lt;b&gt;d&lt;/b&gt; elements
 *in &lt;b&gt;O(d)&lt;/b&gt; time
 */
 for(i=d;i&amp;lt;n;i++){
    DeleteMin(H); /*output this key*/
    InsertHeap(H,k&lt;sub&gt;i&lt;/sub&gt;);
 }
/*Note the Heap will have atmost &lt;b&gt;d&lt;/b&gt; keys in it
at any time so the Insert and Delete can be done in 
&lt;b&gt;O(log(d))&lt;/b&gt; worst case.
*/
&lt;/font&gt;
&lt;/pre&gt;
&lt;p&gt;
 &lt;b&gt;(n-d)log(d) = O(nlog(d))&lt;/b&gt;
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-2546570500893678201?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/2546570500893678201/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=2546570500893678201&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/2546570500893678201'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/2546570500893678201'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2008/03/tech-sorting-partially-sorted-sequences.html' title='[TECH] Sorting partially sorted sequences.'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-1793879417562393219</id><published>2008-03-04T14:20:00.000-08:00</published><updated>2008-03-04T15:04:15.811-08:00</updated><title type='text'>[TECH] Converting an Las Vegas algorithm from an Expected Time Bound to High Probability bound.</title><content type='html'>&lt;p&gt;
Some times its not always possible to derive the High Probability bounds &lt;b&gt;(1-n&lt;sup&gt;-&amp;alpha;&lt;/sup&gt;)&lt;/b&gt;
for Las Vegas algorithms, I found an interesting way to convert any Las Vegas algorithm 
with expected bounds on the resources to the High Probability bounds. Assume that T&lt;sub&gt;n&lt;/sub&gt; be the expected runtime(or any resource) for a Las Vegas algorithm. The
plain vanilla Las Vegas algorithm have the following structure.
&lt;/p&gt;
&lt;pre&gt;
&lt;font size=3&gt;
while(1){
  /*Select a random sample*/
  if(answer found) quit;
}
&lt;/font&gt;
&lt;/pre&gt;
&lt;p&gt;
Basically any analysis of the above randomized algorithm should tell how long 
should we run the loop. So let &lt;b&gt;T&lt;sub&gt;n&lt;/sub&gt;&lt;/b&gt; gives the expected time on how
long this loop runs. What we can do is as follows
&lt;ul&gt;
&lt;li&gt; Let the algorithm run for exactly &lt;b&gt;2T&lt;sub&gt;n&lt;/sub&gt;&lt;/b&gt; steps, if the algorithm 
quits before that we are fine, if the algorithm does not quit after &lt;b&gt;T&lt;sub&gt;n&lt;/sub&gt;&lt;/b&gt;
times then stop and restart.
&lt;/ul&gt;
&lt;/p&gt;
&lt;pre&gt;
&lt;font size=3&gt;
counter = 0;
while(1){
 /*Pick a random sample*/
 if(counter++ == 2T&lt;sub&gt;n&lt;/sub&gt;){
    counter=0; /*restarting*/
 }
 if(answer found) quit; 
}
&lt;/font&gt;
&lt;/pre&gt;
&lt;p&gt;
We can now show that the above algorithm will now give high probability bounds. Let
&lt;b&gt;X&lt;/b&gt; be the random variable which indicates the runtime of the algorithm. Then using Markov inequality &lt;b&gt;P[X &amp;ge; aT&lt;sub&gt;n&lt;/sub&gt;] &amp;le; 1/a&lt;/sup&gt;&lt;/b&gt; 
&lt;ul&gt;
&lt;li&gt; &lt;b&gt;P[X &amp;ge; 2T&lt;sub&gt;n&lt;/sub&gt;] &amp;le; 1/2 &lt;/b&gt;
&lt;li&gt; Lets assume that the algorithm runs for &lt;b&gt;k &amp;ge; 2T&lt;sub&gt;n&lt;/sub&gt;&lt;/b&gt; time steps, then we should have done a reset exactly &lt;b&gt;k/(2T&lt;sub&gt;n&lt;/sub&gt;)&lt;/b&gt; times.
&lt;li&gt; The probability of doing a reset equals &lt;b&gt;P[X &amp;ge; 2T&lt;sub&gt;n&lt;/sub&gt;] = P[reset]&lt;/b&gt;.
&lt;li&gt; Lets assume all the events are independent then the probability of resetting &lt;b&gt;k/(2T&lt;sub&gt;n&lt;/sub&gt;)&lt;/b&gt; &lt;b&gt;P[reset k/(2T&lt;sub&gt;n&lt;/sub&gt;) times] = P[algorithm running k time steps]&lt;/b&gt;
&lt;li&gt; &lt;b&gt;P[reset k/(2T&lt;sub&gt;n&lt;/sub&gt;)] &amp;le; (1/2)*(1/2)*(1/2)...k/(2T&lt;sub&gt;n&lt;/sub&gt;) times&lt;/b&gt;
&lt;li&gt; &lt;b&gt;P[reset k/(2T&lt;sub&gt;n&lt;/sub&gt;)] &amp;le; (1/2)&lt;sup&gt;k/(2T&lt;sub&gt;n&lt;/sub&gt;)&lt;/sup&gt;&lt;/b&gt;
&lt;li&gt; we want the above probability to be very small (&lt;b&gt;n&lt;sup&gt;-&amp;alpha;&lt;/sup&gt;&lt;/b&gt;), to 
make that &lt;b&gt;(1/2)&lt;sup&gt;k/(2T&lt;sub&gt;n&lt;/sub&gt;)&lt;/sup&gt; = n&lt;sup&gt;-&amp;alpha;&lt;/sup&gt;&lt;/b&gt;). So 
the value of &lt;b&gt;k&lt;/b&gt; for which this happens is &lt;b&gt;2T&lt;sub&gt;n&lt;/sub&gt;&amp;alpha;log(n)&lt;/b&gt;
&lt;li&gt; So with high probability after &lt;b&gt;2T&lt;sub&gt;n&lt;/sub&gt;&amp;alpha;log(n)&lt;/b&gt; time steps
if we quit the loop then we give the correct answer.
&lt;li&gt; So we just have taken an expected bound &lt;b&gt;T&lt;sub&gt;n&lt;/sub&gt;&lt;/b&gt; and converted into &lt;b&gt;&amp;sim;O(log(n)T&lt;sub&gt;n&lt;/sub&gt;)&lt;/b&gt; time algorithm with high probability rather than
expected bounds.
&lt;/ul&gt;
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-1793879417562393219?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/1793879417562393219/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=1793879417562393219&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/1793879417562393219'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/1793879417562393219'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2008/03/tech-converting-las-vegas-algorithm.html' title='[TECH] Converting an Las Vegas algorithm from an Expected Time Bound to High Probability bound.'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-2650464151961751842</id><published>2008-02-29T23:17:00.000-08:00</published><updated>2008-03-02T15:27:17.522-08:00</updated><title type='text'>[TECH] Finding max and min in exactly 3n/2-2 Element Comparisions.</title><content type='html'>&lt;p&gt;
 We know that the lower bound on the minimum number of comparisons to find &lt;b&gt;max&lt;/b&gt;
and &lt;b&gt;min&lt;/b&gt; in an array of &lt;b&gt;n&lt;/b&gt;. In fact the recurrence &lt;b&gt;T(n) = 2T(n/2)+2 &lt;/b&gt;
solves exactly to &lt;b&gt;3n/2-2&lt;/b&gt; the following is an interesting way to find &lt;b&gt;max&lt;/b&gt;
and &lt;b&gt;min&lt;/b&gt; in exactly &lt;b&gt;3n/2-2&lt;/b&gt; comparisons non-recursively(assume 'n' is even). Also note by comparison we mean the element comparisons as they are significant.
&lt;/p&gt;
&lt;pre&gt;
&lt;font size=3&gt;
current_min = a[0]; current_max=a[1];
/* 1 comparison here */
if(current_min &amp;lt; current_max){
  current_min = a[1]; current_max = a[0];
}
/*(n-1)-2+1 times*/
for(i=2;i&amp;lt;n-1;i+=2){
  /*3 Element Comparisons here */
  if(a[i] &amp;lt; a[i+1]){
      if(a[i] &amp;lt; current_min) current_min = a[i];
      if(a[i+1] &amp;gt; current_max) current_max = a[i+1];     
  }else{
      if(a[i+1] &amp;lt; current_min) current_min = a[i+1];
      if(a[i] &amp;gt; current_max) current_max = a[i]; 
  }
}
/*return current_max current_min*/
&lt;/font&gt;
&lt;/pre&gt;
&lt;p&gt;
 Analysis: Total Comparisions = 1 + (((n-1)-2+1)/2)*3 = 3*n/2-2. &lt;br&gt;
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-2650464151961751842?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/2650464151961751842/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=2650464151961751842&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/2650464151961751842'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/2650464151961751842'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2008/02/tech-finding-max-and-min-in-exactly-3n2.html' title='[TECH] Finding &lt;b&gt;max&lt;/b&gt; and &lt;b&gt;min&lt;/b&gt; in exactly &lt;b&gt;3n/2-2&lt;/b&gt; Element Comparisions.'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-2843563936926936287</id><published>2008-02-12T15:08:00.000-08:00</published><updated>2008-02-12T15:23:02.880-08:00</updated><title type='text'>[TECH] Standard I/O Buffers won't get flushed when program crashes...</title><content type='html'>&lt;p&gt; Today I had a interesting problem, assume that you have a program printing out some
details on to the screen and suddenly the program crashes and you want to capture what 
ever it has printed what would you do? you would try to redirect the output to a file and look at that file and what if the contents of the redirected file is empty? how do you explain this? try the following program and try to redirect what ever it prints using '&gt;' or a '|' ("./a.out &gt; out" or "./a.out | more")
&lt;/p&gt;
&lt;pre&gt;
&lt;font size=3&gt;
char *crash_me = "crash this";
int main(){ 
    int i;  

    for(i=0;i&lt;10;i++){
        printf("Before crash line %d\n",i+1);
        if(i==9){
            crash_me[6] = 'C';
        }
    }
}
/*TRY THE FOLLOWING*/
#1$./a.out
#2$./a.out &gt; out
#3$./a.out | more
&lt;/font&gt;
&lt;/pre&gt;
&lt;/p&gt;
&lt;p&gt;
We can see that the 'out' file and 'more' don't show any thing which was in fact printed if we just run the program normally, how can we explain this? what exactly is
happened? actually this is what has happened in the first case the terminal output is
line buffered when ever terminal sees '\n' it prints that but in the next two cases
the output is written to a file which is not line buffered (but gets written when 
the buffer is full) and since the program is crashed before the buffer gets full nothing is printed in case of #2 and #3. I guess one should definitely have a signal
handler for SIGSEGV and other signals which end the program and do a explicit flush as below.
&lt;/p&gt;
&lt;pre&gt;
&lt;font size=3&gt;
/*The buffers should be flushed before
 *program crashes.
 **/
void FlushBuffers(int sig){
    fprintf(stderr,"Segmentation Fault\n");
    fflush(stdout);fflush(stderr);
    exit(1);

}
char *crash_me = "crash this";
int main(){ 
    int i;  
    assert(signal(SIGSEGV,FlushBuffers)!=SIG_ERR);
    for(i=0;i&lt;10;i++){
        printf("Before crash line %d\n",i+1);
        if(i==9){
            crash_me[6] = 'C';
        }
    }
}
&lt;/font&gt;
&lt;/pre&gt;
&lt;p&gt;
I'm thinking of making a list of this kind of problems on UNIX
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-2843563936926936287?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/2843563936926936287/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=2843563936926936287&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/2843563936926936287'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/2843563936926936287'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2008/02/tech-standard-io-buffers-wont-get.html' title='[TECH] Standard I/O Buffers won&apos;t get flushed when program crashes...'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-1522201538991657912</id><published>2008-02-10T18:50:00.001-08:00</published><updated>2008-02-13T21:41:16.827-08:00</updated><title type='text'>[TECH] SafeRead and SafeWrite</title><content type='html'>&lt;p&gt;
'read' and 'write' are most frequently used system calls, its really a blunder to have something like the following in the code.
&lt;/p&gt;
&lt;pre&gt;
&lt;font size=3&gt;
/*Read and Write blunders*/
if(read(fd,buffer,len) &lt; 0 ){
  perror("Read ERROR:");
}

if(write(fd,buffer,len) &lt; 0){
  perror("Write ERROR:");
}
&lt;/font&gt;
&lt;/pre&gt;
&lt;p&gt;
The above code involving 'read' and 'write' syscalls may seem perfectly fine but unfortunately thats not true, NEVER IGNORE THE RETURN VALUE of a syscall, its very
common to functions like 'read' and 'write' to return values less than 'len' in several situations like program interrupted by a signal or timeout or if the 'len' is
very large say in 'Mb' make sure you have the following 'SafeRead' and 'SafeWrite' in
your coding libraries.
&lt;/p&gt;
&lt;pre&gt;
&lt;font size=3&gt;
ssize_t SafeWrite(int fd,void *buf,size_t wlen){
 ssize_t len; char *bbuf = (char *)buf;
 size_t writeln=0;
 while(writeln &lt; wlen){
   len = write(fd,&amp;(bbuf[writeln]),wlen-writeln);
   if(len&lt;=0) return len;
   writeln += len;
 }
 return writeln;
}

ssize_t SafeRead(int fd,void *buf,size_t rlen){
 ssize_t len;char *bbuf = (char *)buf;
 size_t readln=0;
 while(readln &lt; rlen){
   len = read(fd,&amp;(bbuf[readln]),rlen-readln);
   if(len&lt;=0) return len;
   readln += len;
 }
 return readln;
}
&lt;/font&gt;
&lt;/pre&gt;
&lt;p&gt;
Its quite often that the while loop only executes once, but its always possible that due to some reason the 'read' and 'write' syscalls may return less than the number of bytes you read or write. 
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-1522201538991657912?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/1522201538991657912/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=1522201538991657912&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/1522201538991657912'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/1522201538991657912'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2008/02/tech-saferead-and-safewrite.html' title='[TECH] SafeRead and SafeWrite'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-8569085598000675598</id><published>2008-01-30T22:06:00.000-08:00</published><updated>2008-01-30T22:21:12.113-08:00</updated><title type='text'>[TECH] A Contradictory gcc message.</title><content type='html'>&lt;p&gt;
I have been experimenting on some of my PDM (parallel disk model) sorting code
and wanted to create huge files with billions of keys I wanted to create a file
with 1 billion integers (1024*1024*1024*4), the program stopped after some time saying
that it "File size limit exceeded" , however in my shell (csh) the 'limit' command showed unlimited. 
&lt;/p&gt;

&lt;pre&gt;
&lt;font size=3&gt;

[vamsik@abadon PDMSorting]$ ./pdm_sort 
Setting RAND_SEED to 1201763856 
Filesize limit exceeded
[vamsik@abadon PDMSorting]$ ls -al key_file.txt 
---------- 1 vamsik fuse 2147483647 Jan 31 02:18 key_file.txt
[vamsik@abadon PDMSorting]$ 
&lt;/font&gt;
&lt;/pre&gt;

&lt;p&gt;
I saw that the file was created without any permissions, so I tweaked
my 'umask' but nothing changed (I was doing a open with (O_WRONLY|O_CREAT)). You might be wondering what exactly I'm trying to say in this post, in fact the story just started, rather than setting my 'umask' to 'umask 22', I have set it to 
'umask 755' and as usual I was doing a build with 'make' this is what happened.
&lt;/p&gt;
&lt;pre&gt;
&lt;font size=3&gt;
[vamsik@abadon PDMSorting]$ make
gcc  -O2  -I../myutil/            -c ExternalSort.c
ExternalSort.c:1: fatal error: can't open /tmp/cct9kuSr.s for writing: Permission denied
compilation terminated.
The bug is not reproducible, so it is likely a hardware or OS problem.
make: *** [ExternalSort.o] Error 1
[vamsik@abadon PDMSorting]$ 
&lt;/font&gt;
&lt;/pre&gt;
&lt;p&gt;
 Looks strange right? , see the funny thing it says &lt;b&gt;"The bug is not reproducible, so it is likely a hardware or OS problem."&lt;/b&gt; , its really a stupid error message
how can it say it cannot be reproduces? , just set 'umask 755' and do a 'gcc' on any
file its going to say the same thing, in fact the message is a utter contradiction because we can reproduce this by changing the 'umask'. I'm going to report this to the 'gcc' maintainers or submit a patch to the maintainers.
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-8569085598000675598?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/8569085598000675598/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=8569085598000675598&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/8569085598000675598'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/8569085598000675598'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2008/01/tech-contradictory-gcc-message.html' title='[TECH] A Contradictory gcc message.'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-6737382497203606010</id><published>2008-01-14T19:25:00.000-08:00</published><updated>2008-01-14T19:51:28.517-08:00</updated><title type='text'>[TECH] Ideas for Optimizing Design pattern implementations with Stack Collapsing</title><content type='html'>&lt;p&gt;
One major drawback I guess with all these object oriented systems I guess is performance, since people write the code so that its extensible it always ends up creating deep stack sizes, recently I was looking into 
(&lt;a href="jmol.sourceforge.net"&gt;Jmol&lt;/a&gt;) this structure visualization tool supports several input format descriptions for the structures (pdb,cif,molxyz....). This is how they hide format details from the display code &lt;br&gt;
&lt;b&gt;JmolAdapter&lt;/b&gt; (abstract class) &lt;br&gt; ==&gt; &lt;b&gt;SmarterJmolAdapter&lt;/b&gt; (this contains 
a interface called &lt;b&gt; AtomSetCollection &lt;/b&gt;). So depending on the input file
we have several &lt;b&gt; AtomSetCollection &lt;/b&gt; readers like &lt;b&gt;PdbAtomSetCollection&lt;/b&gt; etc... 
&lt;/p&gt;
&lt;p&gt;
Although I came to a conclusion that to implement the structural alignment algorithm into Jmol, I need to implement this &lt;b&gt; AtomSetCollection &lt;/b&gt; which structurally aligns the protein structures, but I guess there are several draw backs of the implementation of object oriented java implementation, the cost of creating an 
extensible design does not come for free it comes at the cost of performance, I found that a simple command execution could end up creating a stack size of 32 this is what
concerns me is there a way we can collapse the stack when we know that the intermediate functions on the stack are just delegating the call to the actual instance, I guess this STACK COLLAPSING technique can always be applied when ever
the Adapter design pattern is used. For example see the below stack of size 32,
its not doing any thing great its just opening a new script file, because of the
way the code is written (use of design patterns) the stack size seem to increase 
a lot and ULTIMATELY ALL THESE PATTERNS ARE JUST DELEGATING A FUNCTION CALL TO
TO FUNCTION ON TOP OF THE STACK, I'm think of ways to improve the delegation since
at each level of the stack you are doing a look up and it increases linearly with 
the size of the stack.
&lt;/p&gt;
&lt;pre&gt;
  [1] org.jmol.viewer.ScriptManager.addScript (ScriptManager.java:69)
  [2] org.jmol.viewer.ScriptManager.addScript (ScriptManager.java:52)
  [3] org.jmol.viewer.Viewer.evalStringQuiet (Viewer.java:3,152)
  [4] org.jmol.viewer.Viewer.evalString (Viewer.java:3,119)
  [5] org.jmol.viewer.Viewer.openFile (Viewer.java:1,379)
  [6] org.openscience.jmol.app.Jmol$OpenAction.actionPerformed (Jmol.java:1,435)
  [7] javax.swing.AbstractButton.fireActionPerformed (AbstractButton.java:1,849)
  [8] javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2,169)
  [9] javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:420)
  [10] javax.swing.DefaultButtonModel.setPressed (DefaultButtonModel.java:258)
  [11] javax.swing.AbstractButton.doClick (AbstractButton.java:302)
  [12] javax.swing.plaf.basic.BasicMenuItemUI.doClick (BasicMenuItemUI.java:1,051)
  [13] javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased (BasicMenuItemUI.java:1,092)
  [14] java.awt.Component.processMouseEvent (Component.java:5,517)
  [15] javax.swing.JComponent.processMouseEvent (JComponent.java:3,135)
  [16] java.awt.Component.processEvent (Component.java:5,282)
  [17] java.awt.Container.processEvent (Container.java:1,966)
  [18] java.awt.Component.dispatchEventImpl (Component.java:3,984)
  [19] java.awt.Container.dispatchEventImpl (Container.java:2,024)
  [20] java.awt.Component.dispatchEvent (Component.java:3,819)
  [21] java.awt.LightweightDispatcher.retargetMouseEvent (Container.java:4,212)
  [22] java.awt.LightweightDispatcher.processMouseEvent (Container.java:3,892)
  [23] java.awt.LightweightDispatcher.dispatchEvent (Container.java:3,822)
  [24] java.awt.Container.dispatchEventImpl (Container.java:2,010)
  [25] java.awt.Window.dispatchEventImpl (Window.java:1,791)
  [26] java.awt.Component.dispatchEvent (Component.java:3,819)
  [27] java.awt.EventQueue.dispatchEvent (EventQueue.java:463)
  [28] java.awt.EventDispatchThread.pumpOneEventForHierarchy (EventDispatchThread.java:242)
  [29] java.awt.EventDispatchThread.pumpEventsForHierarchy (EventDispatchThread.java:163)
  [30] java.awt.EventDispatchThread.pumpEvents (EventDispatchThread.java:157)
  [31] java.awt.EventDispatchThread.pumpEvents (EventDispatchThread.java:149)
  [32] java.awt.EventDispatchThread.run (EventDispatchThread.java:110)


&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-6737382497203606010?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/6737382497203606010/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=6737382497203606010&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/6737382497203606010'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/6737382497203606010'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2008/01/tech-ideas-for-optimizing-design.html' title='[TECH] Ideas for Optimizing Design pattern implementations with &lt;i&gt;Stack Collapsing&lt;/i&gt;'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-4784848552479839745</id><published>2008-01-05T20:39:00.000-08:00</published><updated>2008-01-05T20:48:56.794-08:00</updated><title type='text'>[TECH] Association rules of by Data Mining (TM Algorithm) on Cancer Data.</title><content type='html'>&lt;p&gt; I have datamined the Cancer data at http://breastscreening.cancer.gov/rfdataset/ using the TM(Transaction Mapping) and FP-Growth algorithm, this is what I have done
to mine the association rules.
&lt;/p&gt;
&lt;p&gt;
1. Randomly partition the data into two parts, I partitioned the 
data into part1 of size = 148458 records, part2 of
size = 153897. 
&lt;br&gt; 
2. Used the part1 (148458 records) and found association rules of
support &gt;=0.4 and
confidence &gt;=0.4 , I got 72 rules from this.
&lt;br&gt;

3. For each of the rule (in step 2) I found the support and confidence
of each of the rules in
part2, it looks like the support and confidence is close to the
support and confidence in
training data (part1).
&lt;br&gt;
&lt;/p&gt;

&lt;pre&gt;
&lt;font size=3&gt;
The 72 rules of step1 [&lt;a href="http://www.engr.uconn.edu/~vkk06001/CancerDataMining/rules.txt"&gt;
http://www.engr.uconn.edu/~vkk06001/CancerDataMining/rules.txt&lt;/a&gt; ]

Support and Confidence of each of this rules in part2
[&lt;a href="http://www.engr.uconn.edu/~vkk06001/CancerDataMining/training_result.txt"&gt;http://www.engr.uconn.edu/~vkk06001/CancerDataMining/training_result.txt&lt;/a&gt; ]

I have made the rules human readable removing all the encoding please
see the rules
[&lt;a href="http://www.engr.uconn.edu/~vkk06001/CancerDataMining/human_readable.txt"&gt;
http://www.engr.uconn.edu/~vkk06001/CancerDataMining/human_readable.txt&lt;/a&gt; ]

These are in the following format
==============RULE:1=================
SUP:0.402 ,CONF:0.412,TRAIN_SUP:0.404,TRAIN_CONF:0.414
{
Diagnosis of invasive breast cancer within one year of the index
screening mammogram = no,
}
IMPLIES ===&gt;
{
Diagnosis of invasive or ductal carcinoma in situ breast cancer within
one year of the index screening mammogram = no,
menopaus = postmenopausal or age&gt;=55,
hispanic = no,
}
==============RULE:2=================

SUP indicates support of this rule in part2 , CONF indicates confidence of this
rule in part2, TRAIN_SUP indicates the support of this rule in part1 and
TRAIN_CONF indicates the confidence of this rule in part1.
&lt;/font&gt;
&lt;/pre&gt;
&lt;p&gt;
These rules may not make any sense for me but it might make sense for a cancer doctor. There are several useful perl programs for people who want to do some
datamining please feel free to use them &lt;a href="http://www.engr.uconn.edu/~vkk06001/CancerDataMining/"&gt;http://www.engr.uconn.edu/~vkk06001/CancerDataMining
&lt;/a&gt;, let me know if you have any questions.
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-4784848552479839745?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/4784848552479839745/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=4784848552479839745&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/4784848552479839745'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/4784848552479839745'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2008/01/tech-association-rules-of-by-data.html' title='[TECH] Association rules of by Data Mining (TM Algorithm) on Cancer Data.'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-2405662161173701449</id><published>2007-12-31T19:31:00.000-08:00</published><updated>2007-12-31T20:11:13.152-08:00</updated><title type='text'>[TECH] An observation to merge upper convex hulls in O(log(n)) time rather than O(log^2(n)).</title><content type='html'>&lt;p&gt; The well known divide and conquer algorithm for finding convex hull for a given set of points, needs to merge smaller hulls H_1 and H_2 for doing this merge the algorithm uses lemma 3.2 (in Book Fundamentals of Computer Algorithms). This lemma essentially finds the tangent line (u,v) in O(log^2(n)) time.
&lt;/p&gt;
&lt;p&gt; We can in fact merge the hulls in more efficient manner, the observation is based on the fact that any point with maximum y-coordinate should definitely be on the hull. Let p1 and p2 be the points in hulls H_1 and H_2 with maximum y-coordinate, then we can safely state that either p1 or p2 will be on the combined hull of H_1 and H_2, we can determine which of these two points lie on the merged hull by comparing the y-coordinates of p1,p2. Among these two the point with maximum y-coordinate will definitely be on the merged hull so one end of the tangent line (u,v) is fixed, the other end of the tangent line can be probed in O(log(n)) time, this basically saves the extra O(log(n)) time which is spent previously in lemma 3.2 for finding the other end of tangent in H_2
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-2405662161173701449?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/2405662161173701449/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=2405662161173701449&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/2405662161173701449'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/2405662161173701449'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2007/12/tech-observation-to-merge-upper-convex.html' title='[TECH] An observation to merge upper convex hulls in O(log(n)) time rather than O(log^2(n)).'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-7813328438448532076</id><published>2007-12-25T15:04:00.000-08:00</published><updated>2007-12-25T15:38:04.254-08:00</updated><title type='text'>[TECH] Hanging simulation..</title><content type='html'>&lt;p&gt; I came across a interesting problem in which the entire simulation 
was hanging just because of an extra non-sensitive always block , in 
the verilog code the statement "always dummy_reg = in;" was causing
both VCS and NC-VERILOG hang. Theoretically speaking irrespective of
what I do in my design the simulation should stop after 500 steps
because I have a "#500 $finish" in the initial block of the module
"TestHangMux", although I got around this problem by removing the
"dummy_reg" totally in the multiplexer, but I still don't understand
why the simulation was hanging irrespective of the "#500 $finish" statement,
is it because we have multiple non-sensitive "always" statement? the LRM(Language
Reference Manual) says that all the "always" blocks execute in parallel just
like parallel processors in that that the statement "#500 $finish" should have
executed in parallel and stop the simulation but why it hangs?
&lt;/p&gt;
&lt;pre&gt;
&lt;code class="codelist"&gt;
&lt;font size=2&gt;
===================================
module HangMux(in,sel,out);
input [1:0]in;
input sel; output out;
reg [1:0]dummy_reg;
reg out;

always @(sel) begin
    case(sel)
        0: out = dummy_reg[0];
        1: out = dummy_reg[1];
    endcase 
end

always dummy_reg = in;


endmodule

module TestHangMux(out_net);
output out_net;
wire out_net;
reg [1:0]in_reg;
reg sel;

initial begin
 in_reg = 2'b01;
 sel = 0;
#500 $finish;
end

always begin
#10 sel = ~sel;
end

HangMux hang_me (in_reg,sel,out_net);
endmodule
==============================
&lt;/font&gt;
&lt;/code&gt;
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-7813328438448532076?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/7813328438448532076/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=7813328438448532076&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/7813328438448532076'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/7813328438448532076'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2007/12/tech-hanging-simulation.html' title='[TECH] Hanging simulation..'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-919125890740151255</id><published>2007-12-21T20:24:00.000-08:00</published><updated>2007-12-25T15:35:21.803-08:00</updated><title type='text'>[TECH] Finding frequent itemsets faster than FP-Growth algorithm</title><content type='html'>&lt;p&gt; I wanted to implement my prime-number mapping intersection algorithm into the TM(Transaction Mapping) Algorithm, I got the FP-Tree implementation from &lt;a href="http://search.cpan.org/~nitram/Tree-FP-0.04/FP.pm"&gt;PERL FP Tree&lt;/a&gt; and was trying to test this on a data of around 300,000 records, it works till 10,000 records
with support and confidence of 0.8 and 0.9 and fails if the number of records &gt; 20,000. I'm not sure if its a perl bug but the following code which is the cause of the problem  seems difficult to understand &lt;br&gt;
&lt;pre&gt;
&lt;code&gt;
&lt;font size=2&gt;
===================================================================
@association_rules = map $_-&gt;[0], (sort {$b-&gt;[1] &lt;=&gt; $a-&gt;[1]} 
      (map [$_, $_-&gt;confidence], @association_rules));      
===================================================================
&lt;/font&gt;
&lt;/code&gt;
&lt;/pre&gt;

I tried to bless the reference $_ but it did'nt work. The following is the
error it gives.
&lt;pre&gt;
&lt;font size=3&gt;
[vamsik@abadon Tree-FP-0.04]$ !perl
perl test_vamsi.pl
Setting support
Mining rules...
Can't call method "confidence" on an undefined value at /usr/lib/perl5/site_perl/5.8.8/Tree/FP.pm line 397, &lt;FILE&gt; line 20001.
&lt;/font&gt;
&lt;/pre&gt;

I need to fix this and send it to the FPTree maintainer tomorrow. I guess
its really a issue to implement the FPTree in perl because of the speed and
time especially when the algorithm need to work on huge data just in my 
case. A good idea is to re-write FPTree in C and extend TM based on that
and compare the results.

&lt;p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-919125890740151255?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/919125890740151255/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=919125890740151255&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/919125890740151255'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/919125890740151255'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2007/12/tech-finding-frequent-itemsets-faster.html' title='[TECH] Finding frequent itemsets faster than FP-Growth algorithm'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-5176239768673047828</id><published>2007-11-28T17:24:00.000-08:00</published><updated>2007-12-25T15:36:05.685-08:00</updated><title type='text'>[TECH] why is ((unsigned long)a_ptr+(unsigned long)b_int) not equals (a_ptr+(unsigned long)b_int)</title><content type='html'>&lt;p&gt;
I was looking at some code today on SGI super computer, and wanted 
to make sure that there are no 32-64 bit problems in the code since
SGI was super computer. I found the following thing to be interesting
&lt;pre&gt;
&lt;font size=2&gt;
&lt;----------------------&gt;
((unsigned long)a_ptr+(unsigned long)b_int)!=
          (a_ptr+(unsigned long)b_int)
&lt;----------------------&gt;
&lt;/font&gt;
&lt;/pre&gt;
That is if I cast both the operands of binary + to (unsigned long)
the value I get from that addition is different from if I cast
just one operand of binary + to (unsigned long), whats the compiler
doing here? since if both the operands to binary + are unsigned long
and the value(no.of bits) could be larger than sizeof(unsigned long)
is it the reason why I get different values here?, I couldn't find
this in FAQ.
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-5176239768673047828?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/5176239768673047828/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=5176239768673047828&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/5176239768673047828'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/5176239768673047828'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2007/11/tech-why-is-unsigned-longaptrunsigned.html' title='[TECH] why is ((unsigned long)a_ptr+(unsigned long)b_int) not equals (a_ptr+(unsigned long)b_int)'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-7832241670458452261</id><published>2007-11-23T19:27:00.000-08:00</published><updated>2007-11-23T19:38:44.986-08:00</updated><title type='text'>[TECH] Verilog incompatabilities between 'ncverilog' and 'vcs'</title><content type='html'>&lt;p&gt;
Thanksgiving vacation may be fun for some but its really not fun if your IT department
is taking a break, our Synopsys License server has been down for last few days all my
emails are vain no one responds. I used 'vcs' to compile all my verilog code all these
days, now I'm helpless.....how can we solve this problem.&lt;br&gt;
I want to get some synthesis metrics for the Sequence Alignment design, although Synopsys License server is down looks like the Cadence License server is up :). Thats
good news but whats equivalent to 'vcs' in Cadence....'NCVERILOG' I found 'ncverilog'
and try to compile all my design modules now the in-compatibility, NC-Verilog don't like to see any thing in the module description until all the port list is filled up,but vcs scans the code of the entire declaration list before checking if the port list is filled up (I guess thats the way it should be the algorithm should be very general). I like 'vcs' and not impressed by 'NC-Verilog' but unfortunately I have to live with it for few more days, by porting my verilog code...sounds crazy I have ported code on machines different processors but the way these compilers are build is
really crazy....
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-7832241670458452261?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/7832241670458452261/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=7832241670458452261&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/7832241670458452261'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/7832241670458452261'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2007/11/tech-verilog-incompatabilities-between.html' title='[TECH] Verilog incompatabilities between &apos;ncverilog&apos; and &apos;vcs&apos;'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-4067915582530978289</id><published>2007-11-21T04:30:00.000-08:00</published><updated>2007-11-21T04:40:41.240-08:00</updated><title type='text'>[TECH] Iso-spectral and Non-Isomorphic Graphs (PINGS)</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_vefOGWfEeww/R0QmTDbtbwI/AAAAAAAAAHY/iNcjO1_g_bA/s1600-h/PING5.jpg"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;" src="http://4.bp.blogspot.com/_vefOGWfEeww/R0QmTDbtbwI/AAAAAAAAAHY/iNcjO1_g_bA/s320/PING5.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5135271583890108162" /&gt;&lt;/a&gt;
&lt;p&gt; Having the same spectrum for the adjacency matrix is a Necessary but not 
sufficient condition for Graph Isomorphism, our recent algorithmic result states a conjecture that every graph is characterized by its Family of Spectra, rather than
Spectrum itself. 
&lt;/p&gt;

&lt;p&gt; I have been doing some work on efficient algorithms for generating PINGS (Pair of
Isospectral and Non-Isomorphic Graphs), I wrote a program which can search for PINGS
in a very efficient manner, I found some interesting results there are no PINGS
for n=2,3,4 for n=5 we have one PING (see the picture) it happens that its the only PING for n=5 it has a symmetric spectrum of {-2,0,0,2}. Also I found a very interesting result that there cannot be more than two INGS(Iso-Spectral 
and non-isomorphic graphs) which share the same spectrum so if INGS exists they
exist as PINGS, I was curious if they exist something like XINGS X=P or T or ...
but it happens its just P (only a pair). There are 5 PINGS for n=6 for n=7 there
are 55 PINGS see the list at &lt;a href="http://trinity.engr.uconn.edu/~vamsik/n.7"&gt;
http://trinity.engr.uconn.edu/~vamsik/n.7&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/6902761-4067915582530978289?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/4067915582530978289/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=4067915582530978289&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/4067915582530978289'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/4067915582530978289'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2007/11/tech-iso-spectral-and-non-isomorphic.html' title='[TECH] Iso-spectral and Non-Isomorphic Graphs (PINGS)'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_vefOGWfEeww/R0QmTDbtbwI/AAAAAAAAAHY/iNcjO1_g_bA/s72-c/PING5.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-8456036020797302849</id><published>2007-11-10T23:25:00.000-08:00</published><updated>2007-11-10T23:34:35.364-08:00</updated><title type='text'>[TECH] Design of my first chip (A sequence Aligner O(n) space implementation)</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_vefOGWfEeww/RzawddpVSoI/AAAAAAAAAHQ/dy-wY7rmWow/s1600-h/test2_all_signals.GIF"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;" src="http://3.bp.blogspot.com/_vefOGWfEeww/RzawddpVSoI/AAAAAAAAAHQ/dy-wY7rmWow/s320/test2_all_signals.GIF" border="0" alt=""id="BLOGGER_PHOTO_ID_5131482845655943810" /&gt;&lt;/a&gt;
&lt;p&gt;Designing hardware is totally different from writing software, writing verilog code
is totally different from writing software 'C' programs, often a software engineer tries to solve the problems using loops,arrays etc.. unfortunately implementing the same algorithm in hardware is totally different. I had my experience in designing a chip (verilog code) for finding edit distance between two strings this has a well known
O(n^2) dynamic programming based algorithm. Now the trick is how do you create a hardware which realizes the two for loops in the O(n^2) algorithm, after quite a bit of
thinking I came up with a solution which involves just SHIFTERS,MULTIPLEXERS and ADDERS. I'm not aware of any such hardware implementation of edit distance algorithm till now...I'm tempted to share my design diagram on the blog but I cannot do it until it gets published some where....
&lt;/p&gt;
&lt;p&gt; My design flow is as follows (verilog)-&gt;vcs; (libs+verilog)-&gt;Design Compiler; and I will use cadence virtuso (ICFB) for my placement and routing and also extraction; Will use HSPICE/Nanosim and spectre for postlayout simulation.
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-8456036020797302849?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/8456036020797302849/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=8456036020797302849&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/8456036020797302849'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/8456036020797302849'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2007/11/tech-design-of-my-first-chip-sequence.html' title='[TECH] Design of my first chip (A sequence Aligner O(n) space implementation)'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_vefOGWfEeww/RzawddpVSoI/AAAAAAAAAHQ/dy-wY7rmWow/s72-c/test2_all_signals.GIF' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-8502359825761260052</id><published>2007-10-27T17:14:00.001-07:00</published><updated>2007-12-25T15:30:56.635-08:00</updated><title type='text'>[TECH] A simple O(n^2) time algorithm to construct the Ultra-metric trees.</title><content type='html'>&lt;p&gt; Given a matrix 'D' which is symmetric an Ultra-metric tree 'T' is a binary
tree with internal nodes corresponding to D(i,j) and leaves corresponding to 
rows in the matrix 'D', and a path from the root to the leaf must be strictly decreasing (Ultra-metric tree). Also D(i,j) is the lowest common ancestor for
'i' and 'j'. &lt;br&gt;
The problem is given 'D' we need to figure out corresponding 'T'.
&lt;/p&gt;
&lt;p&gt; The well know fact about the Ultra-metric trees is that if 
we take any 3 leaves i,j,k the maximum is not unique (e.x D(i,j)=5,
D(j,k)=6,D(i,k)=5) we have D(i,j) and D(i,k) having same value.&lt;br&gt;
How do we test if D is Ultra-metric?&lt;br&gt;
&lt;ul&gt;
&lt;li&gt; A trivial solution is O(n^3).
&lt;li&gt; The &lt;a href="http://www.cs.ucdavis.edu/~gusfield/ultraerrat/ultraerrat.html"&gt;Errata&lt;/a&gt; shows construction of Ultra-metric trees in O(n^2) and asks a question if we can 
check for the Ultra-metric property in O(n^2) ? which my next item answers affirmatively.
&lt;li&gt; My observation is we can partition the leaves of the ultra-metric tree with out
any need of building a complete weighted graph as in Gusfields solution, one fact is that every row in D is going to have a maximum (global) we don't need to spend O(n^2) (comparing all the elements in the matrix D) to find one. The algorithm below we perform such a check if an ultra-metric tree exists and also builds one.
&lt;pre&gt;
&lt;font size=3&gt;
L = {1,2,....n};
UltraMetricPartition(L){
 i = select_a_random_element_in(L) ;
 max = find_max(D(i,*)); /*Takes linear time*/
 /*max = D(i,q) &amp;&amp; q should be in L*/
 Part_q = {};
 Part_i = {};
 foreach(j in L){
    if(j!=i){
        if(D(j,i)&lt;=max &amp;&amp; D(j,q)==max){
             Part_i += {j};
        }else if(D(j,q)&lt;=max &amp;&amp; D(j,i)==max){
             Part_q += {j};
        }else{
           printf("D is not ultra-metric");
           return 0;
        }
    }
 }
 UltraMetricPartition(Part_i);
 UltraMetricPartition(Part_q);

}
&lt;/font&gt;
&lt;/pre&gt;
&lt;/ul&gt;
Running time would be T(n) = T(n-k) + T(k) + O(n), clearly its quadratic O(n^2). 
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-8502359825761260052?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/8502359825761260052/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=8502359825761260052&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/8502359825761260052'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/8502359825761260052'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2007/10/tech-simple-on2-time-algorithm-to.html' title='[TECH] A simple O(n^2) time algorithm to construct the Ultra-metric trees.'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-2627337084312909143</id><published>2007-10-16T17:50:00.000-07:00</published><updated>2007-10-16T18:01:43.825-07:00</updated><title type='text'>[TECH] Implementing Reliability(FEARLESS) on top of FUSE</title><content type='html'>&lt;p&gt; &lt;a href="http://fuse.sf.net"&gt;FUSE&lt;/a&gt; is a user space file system implementation 
framework, the file system implementation can run as a user process and interact with the VFS of the kernel through a named pipe /dev/fuse, FUSE comes by default with all kernels &gt; 2.6.8
&lt;/p&gt;

&lt;p&gt; "Any data which persists on just one disk is very unreliable" , I was talking with Rohit couple of days back and he compared disk as an "Electric Bulb", and u know about the filament in the bulb it can go off any time. So what do you think of your laptop how many disk's does it have? JUST ONE.....thats extremely unreliable until and unless your system is not backed up every day. So how can we get the reliability achieved by RAID (Redundant Array of Inexpensive Disks) ? the answer is persist what is called an "ACTIVE DATA" on some thing like FLASH memory and we can integrate this with a backup mechanism to get good reliability for personal storage devices like laptops. FEARLESS is idea which came up with this reliability for personal storage devices, you can read &lt;a href="http://portal.acm.org/citation.cfm?id=1228291.1228301"&gt;paper&lt;/a&gt; by Dr.Chandy.
&lt;/p&gt;

&lt;p&gt; Our IDEA is now to realize FEARLESS using FUSE and rsync (for backup), so FEARLESS would be just another file system similar to SSHFS but very reliable
&lt;/p&gt;

Cheers!&lt;br&gt;
Vamsi.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-2627337084312909143?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/2627337084312909143/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=2627337084312909143&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/2627337084312909143'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/2627337084312909143'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2007/10/tech-implementing-reliabilityfearless.html' title='[TECH] Implementing Reliability(FEARLESS) on top of FUSE'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-4520748955528518655</id><published>2007-10-08T14:13:00.000-07:00</published><updated>2007-10-10T13:12:40.417-07:00</updated><title type='text'>[BDAY] unsigned char age  = age++;</title><content type='html'>&lt;p&gt; Today happened to be my birthday, we just need an &lt;b&gt;unsigned char&lt;/b&gt;
to represent age, can you tell whats wrong with the code in the title (or below?).
&lt;/p&gt;
&lt;pre&gt;
static unsigned char age;

void Birthday(){
  age = age++;
}
&lt;/pre&gt;
&lt;p&gt;
Looks like the Standard 'C' says the value in the age is undefined ? because the assignment (=) is not a sequence point where the side effects (++,--) are settled. That
can make the age of the person remain the same or increase it by one its ambiguous.
&lt;/p&gt;


Cheers!
&lt;br&gt;
Vamsi.
&lt;a href="http://dna.engr.uconn.edu/~vamsik"&gt;google index this&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-4520748955528518655?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/4520748955528518655/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=4520748955528518655&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/4520748955528518655'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/4520748955528518655'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2007/10/bday-unsigned-char-age-age.html' title='[BDAY] unsigned char age  = age++;'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-1975705258248518812</id><published>2007-10-05T14:36:00.000-07:00</published><updated>2007-10-05T14:52:42.799-07:00</updated><title type='text'>[TECH] O(n^2/(log(n)^2)) time algorithm for finding edit distance. [How does it feel when you know have reinvented the wheel :(]</title><content type='html'>&lt;p&gt; Yesterday night during the workout suddenly I thought about what will happen if we
encode the t-vector {-1,0,1}in the Four Russian algorithm as an integer.....the idea was a BOOM! I really felt like EUREKA! just like Archimedes thought when he discovered the law of flotation, I felt that suddenly I speedup the edit-distance dynamic programming algorithm which is O(n^2) by a factor of O(log^2(n)), it was really great
I spend working on the details all special cases and written up every thing was great till then. I discussed the solution with Dr.Wu and found that it was actually solution to some exercise problem in Gusfield's book which says that in a RAM based computation model the copy of vector 't' can be done in O(log(t)) time.
&lt;/p&gt; 
&lt;p&gt; How do you feel when you know some thing which you are exited just slips from you ?
its very painful and its like killing you, but thats the way the world is its full of SMART people and any path which you are taking might have been taken before........
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-1975705258248518812?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/1975705258248518812/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=1975705258248518812&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/1975705258248518812'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/1975705258248518812'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2007/10/tech-on2logn2-time-algorithm-for.html' title='[TECH] O(n^2/(log(n)^2)) time algorithm for finding edit distance. [How does it feel when you know have reinvented the wheel :(]'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-8254165068018790900</id><published>2007-09-20T23:44:00.000-07:00</published><updated>2007-09-20T23:53:20.135-07:00</updated><title type='text'>[TECH] Generic Randomized Quicksort algorithm.</title><content type='html'>&lt;p&gt;
Adding to my own collection of generic data structures, today I added a
generic Randomized Quicksort algorithm, I need a good sorting routine 
in the SAPE algorithm for sorting distances. I want to makesure that
it can sort any kind array (array of char's,int's,float's,double's and
also structures).
&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;
/*A generic Randomized Quicksort:
 *The key idea of being generic comes
 *from the fact that you take a memory 
 *block and size of each element and 
 *sort this memory chunk, so we always
 *deal with address's.
 *
 *
 *Sep 20,2007 vamsik@engr.uconn.edu
 **/
#include&lt;stdlib.h&gt;
#include&lt;stdio.h&gt;
#include&lt;time.h&gt;
#include&lt;assert.h&gt;
#include&lt;string.h&gt;
#include "RandQsort.h"

/*INPUT: swap_routine,compare_routine
 * swap_routine: The algorithm gives the 
 * (void *)'s swap_routine of two things
 * which need to be swapped.
 *
 * compare_routine: The algorithm gives the
 * (void *)'s to the compare_routine its 
 */
static char QSORT_RAND_SEED=0;
static void (*swap_routine)(void *,void *) = NULL;
static unsigned char (*compare_routine_l)(void *,void *) = NULL;
static unsigned char (*compare_routine_g)(void *,void *) = NULL;
static time_t t_rqsort;
unsigned int GetPivot(void){
 if(!QSORT_RAND_SEED){
  assert(((time_t)-1)!=time(&amp;t_rqsort));
  srand(t_rqsort);
  fprintf(stdout,"Setting RAND_SEED to %d \n",t_rqsort);
  QSORT_RAND_SEED=1;
 }
 return ((unsigned int)rand());
}
/*Avoid loosing the pivot during swaps*/
void UpdatePivot(void **pivot,void **i,void **j){
 if(*i==*pivot){
  *pivot = *j;
 }else if(*j == *pivot){
  *pivot = *i;
 }
}
/*Take a memory address location and size 
of the data items[Inplace partition]*/
static void PartitionWithPivot(void* start,void* end,
unsigned int dsize){
 void *pivot=NULL;
 void* i=start;
 void* j=end;
 unsigned int p_index = GetPivot();
 if(start==end){
  return;
 }
 p_index %= (((unsigned int)(end-start))/dsize);
 pivot=(void *)((unsigned long)start+
  (unsigned long)((p_index)*dsize));
 while(i&lt;j){
  /*Find a element greater than the pivot*/
  while(compare_routine_l(i,pivot) &amp;&amp; (i&lt;=end)){
   i+=dsize;
  }
  /*Find a element less than the pivot*/
  while(!compare_routine_l(j,pivot) &amp;&amp; (j&gt;=start)){
   j-=dsize;
  }
  /*Swap i,j*/
  if(i&lt;j){
   /*Make sure we update the pivot.*/
   UpdatePivot(&amp;pivot,&amp;i,&amp;j);
   swap_routine(i,j);
  }
 }
 /*i is the pivot element at (i-(dsize)) */
 if((i-dsize)&gt;start){
  swap_routine(pivot,(void *)(i-dsize));
  PartitionWithPivot(start,(void *)(i-(2*dsize)),
  dsize);
 }
 if((i+dsize)&lt;=end){
  PartitionWithPivot(i,end,dsize);
 }
}
/*Call PartitionWithPivot recursively*/
void RandQsort(void *start,void *end,unsigned int dsize,
void_void_fptr sroutine,bool_void_fptr croutine_l){
 swap_routine = sroutine;
 compare_routine_l = croutine_l;
 assert(swap_routine &amp;&amp; compare_routine_l);
 PartitionWithPivot(start,end,dsize);
}
#ifdef UNIT_TEST_RQSORT
/*TEST1:Testing for chars*/
unsigned char CharCompare_L(void *a,void *b){
 return ((*((char *)a))&lt;=(*((char *)b)))?1:0;
}
unsigned char CharCompare_G(void *a,void *b){
 return ((*((char *)a))&gt;=(*((char *)b)))?1:0;
}
void CharSwap(void *a,void *b){
 char temp=*((char *)a);
 *((char *)a) = *((char *)b);
 *((char *)b) = temp;
}
void TestCharSort(){
 char *data = malloc(sizeof(char)*10);
 char test_buffer[64];
 unsigned int i,j,k;
 time_t test_time;
 for(i=0;i&lt;10;i++){
  data[9-i] = '0'+i;
 }
 /*Randomize the input data*/
 time(&amp;test_time);
 srand(test_time);
 for(i=0;i&lt;100;i++){
  j=(rand())%10;
  k=(rand())%10;
  test_buffer[63]=data[j];
  data[j]=data[k];
  data[k]=test_buffer[63];
 }
 /*Print the buffer*/
 if(strncpy(test_buffer,data,10)!=test_buffer){
  fprintf(stderr,"SYSTEM_ISSUE:Copy into buffer failed\n");
 }else{
  test_buffer[10]='\0';
  fprintf(stdout,"%s\n",test_buffer);
 }
 RandQsort((void *)data,(void *)(data+9),1,
 CharSwap,CharCompare_L);
 for(i=0;i&lt;10;i++){
  if(data[i]-('0'+i)){
   printf("Test Failed for Chars\n");
   printf("Expecting %d but found %d\n",i,
    ((unsigned int)data[i]-'0'));
   exit(1);
  }
 }
 test_buffer[0]='\0';
 if(strncpy(test_buffer,data,10)!=test_buffer){
  fprintf(stderr,"FAILED_TEST: UNABLE TO COPY BUFFER\n");
  fprintf(stderr,"MAY_BE_SOME_MEMORY_CORRUPTION_DURING_SORT\n");
  exit(1);
 }else{
  fprintf(stdout,"%s\n",data);
 }
 printf("Test Passed For Chars....\n");
}

unsigned char FloatCompare(void *a,void *b){
 int a_int = (int)((*(float *)a)*10000);
 int b_int = (int)((*(float *)b)*10000);
 return (a_int&lt;=b_int)?1:0;
}
void FloatSwap(void *a,void *b){
 float temp;
 temp = *((float *)a);
 *((float *)a) = *((float *)b);
 *((float *)b) = temp;
}

#include&lt;math.h&gt;
void TestFloatSort(){
 float *data = malloc(sizeof(float)*10);
 float temp;
 unsigned int i,j,k;
 time_t test_time;
 for(i=0;i&lt;10;i++){
  data[9-i] = (float)sin(i);
 }
 /*Randomize the input data*/
 time(&amp;test_time);
 srand(test_time);
 for(i=0;i&lt;100;i++){
  j=(rand())%10;
  k=(rand())%10;
  temp=data[j];
  data[j]=data[k];
  data[k]=temp;
 }
 /*Print the buffer*/
 for(i=0;i&lt;10;i++){
  printf("%f ",data[i]);
 }
 printf("\n");
 printf("The # of elements %d\n",(&amp;data[9]-&amp;data[0])/4);
 RandQsort((void *)&amp;data[0],(void *)&amp;(data[9]),4,
 FloatSwap,FloatCompare);
 for(i=1;i&lt;10;i++){
  if(!FloatCompare((void *)&amp;data[i-1],(void *)&amp;data[i])){
   printf("Test FAILED comparing %f , %f\n",
   data[i-1],data[i]);
   exit(1);
  }
 }
 for(i=0;i&lt;10;i++){
  printf("%f ",data[i]);
 }
 printf("\n");
 printf("Test Passed For Floats....\n");
}

/*Test for floats*/
int main(){
 TestCharSort();
 TestFloatSort();
 exit(0);
}
#endif

&lt;/code&gt;
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-8254165068018790900?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/8254165068018790900/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=8254165068018790900&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/8254165068018790900'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/8254165068018790900'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2007/09/tech-generic-randomized-quicksort.html' title='[TECH] Generic Randomized Quicksort algorithm.'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-2309912487493628357</id><published>2007-09-08T11:58:00.000-07:00</published><updated>2007-09-08T12:08:33.252-07:00</updated><title type='text'>[TECH] Perl template toolkit and Bugzilla</title><content type='html'>&lt;p&gt; I have now done with the customization of Bugzilla for our internal needs,
to keep track of things. The core of the idea of templates was simple &lt;br&gt;
&lt;ul&gt;
&lt;li&gt; Seperate the presentation from the code
&lt;/ul&gt;


The good thing about using Perl + TTK is that the split (presentation code and actual 
code) is very wide compared to any other framework which I'm aware at least from my past experience. I have used the following frameworks previously. Its a very useful add on as a skill learn more about &lt;a href="http://www.template-toolkit.org/"&gt; http://www.template-toolkit.org&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt; Have few things to fix today, Add code to SAPE_1 with the new
Center of Gravity algorithm.
&lt;/p&gt;

Cheers!&lt;br&gt;
Vamsi&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-2309912487493628357?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/2309912487493628357/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=2309912487493628357&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/2309912487493628357'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/2309912487493628357'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2007/09/tech-perl-template-toolkit-and-bugzilla.html' title='[TECH] Perl template toolkit and Bugzilla'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-7421670107696487749</id><published>2007-09-03T09:38:00.000-07:00</published><updated>2007-09-03T09:46:43.278-07:00</updated><title type='text'>[TECH] Bugzilla Internals</title><content type='html'>&lt;p&gt; Got back to work today !&lt;/p&gt; &lt;br&gt;
&lt;p&gt; Was looking at the Bugzilla's perl code to extend it for some of my internal work, I found that it was a expert level perl code (Object oriented) they are using several things which I never used, It was a good learning experience.&lt;/p&gt;&lt;br&gt;
&lt;p&gt; I want extract few concepts from this code &lt;br&gt;
&lt;ul&gt;
&lt;li&gt; How do all these websystem's avoid hard coding of HTML inside the code which 
generate's HTML dynamically (I know its kind of servlet and JSP/ASP situation), I found that these guys have some mechanism based on templates which avoids hard coding of the HTML inside the dynamic HTML generation code&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
I guess this is the key idea/concept behind all the code which generates HTML dynamically.&lt;br&gt;
&lt;p&gt; I was reading Sriram's "Advanced Perl Programming" I think its a great book
the way he build's up the concepts, I was really impressed by a quote by him in the book &lt;br&gt;
&lt;i&gt;"It is indicative of inflexible procedural design if you find yourself using conditional statements to distinguish between object types"&lt;/i&gt;&lt;/br&gt;
&lt;/p&gt;
&lt;br&gt;
I want to go out to get some lunch today :)
&lt;br&gt;
Cheers!&lt;/br&gt;
Vamsi&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-7421670107696487749?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/7421670107696487749/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=7421670107696487749&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/7421670107696487749'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/7421670107696487749'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2007/09/tech-bugzilla-internals.html' title='[TECH] Bugzilla Internals'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-8626642033177919587</id><published>2007-09-02T04:11:00.000-07:00</published><updated>2007-09-02T04:33:50.929-07:00</updated><title type='text'>[NON-TECH] The old and cold feeling comes back........</title><content type='html'>&lt;p&gt;I visited India from Aug10-Aug30 all those 20 days were great most of the time I was in Hyderabad, life was great in India except that there was a lot of pollution especially in Hyderabad and also overcrowded places especially because of the booming IT industry.
&lt;/p&gt;

&lt;p&gt; Some of the things I noticed have changed in India from the time I left&lt;br&gt;
&lt;ul&gt;
&lt;li&gt; The money spending power of people have increased a lot, I heard that the average
salary for a undergrad is now around 5.0 lack/annum ($12.5k ), this was a huge increase
compared to average of 2.4 lack/annum ($6k) which is more than double.
&lt;li&gt; The cost of living has gone up from the last year, I remember that I used to eat in a hotel called Kakatiya in Ameerpet a full meal for Rs 26.00/- the same costs Rs 32.00/- now. A bottle of mineral water went up to 13.00/- from 10.00/-
&lt;li&gt; There have been a lot of malls/multiplexes mushrooming every where in Hyderabad. I saw several existing houses being demolished and new multiplexes and malls are taking their place.
&lt;li&gt; Looks to me that almost every thing is available in India now. I was shocked to see PSP in Music World, I guess people are now getting into games market and if its true India will be a great market for selling computer games.
&lt;li&gt; In India cell phone has become a revolution I find that almost every one in the country has a mobile phone, thanks to Reliance which had a vision of making cell phones affordable to every one.
&lt;/ul&gt;
&lt;/p&gt;

&lt;p&gt; All these things are fine but my old feeling comes back again, I remember all those dilemma which I was having when I just landed in U.S went to riverside and came to UCONN, all those feeling are fresh in my mind. Well that COLD FEELING of missing India comes back again I don't know why but its back.....I feel sorry for myself I don't know what I'm up to in my life.....But I'm transforming my self to be better than what I used to be, and I believe that what ever is happening is just transformation for something better........as usual Connecticut is very lonely very quiet place, I used to go for jogging in India every day around 7-8 a.m in the morning.....&lt;/p&gt;

Well its life and lets face it without fear!&lt;br&gt;
Cheer!
Vamsi.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-8626642033177919587?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/8626642033177919587/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=8626642033177919587&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/8626642033177919587'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/8626642033177919587'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2007/09/non-tech-old-and-cold-feeling-comes.html' title='[NON-TECH] The old and cold feeling comes back........'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-6154561975110817398</id><published>2007-08-02T14:55:00.000-07:00</published><updated>2007-08-02T15:07:49.593-07:00</updated><title type='text'>[NON-TECH] From Dennis Ritchie's Bio....</title><content type='html'>Some times there are far too many things for people to decide on what to do? how to excel? what exactly is our strength ? . The problem here is that people tend to be *good* in several things, but being *good* is not enough if a person who is *good* compares to some of the smartest people in the same field. All this thoughts haunt every one I found the following from &lt;b&gt; Dennis Ritchie's &lt;/b&gt; biography &lt;a href="http://cm.bell-labs.com/cm/cs/who/dmr/bigbio1st.html"&gt; here &lt;/a&gt; &lt;br&gt;
&lt;b&gt;&lt;i&gt;"My undergraduate experience convinced me that I was not smart enough to be a physicist, and that computers were quite neat. My graduate school experience convinced me that I was not smart enough to be an expert in the theory of algorithms and also that I liked procedural languages better than functional ones."&lt;/i&gt;&lt;/b&gt;
&lt;br&gt;
see that line &lt;b&gt;"I was not smart enough to be an expert in the theory of algorithms....."&lt;/b&gt; I guess any person at his position would never say that (even though he is not smart), I really felt this guy is TRULY a GREAT GUY, he had to be really modest and humble to say such things......
&lt;br&gt;
Cheers!&lt;br&gt;
Vamsi.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-6154561975110817398?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/6154561975110817398/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=6154561975110817398&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/6154561975110817398'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/6154561975110817398'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2007/08/non-tech-from-dennis-ritchies-bio.html' title='[NON-TECH] From Dennis Ritchie&apos;s Bio....'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-5099676083408369433</id><published>2007-07-03T09:04:00.000-07:00</published><updated>2007-07-03T09:06:23.023-07:00</updated><title type='text'>[TECH] My Quick VIM tip of the day</title><content type='html'>&lt;p&gt;
To add something to every line in a file with vim&lt;br&gt;
&lt;b&gt;:s/^/something/gc&lt;/b&gt;
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-5099676083408369433?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/5099676083408369433/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=5099676083408369433&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/5099676083408369433'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/5099676083408369433'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2007/07/tech-my-quick-vim-tip-of-day.html' title='[TECH] My Quick VIM tip of the day'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-4772942539200728024</id><published>2007-07-03T00:35:00.000-07:00</published><updated>2007-07-03T00:51:42.722-07:00</updated><title type='text'>[TECH] FORTRAN awful stories</title><content type='html'>&lt;p&gt;
Well first time in my life had a chance to look at a messy FORTRAN code. I used
some of the CRAY style &lt;b&gt;POINTER(ptr,pointee)&lt;/b&gt; stuff and it looked to me its
really weird.&lt;br&gt;

There are several crazy things which got me irritated while writing the code&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;Can you beleive that when you write FORTRAN code you must make sure that every
line is no more than 80 chars, some one told me that FORTRAN had this because of 
the punch cards whose size limit come from there.
&lt;li&gt;Really strange that FORTRAN has no concept of global variables, and its a real
pain especially when you have SUBROUTINES you will have to make a COMMON block and
copy all the definitions into the SUBROUTINE, real big pain, thanks to INCLUDE which
saves us.
&lt;li&gt;I found they there seems to be a huge variations in the standards of FORTRAN, there
are several things 'g77' did'nt support, I used 'ifort' intel fortran compiler.
&lt;li&gt;Really had tough time figuring out the format specifiers equivalent to 'printf' for
'WRITE(6,*)'
&lt;li&gt;Last but not least FORTRAN dont have a ';' at the end of statement and its really
pain when you are a 'C' programmers.
&lt;li&gt;Last++ IF conditions seems to require THEN , I figured out after writing several
lines of code :(, really an Experience of writing programs in legacy languages and a real
test for a real programmer.
&lt;/ul&gt;
&lt;/p&gt;

&lt;p&gt;
I forgot I wanted to keep track of this piece of code, to
close all the files in a program with calling close(fd) in
each of fd's
&lt;pre&gt;
fp = tmpfile();
fp-&gt;_chain = stderr;
fpclose(fp);
fp = NULL;
&lt;/pre&gt;
&lt;/p&gt;

Take care guys!&lt;br&gt;
Cheers!&lt;br&gt;
Vamsi&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-4772942539200728024?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/4772942539200728024/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=4772942539200728024&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/4772942539200728024'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/4772942539200728024'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2007/07/tech-fortran-awful-stories.html' title='[TECH] FORTRAN awful stories'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-1035962458098520133</id><published>2007-06-28T13:19:00.000-07:00</published><updated>2007-06-28T13:34:19.386-07:00</updated><title type='text'>[TECH] Memory corruption and  format specifiers "%s%c" is different from "%s%1s"</title><content type='html'>&lt;p&gt;
I have been fixing several issues last few weeks, and the following 
issue in someone's code is a clear test for understanding differences
between strings and char's. 
&lt;/p&gt;

&lt;p&gt;
On the first look &lt;b&gt;"%s%c"&lt;/b&gt; and &lt;b&gt;"%s%1s"&lt;/b&gt; seem 
very similar, but unfortunately NO! and they can create some
nasty runtime bugs corrupting your variables, suppose the code
existing in someone's code like this.
&lt;pre&gt;
void BuggyScanner(){
    char buf[MAX_SIZE];
    int a;
    char b;
    scanf("%d",&amp;a);
    scanf("%3s%1s",buf,&amp;b);
    printf("a=%d buf=%s b=%c\n",a,buf,b);
}
&lt;/pre&gt;
The format specifier is really a blunder as scanf "%1s" is going to write
beyond one byte (the extra '\0' which gets padded for strings)at the 
address of 'b' , since 'buf','a','b' are on the stack writing one byte 
beyond the address of 'b' can do really nasty stuff.
&lt;ul&gt;
&lt;li&gt; Just as in this corrupted the variables.
&lt;li&gt; Potentially corrupt the return address of the function, creating
a great security bug.
&lt;/ul&gt;

Be Careful guys!
Vamsi.

&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-1035962458098520133?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/1035962458098520133/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=1035962458098520133&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/1035962458098520133'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/1035962458098520133'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2007/06/tech-memory-corruption-and-format.html' title='[TECH] Memory corruption and  format specifiers &quot;%s%c&quot; is different from &quot;%s%1s&quot;'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-8526426715589583171</id><published>2007-06-19T00:16:00.000-07:00</published><updated>2007-06-19T00:20:44.658-07:00</updated><title type='text'>[BOOKS] List of books I want to buy when I'm in india</title><content type='html'>&lt;p&gt;
1. The Practice of Programming (Paperback)
by Brian W. Kernighan (Author), Rob Pike (Author)

2. Programming Pearls (2nd Edition) (Paperback)
by Jon Bentley (Author).

3. Algorithms on Strings, Trees and Sequences: 
Computer Science and Computational Biology (Hardcover)

&lt;/p&gt;

I'll keep adding to this list...&lt;br&gt;
Life has been through a lot of code in
Matlab/Octave, Perl and C.

Cheers!
Vamsi.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-8526426715589583171?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/8526426715589583171/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=8526426715589583171&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/8526426715589583171'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/8526426715589583171'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2007/06/books-list-of-books-i-want-to-buy-when.html' title='[BOOKS] List of books I want to buy when I&apos;m in india'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-6320110868586667540</id><published>2007-06-09T23:55:00.000-07:00</published><updated>2007-06-10T00:04:58.235-07:00</updated><title type='text'>[Perl] Don't nest your regular expressions when you use /g switch</title><content type='html'>&lt;p&gt;
I have been busy all these days with quite a few things, well the motive of this blog
is to document some of the issues I face in my day to day work.
&lt;/p&gt;

&lt;pre&gt;
while($line =~ /input .*? name="(.*?)" .*? value="(.*?)"/g){
  $param_name = $1;
  $param_value = $2;
  if($param_name =~ /blah/){
    # Do some stuff
  }else{
    #Do some stuff
  }
}
&lt;/pre&gt;

&lt;p&gt;

The above code can go miserably wrong and hard to debug especially when the outer while loop has hundreds of lines of code in it, as you can see when we use '/g' switch in the matching all the matches within a string, make sure that THERE ARE 
NO NESTED REGULAR EXPRESSIONS WHEN USING /g switch

&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-6320110868586667540?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/6320110868586667540/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=6320110868586667540&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/6320110868586667540'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/6320110868586667540'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2007/06/perl-dont-nest-your-regular-expressions.html' title='[Perl] Don&apos;t nest your regular expressions when you use /g switch'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-1366266742887748267</id><published>2007-04-04T14:16:00.000-07:00</published><updated>2007-04-04T14:29:58.185-07:00</updated><title type='text'>I want to become expert in one area</title><content type='html'>Some times I think what I'm I worth of? what can sell myself?
&lt;br&gt;
In fact I did sell myself when I created perl2exe based on my systems knowledge.&lt;br&gt;
few things I think I should concentrate on &lt;br&gt;
1. Parallel Algorithms (they make me to say ahaa!) &lt;br&gt;
2. Systems (Drepper called me Moron! :() &lt;br&gt;
3. EDA (Feels good for me). &lt;br&gt;
&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-1366266742887748267?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/1366266742887748267/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=1366266742887748267&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/1366266742887748267'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/1366266742887748267'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2007/04/i-want-to-become-expert-in-one-area.html' title='I want to become expert in one area'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-6617511895073262168</id><published>2007-03-21T15:27:00.001-07:00</published><updated>2007-03-21T15:34:24.637-07:00</updated><title type='text'>[NON-TECH] Puppy</title><content type='html'>&lt;div style="float: center; margin-left: 10px; margin-bottom: 10px;"&gt; &lt;a href="http://www.flickr.com/photos/vamsi/429726060/" title="photo sharing"&gt;&lt;img src="http://farm1.static.flickr.com/169/429726060_366c1ab5e4_m.jpg" alt="" style="border: solid 2px #000000;" /&gt;&lt;/a&gt; &lt;br/&gt; Pic of puppy after a fashion show in hyderabad!&lt;br /&gt; &lt;span style="font-size: 0.9em; margin-top: 0px;"&gt;  &lt;a href="http://www.flickr.com/photos/vamsi/429726060/"&gt;IMG_0495&lt;/a&gt;  &lt;br /&gt;  Originally uploaded by &lt;a href="http://www.flickr.com/people/vamsi/"&gt;vamsi&lt;/a&gt;. &lt;/span&gt;&lt;/div&gt;&lt;br clear="all" /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-6617511895073262168?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/6617511895073262168/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=6617511895073262168&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/6617511895073262168'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/6617511895073262168'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2007/03/non-tech-puppy.html' title='[NON-TECH] Puppy'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://farm1.static.flickr.com/169/429726060_366c1ab5e4_t.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-7906055027668222018</id><published>2007-03-08T22:59:00.000-08:00</published><updated>2007-03-08T23:11:49.618-08:00</updated><title type='text'>[Tech] Bitonic Sequences and Bitonic Merge</title><content type='html'>Given a Bitonic Sequence of length 2n (a motonically decreasing (inceasing) and montonically increasing (decreasing).&lt;br&gt;
If we do a Bitonic merge we still of 2 bitonic sequences of length 'n' each.&lt;br&gt;
&lt;pre&gt;
void BitonicMerge(int *array,size_t size){
 int i;
 assert(!(size%2));
 for(i=0;i lessthan size/2;i++){
   if(a[i+(size/2)] &lt; a[i]){
     swap(a[i+(size/2)],a[i]);
   }
}
&lt;/pre&gt;&lt;br&gt;
&lt;p&gt;
What we have is now two Bitonic sequences. Doing a Bitonic sort on a parallel machines 
with 'p' processors and 'n' elements n &gt;&gt; p. Next post I'll post my code to do the 
Bitonic merge of the sequences.
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-7906055027668222018?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/7906055027668222018/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=7906055027668222018&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/7906055027668222018'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/7906055027668222018'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2007/03/tech-bitonic-sequences-and-bitonic.html' title='[Tech] Bitonic Sequences and Bitonic Merge'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-5692575430393913043</id><published>2007-03-05T18:30:00.000-08:00</published><updated>2007-03-05T18:32:54.292-08:00</updated><title type='text'>[FUN] Top 21 things an Indian does after returning from U.S</title><content type='html'>&lt;pre&gt;
(---  Good One!.... Just for fun---)


21. Tries to use credit cards in a road side hotel.


20. Drinks and carries mineral water and always speaks of being health conscious.


19. Sprays deo so that he doesn't need to take bath.


18. Sneezes and says 'Excuse me'.


17. Says "Hey" instead of "Hi".
says "Yogurt" instead of "Curds".
Says "Cab" instead of "Taxi".
Says "Candy" instead of "Chocolate".
Says "Cookie" instead of "Biscuit".
Says "Free Way" instead of "Highway".
Says "got to go" instead of "Have to go".
Says "Oh" instead of "Zero", (for 704, he will say Seven Oh Four Instead of Seven Zero Four)

 

 


16. Doesn't forget to crib about the air pollution. Keeps cribbing every time he steps out.

15. Says all the distances in Miles (Not in Kilo Meters), and counts in Millions. (Not in Lakhs)

14. Tries to figure all the prices in Dollars as far as possible (but deep inside multiplies by 43).


13. Tries to see the % of fat on the cover of a milk pocket.

12. When he needs to say Z (zed), he never says Z (Zed), instead repeats "Zee" several times, and if the other person is unable to get it, then says X, Y Zee(but never says Zed)

11. Writes the date in MM/DD/YYYY. On watching traditional DD/MM/YYYY, says "Oh! British Style!!!!"

10. Makes fun of Indian Standard Time and the Indian Road Conditions.

9. Even after 2 months, complaints about "Jet Lag".

8. Avoids eating spicy food.

7. Tries to drink "Diet Coke", instead of Normal Coke. Eats Pizza instead of Dosa.

6. Tries to complain about any thing in India as if he is experiencing it for the first time. Asks questions etc. about India as though its his first visit to India.

5. Pronounces "schedule" as "skejule", and "module" as "mojule".

4. Looks suspiciously towards any Hotel/Dhaba food.Few more important ones:

3. From the luggage bag, does not remove the stickers of the Airways by which he traveled back to India, even after 4 months of arrival.

2. Takes the cabin luggage bag to short visits in India and tries to roll the bag on Indian Roads.The Ultimate one


1. Tries to begin any conversation with "In US ...." or "When I was in US..."
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-5692575430393913043?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/5692575430393913043/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=5692575430393913043&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/5692575430393913043'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/5692575430393913043'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2007/03/fun-top-21-things-indian-does-after.html' title='[FUN] Top 21 things an Indian does after returning from U.S'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-3803484883716556553</id><published>2007-02-27T17:48:00.000-08:00</published><updated>2007-02-27T17:55:50.093-08:00</updated><title type='text'>[Tech] How to determine the bus bandwidth.</title><content type='html'>&lt;pre&gt;
Hi recently I had a need to find out the bus bandwidth. 
The bus had 64 lines and assume that the speed of the bus is xMHz.
This implies the bandwidth = (no.of lines) * (speed of each line).
Bus Bandwidth = ((64/8)*x*10^6)/(2^20) MBytes/sec.

A simple use of this metric is suppose you have 
SMP(Shared memory processors) with a common bus
and the bandwidth of the bus is 1 GBytes/sec
and you have several processors which have an 
(memory) Instruction bandwidth of 250 MBytes/sec
you cannot connect more than 4 processors to 
saturate the bus.  

&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-3803484883716556553?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://www.pcguide.com/ref/mbsys/buses/funcBandwidth-c.html' title='[Tech] How to determine the bus bandwidth.'/><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/3803484883716556553/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=3803484883716556553&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/3803484883716556553'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/3803484883716556553'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2007/02/tech-how-to-determine-bus-bandwidth.html' title='[Tech] How to determine the bus bandwidth.'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-3070378570467091874</id><published>2007-02-22T00:00:00.000-08:00</published><updated>2007-02-22T00:03:26.676-08:00</updated><title type='text'>[Tech] Pathetic non unix standard matlab editor</title><content type='html'>Well I'm really pissed of this damn editor (matlab editor) , some how I cannot execute my program .m file from the command line so I had to use this matlab's editor to run my program, after using vi for long this is really pathetic, its more worse than windows I just did ctrl+c and ctrl+v it pased some junk instead of the code which I intended to paste.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-3070378570467091874?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/3070378570467091874/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=3070378570467091874&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/3070378570467091874'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/3070378570467091874'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2007/02/tech-pathetic-non-unix-standard-matlab.html' title='[Tech] Pathetic non unix standard matlab editor'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-4476426994266256732</id><published>2007-02-19T21:51:00.000-08:00</published><updated>2007-02-19T21:54:17.633-08:00</updated><title type='text'>[SPICE2LAYOUT] 40% Complete</title><content type='html'>Got back to the SPICE2LAYOUT project updated some Makefiles and added all the skeletal code today. By the mid of the week I should get this up and running, It also needs to have the channel router in that.&lt;br&gt;

Need to get back home and study some stuff for a upcoming Friday jury.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-4476426994266256732?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/4476426994266256732/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=4476426994266256732&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/4476426994266256732'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/4476426994266256732'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2007/02/spice2layout-40-complete.html' title='[SPICE2LAYOUT] 40% Complete'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-8615993173361728346</id><published>2007-02-18T15:29:00.000-08:00</published><updated>2007-02-18T15:35:31.486-08:00</updated><title type='text'>Algorithm for Permuting in place</title><content type='html'>Problem: Given a set of numbers S = 1...n and a permutation PI(S), how can you rearrange elements in S in O(n) time with no extra space. &lt;br&gt;
&lt;br&gt;
I don't like explaining things just code it., here's code below
&lt;pre&gt;
#include&lt;stdio.h&gt;
#include&lt;assert.h&gt;
#include&lt;stdlib.h&gt;
int a[10];
int b[10];

void ResetArray(){
    unsigned int i;
    for(i=0;i&lt;10;i++){
        a[i] = i; 
    }
}
void swap_elements(unsigned int i,unsigned int j){
    int temp;
    temp = a[i];
    a[i] = a[j];
    a[j] = temp;
}
/*b is the swap list*/
void InplacePermute(int *perm){
    unsigned int i;
    for(i=0;i&lt;10;i++){
        if(perm[i] &lt; i){
            perm[i] = perm[perm[i]];
        }
        if(a[i] &lt; i){
            perm[a[i]] = perm[i];
        }
        swap_elements(i,perm[i]);
    }
}

void PrintPermutation(void){
    unsigned int i;
    for(i=0;i&lt;10;i++){
        printf("%d ",a[i]);
    }
}

int main(){
    int runs=10;
    unsigned int i;
    do{
        ResetArray();
        printf("Please enter the permutation of size 10, 10 unique digits from 0-9\n");
        for(i=0;i&lt;10;i++){
         if(scanf("%d",&amp;b[i])&lt;=0){
            break;
         }
         assert(b[i] &gt;=0 &amp;&amp; b[i] &lt;=10);
        }
        if(i&lt;10){
            break;
        }
        InplacePermute(b);
        printf("The permutation is::");
        PrintPermutation();
    }while(1);
}
&lt;/pre&gt;

&lt;br&gt; The following are testcases
&lt;br&gt;
&lt;pre&gt;
7 3 2 1 4 8 9 0 5 6
8 9 1 2 5 6 7 3 4 0
1 2 3 4 5 6 7 8 0 9
1 3 4 8 9 0 7 6 5 2
&lt;/pre&gt;

Well this week has been a little productive, got the space for http://phaedrus.sourceforge.net a library of randomized algorithms
&lt;br&gt;

Have Fun....
Vamsi.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-8615993173361728346?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/8615993173361728346/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=8615993173361728346&amp;isPopup=true' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/8615993173361728346'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/8615993173361728346'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2007/02/algorithm-for-permuting-in-place.html' title='Algorithm for Permuting in place'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-7560837315945270012</id><published>2007-02-15T00:31:00.000-08:00</published><updated>2007-02-15T00:34:32.945-08:00</updated><title type='text'>Passing multidimensional arrays to functions</title><content type='html'>Got enlightened by this today. And realized the following.
&lt;pre&gt;
int a[10][20];

int main(){
 print_array(a); /*results in a crash.*/

}

void print_array(int **a,int i,int j){
 printf("%d",a[i][j]); /*How stupid this can be?*/
}
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-7560837315945270012?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://c-faq.com/aryptr/aryptr.c' title='Passing multidimensional arrays to functions'/><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/7560837315945270012/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=7560837315945270012&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/7560837315945270012'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/7560837315945270012'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2007/02/passing-multidimensional-arrays-to.html' title='Passing multidimensional arrays to functions'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-3738986688917792798</id><published>2007-02-12T12:25:00.000-08:00</published><updated>2007-01-30T22:47:59.727-08:00</updated><title type='text'>I love PHP</title><content type='html'>Have been using PHP with apache to build some stuff really like 
programming in this I'am in love with PHP.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-3738986688917792798?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/3738986688917792798/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=3738986688917792798&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/3738986688917792798'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/3738986688917792798'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2007/02/i-love-php.html' title='I love PHP'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-8215230740145551</id><published>2007-01-30T21:12:00.000-08:00</published><updated>2007-01-30T21:21:29.790-08:00</updated><title type='text'>[Tech] One more reason why MACRO's are Not Preferred over inlines.</title><content type='html'>&lt;pre&gt;
...macro.h....
/***Dangerouse Macro1***/
#define print_int_value_twice(c) do{\
 printf("first time %c second time %c\n",c,c);\
}while(0);

/***Stupid Preprocessor***/
#define my_error(c) do{\
 fprintf(stderr,"Error::");
 fprintf(stderr,c);
 fprintf(stderr,"\n");
 exit(1);
}while(0);

.....macro user ....
j=0;
print_int_value_twice(j++);
/*j incremented twice by the preprocessor*/


/*In this case the preprocessor is stupid 
 not treat the string spanned across several lines
 as a incomplete macro argument and fails compilation.*/
my_error(" My error spans three lines
            line1
            line2");

&lt;/pre&gt;
&lt;br&gt;
&lt;p&gt; Avoid MACROS start using inlines , if you define macros
the users should use them with caution
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-8215230740145551?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/8215230740145551/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=8215230740145551&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/8215230740145551'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/8215230740145551'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2007/01/tech-one-more-reason-why-macros-are.html' title='[Tech] One more reason why MACRO&apos;s are Not Preferred over inlines.'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-2077486005837612189</id><published>2007-01-29T19:45:00.000-08:00</published><updated>2007-01-29T19:55:22.984-08:00</updated><title type='text'>[Personal] I was not good and never have been.....</title><content type='html'>Yes! today I realize my potential, I was never good in fact never have been....I accept my failure.
I'm a looser, I cannot win and never have won and in fact I'm obliged to life for letting me live and eat what ever I want and wear what ever I could....in the midst of bitter shame....I gave up...I don't want to live as a looser...I will soon end my life and this blog may be the last. I was never honest to myself I have things which I don't deserve. And I get emotional for small things...what else a looser can say except bending down head in shame.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6902761-2077486005837612189?l=vkundeti.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://vkundeti.blogspot.com/feeds/2077486005837612189/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6902761&amp;postID=2077486005837612189&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/2077486005837612189'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6902761/posts/default/2077486005837612189'/><link rel='alternate' type='text/html' href='http://vkundeti.blogspot.com/2007/01/personal-i-was-not-good-and-never-have.html' title='[Personal] I was not good and never have been.....'/><author><name>vamsi</name><uri>http://www.blogger.com/profile/06920946350286969217</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='http://photos2.flickr.com/1853391_a74967956e.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6902761.post-4935824069740086701</id><published>2007-01-24T20:00:00.000-08:00</published><updated>2007-01-24T20:26:11.398-08:00</updated><title type='text'>[TECH-NON-TECH] SPICE2LAYOUT should I use BGL?</title><content type='html'>&lt;p&gt;

A Warm Welcome to a great new year 2007! 

This is my first blog after 24 days in the new year. Last time I had written my blog was on Dec 31, 2006, well this was the coldest new year eve I had. I just went to bed on Dec 31 night 2006. Its because I was with puppy taking care of puppy...we were really afraid on whats going to happen next....but it was great what happened next day was really a new begining in a new year things went excatly how I wanted (In fact I did'nt know what would be the best solution and just prayed "God! Please do something so that I will be comfortable after that")...a great going new year 2007 from there on, really had great time in Hyd from Jan-1 to Jan-6.....after that I took pathetic AeroSvit flight (Never Ever Take this shoddy airline) back to JFK, travelled all the way from NewYork to Hartford and took a cab to my place....its quite a tiresome journey to travel from India to U.S, next time I will travel by either BA ,Lufthansa o
