<?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-8743160121835339419</id><updated>2011-12-20T06:34:49.716-08:00</updated><title type='text'>The coding bird</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://evanxg.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8743160121835339419/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://evanxg.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Evance Soumaoro</name><uri>http://www.blogger.com/profile/02386230511527143770</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>3</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8743160121835339419.post-7099735802608375512</id><published>2011-12-16T08:42:00.000-08:00</published><updated>2011-12-16T09:43:05.443-08:00</updated><title type='text'>The fibonacci series using memoization</title><content type='html'>Another algorithm today...&lt;br /&gt;This is the&amp;nbsp;Fibonacci&amp;nbsp;series implemented with memoization .&lt;br /&gt;&lt;br /&gt;&lt;pre class="prettyprint"&gt;int fibonacci(int n){&lt;br /&gt; int prev=0;&lt;br /&gt; int next=1;&lt;br /&gt; int val=0;&lt;br /&gt; for(int i=2;i&amp;lt;=n;i++){&lt;br /&gt;  val=next+prev;&lt;br /&gt;  prev=next;&lt;br /&gt;  next=val;&lt;br /&gt; }&lt;br /&gt; return val;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;Typically, If you are designing a&amp;nbsp;maths&amp;nbsp;library, you would implement a caching&amp;nbsp;mechanism&amp;nbsp;to avoid reprocessing again. A better&amp;nbsp;&amp;nbsp;way&amp;nbsp;in term of performance would be :&lt;br /&gt;&lt;br /&gt;&lt;pre class="prettyprint"&gt;int fibonacci(int n){&lt;br /&gt; static vector&amp;lt;int&amp;gt; cache(0);&lt;br /&gt; //check if we have already processed&lt;br /&gt; if(n&amp;lt;cache.size()){&lt;br /&gt;  cout&amp;lt;&amp;lt;"from cache: ";&lt;br /&gt;  return cache.at(n);&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; //initial values &lt;br /&gt; if(cache.size()==0){&lt;br /&gt;  cache.push_back(0);&lt;br /&gt;  cache.push_back(1);&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; //we calculate the fibonacci from where the cache end to the number requested&lt;br /&gt; for(int i=cache.size()-1;i&amp;lt;=n;i++){&lt;br /&gt;  cache.push_back( cache.at(i) + cache.at(i-1) );&lt;br /&gt; }&lt;br /&gt; cout&amp;lt;&amp;lt;"Calculated : ";&lt;br /&gt; return cache.at(n);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;the cout is&amp;nbsp;embedded&amp;nbsp;for simple debugging.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8743160121835339419-7099735802608375512?l=evanxg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://evanxg.blogspot.com/feeds/7099735802608375512/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://evanxg.blogspot.com/2011/12/fibonacci-series-using-memoization.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8743160121835339419/posts/default/7099735802608375512'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8743160121835339419/posts/default/7099735802608375512'/><link rel='alternate' type='text/html' href='http://evanxg.blogspot.com/2011/12/fibonacci-series-using-memoization.html' title='The fibonacci series using memoization'/><author><name>Evance Soumaoro</name><uri>http://www.blogger.com/profile/02386230511527143770</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8743160121835339419.post-5851764048369139363</id><published>2011-12-14T13:47:00.000-08:00</published><updated>2011-12-14T13:48:06.502-08:00</updated><title type='text'>Matching parenthesis in arithmetic expressions with c++</title><content type='html'>This is a simplinstic way of testing if an expression is correctly grouped using stack based method.  &lt;br /&gt;&lt;pre class="prettyprint"&gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;#include &amp;lt;vector&amp;gt;&lt;br /&gt;#include &amp;lt;string&amp;gt;&lt;br /&gt;using namespace std;&lt;br /&gt;&lt;br /&gt;int main (int argc, char *argv[]){&lt;br /&gt;	vector&amp;lt;char&amp;gt; expr_validator;&lt;br /&gt;	string expression="2[(a-9)/(2-b)]/(x-2)-[(4*(x-8)+4)/(5x+17)]";&lt;br /&gt;	for(int i=0;i&amp;lt;expression.length() ;i++){&lt;br /&gt;		switch(expression[i]){&lt;br /&gt;			case '(':&lt;br /&gt;					expr_validator.push_back(expression[i]);&lt;br /&gt;				break;		&lt;br /&gt;			case ')':&lt;br /&gt;					if('('==expr_validator.back())&lt;br /&gt;						expr_validator.pop_back();&lt;br /&gt;					else&lt;br /&gt;						expr_validator.push_back(expression[i]);&lt;br /&gt;				break;&lt;br /&gt;			case '[':&lt;br /&gt;					expr_validator.push_back(expression[i]);&lt;br /&gt;				break;&lt;br /&gt;			case ']':&lt;br /&gt;					if('['==expr_validator.back())&lt;br /&gt;						expr_validator.pop_back();&lt;br /&gt;					else&lt;br /&gt;					expr_validator.push_back(expression[i]);&lt;br /&gt;				break;					&lt;br /&gt;		}&lt;br /&gt;	}	&lt;br /&gt;	&lt;br /&gt;	if(expr_validator.empty()){&lt;br /&gt;		cout &amp;lt;&amp;lt; "Good Expression" &amp;lt;&amp;lt; endl;	&lt;br /&gt;	}else {&lt;br /&gt;		cout &amp;lt;&amp;lt; "Bad Expression" &amp;lt;&amp;lt; endl;&lt;br /&gt;		cout&amp;lt;&amp;lt;	expr_validator.size() ;&lt;br /&gt;	}&lt;br /&gt;	return 0;	&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8743160121835339419-5851764048369139363?l=evanxg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://evanxg.blogspot.com/feeds/5851764048369139363/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://evanxg.blogspot.com/2011/12/matching-parenthesis-in-arithmetic.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8743160121835339419/posts/default/5851764048369139363'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8743160121835339419/posts/default/5851764048369139363'/><link rel='alternate' type='text/html' href='http://evanxg.blogspot.com/2011/12/matching-parenthesis-in-arithmetic.html' title='Matching parenthesis in arithmetic expressions with c++'/><author><name>Evance Soumaoro</name><uri>http://www.blogger.com/profile/02386230511527143770</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8743160121835339419.post-5448459626419581590</id><published>2011-12-01T13:40:00.001-08:00</published><updated>2011-12-14T13:39:55.091-08:00</updated><title type='text'>About this blog</title><content type='html'>Just another blog about c/c++&amp;nbsp; , Qt , STL,&amp;nbsp; C# Winform ,WPF,&amp;nbsp; PHP Zend framework, CI , Yalamo , and javascrip ...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8743160121835339419-5448459626419581590?l=evanxg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://evanxg.blogspot.com/feeds/5448459626419581590/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://evanxg.blogspot.com/2011/12/just-another-blog-about-cc-qt-stl-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8743160121835339419/posts/default/5448459626419581590'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8743160121835339419/posts/default/5448459626419581590'/><link rel='alternate' type='text/html' href='http://evanxg.blogspot.com/2011/12/just-another-blog-about-cc-qt-stl-c.html' title='About this blog'/><author><name>Evance Soumaoro</name><uri>http://www.blogger.com/profile/02386230511527143770</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
