<?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:blogger='http://schemas.google.com/blogger/2008' 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-8416878285227016778</id><updated>2024-09-05T03:41:00.778+05:30</updated><category term="Algorithm Speed"/><category term="Puzzels"/><category term="Inline Function"/><category term="Memory Allocation"/><category term="Templates"/><title type='text'>The C++ Experts</title><subtitle type='html'>This blog is for the people who are interested to learn exceptional thing in C++. Learner can find new things here and experts can share there knowledge.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://cplusplusexpert.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8416878285227016778/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://cplusplusexpert.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Mazhar Rana</name><uri>http://www.blogger.com/profile/16905297996229740326</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgb1siJLeJDitIpWccxizJVnC6RlHZMp82-CN6RQMkl3zNtGmPmVWI_JXjonRI0e6U8pCFcVBuysmHN2R0MS69KqS6MjPVm0B9RmJ6PdR2jEeAUSymZGODdks2pwcHeqY0/s220/Cover_Photo1.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>18</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8416878285227016778.post-7864445749275853152</id><published>2011-09-17T15:06:00.001+05:30</published><updated>2011-09-17T15:13:18.623+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Puzzels"/><title type='text'>Puzzle: Finger counting</title><content type='html'>&lt;i&gt;Start counting on the fingers on one hand thusly: 1 thumb, 2 index finger, 3 middle finger, 4 ring finger, 5 little finger, 6 ring finger, 7middle finger, 8 index finger, 9 thumb and so on.&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;Which finger would you end up on if you were counting to 123456789? That over 123 million in case you think it&#39;s a trick question. Assume that you aren&#39;t carted of to the funny farm while doing it.&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;Answer:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
A complete cycle starting at thumb = 1 ends at thumb = 9. So you add 8 each time you return to the thumb. So you only need to deal with the remainder after dividing by 8. For 123456789 the remainder after dividing by 8 is 5 and that corresponds to the little finger.</content><link rel='replies' type='application/atom+xml' href='http://cplusplusexpert.blogspot.com/feeds/7864445749275853152/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cplusplusexpert.blogspot.com/2011/09/puzzle-finger-counting.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8416878285227016778/posts/default/7864445749275853152'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8416878285227016778/posts/default/7864445749275853152'/><link rel='alternate' type='text/html' href='http://cplusplusexpert.blogspot.com/2011/09/puzzle-finger-counting.html' title='Puzzle: Finger counting'/><author><name>Mazhar Rana</name><uri>http://www.blogger.com/profile/16905297996229740326</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgb1siJLeJDitIpWccxizJVnC6RlHZMp82-CN6RQMkl3zNtGmPmVWI_JXjonRI0e6U8pCFcVBuysmHN2R0MS69KqS6MjPVm0B9RmJ6PdR2jEeAUSymZGODdks2pwcHeqY0/s220/Cover_Photo1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8416878285227016778.post-7104268933627850417</id><published>2011-06-04T19:37:00.000+05:30</published><updated>2011-06-04T19:37:27.628+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Puzzels"/><title type='text'>Multiply a number by 7 without using * and + operator</title><content type='html'>&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-bidi-font-size: 12.0pt;&quot;&gt;int Num = n;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-bidi-font-size: 12.0pt;&quot;&gt;int NewNum;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-bidi-font-size: 12.0pt;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-bidi-font-size: 12.0pt;&quot;&gt;NewNum = Num &amp;lt;&amp;lt; 3; // mulitplied by 2 ^ 3 = 8&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-bidi-font-size: 12.0pt;&quot;&gt;NewNum = NewNum - Num; // 8 – 1 = 7 if n = 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cplusplusexpert.blogspot.com/feeds/7104268933627850417/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cplusplusexpert.blogspot.com/2011/06/multiply-number-by-7-without-using-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8416878285227016778/posts/default/7104268933627850417'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8416878285227016778/posts/default/7104268933627850417'/><link rel='alternate' type='text/html' href='http://cplusplusexpert.blogspot.com/2011/06/multiply-number-by-7-without-using-and.html' title='Multiply a number by 7 without using * and + operator'/><author><name>Mazhar Rana</name><uri>http://www.blogger.com/profile/16905297996229740326</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgb1siJLeJDitIpWccxizJVnC6RlHZMp82-CN6RQMkl3zNtGmPmVWI_JXjonRI0e6U8pCFcVBuysmHN2R0MS69KqS6MjPVm0B9RmJ6PdR2jEeAUSymZGODdks2pwcHeqY0/s220/Cover_Photo1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8416878285227016778.post-8745449609685469222</id><published>2011-06-04T19:29:00.002+05:30</published><updated>2011-06-04T19:29:47.937+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Algorithm Speed"/><title type='text'>Covert a string to upper case</title><content type='html'>&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: .5in;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-bidi-font-size: 12.0pt;&quot;&gt;void ToUpper(char * S)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: .5in;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-bidi-font-size: 12.0pt;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: .5in; text-indent: .5in;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-bidi-font-size: 12.0pt;&quot;&gt;while (*S!=0)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: .5in; text-indent: .5in;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-bidi-font-size: 12.0pt;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: 1.0in; text-indent: .5in;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-bidi-font-size: 12.0pt;&quot;&gt;*S=(*S &amp;gt;= &#39;a&#39; &amp;amp;&amp;amp; *S &amp;lt;= &#39;z&#39;)?(*S-&#39;a&#39;+&#39;A&#39;):*S;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: 1.0in; text-indent: .5in;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-bidi-font-size: 12.0pt;&quot;&gt;S++;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: .5in; text-indent: .5in;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-bidi-font-size: 12.0pt;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: .5in;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-bidi-font-size: 12.0pt;&quot;&gt;}&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cplusplusexpert.blogspot.com/feeds/8745449609685469222/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cplusplusexpert.blogspot.com/2011/06/covert-string-to-upper-case.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8416878285227016778/posts/default/8745449609685469222'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8416878285227016778/posts/default/8745449609685469222'/><link rel='alternate' type='text/html' href='http://cplusplusexpert.blogspot.com/2011/06/covert-string-to-upper-case.html' title='Covert a string to upper case'/><author><name>Mazhar Rana</name><uri>http://www.blogger.com/profile/16905297996229740326</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgb1siJLeJDitIpWccxizJVnC6RlHZMp82-CN6RQMkl3zNtGmPmVWI_JXjonRI0e6U8pCFcVBuysmHN2R0MS69KqS6MjPVm0B9RmJ6PdR2jEeAUSymZGODdks2pwcHeqY0/s220/Cover_Photo1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8416878285227016778.post-8382583440805351480</id><published>2011-06-04T19:25:00.002+05:30</published><updated>2011-06-04T19:25:51.643+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Algorithm Speed"/><title type='text'>Reverse a string</title><content type='html'>&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: .5in;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-bidi-font-size: 12.0pt;&quot;&gt;void ReverseString (char *String)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: .5in;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-bidi-font-size: 12.0pt;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: .5in; text-indent: .5in;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-bidi-font-size: 12.0pt;&quot;&gt;char *Begin = String;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: .5in; text-indent: .5in;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-bidi-font-size: 12.0pt;&quot;&gt;char *End = String + strlen(String) - 1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: .5in; text-indent: .5in;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-bidi-font-size: 12.0pt;&quot;&gt;char TempChar = &#39;\0&#39;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: .5in;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: .5in; text-indent: .5in;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-bidi-font-size: 12.0pt;&quot;&gt;while (Begin &amp;lt; End) &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: .5in; text-indent: .5in;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-bidi-font-size: 12.0pt;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: 1.0in; text-indent: .5in;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-bidi-font-size: 12.0pt;&quot;&gt;TempChar = *Begin;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: 1.0in; text-indent: .5in;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-bidi-font-size: 12.0pt;&quot;&gt;*Begin = *End;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: 1.0in; text-indent: .5in;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-bidi-font-size: 12.0pt;&quot;&gt;*End = TempChar;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: 1.0in; text-indent: .5in;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-bidi-font-size: 12.0pt;&quot;&gt;Begin++;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: 1.0in; text-indent: .5in;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-bidi-font-size: 12.0pt;&quot;&gt;End--;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: .5in; text-indent: .5in;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-bidi-font-size: 12.0pt;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: .5in;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;; font-size: 10.0pt; mso-bidi-font-size: 12.0pt;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cplusplusexpert.blogspot.com/feeds/8382583440805351480/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cplusplusexpert.blogspot.com/2011/06/reverse-string.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8416878285227016778/posts/default/8382583440805351480'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8416878285227016778/posts/default/8382583440805351480'/><link rel='alternate' type='text/html' href='http://cplusplusexpert.blogspot.com/2011/06/reverse-string.html' title='Reverse a string'/><author><name>Mazhar Rana</name><uri>http://www.blogger.com/profile/16905297996229740326</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgb1siJLeJDitIpWccxizJVnC6RlHZMp82-CN6RQMkl3zNtGmPmVWI_JXjonRI0e6U8pCFcVBuysmHN2R0MS69KqS6MjPVm0B9RmJ6PdR2jEeAUSymZGODdks2pwcHeqY0/s220/Cover_Photo1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8416878285227016778.post-7922708272083277190</id><published>2011-06-04T18:57:00.000+05:30</published><updated>2011-06-04T18:57:09.875+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Puzzels"/><title type='text'>Puzzle 3: The 8 ball problem</title><content type='html'>&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #635141; font-family: Arial, Helvetica, sans-serif; line-height: 25px;&quot;&gt;The problem is quite simple. You are given 8 identical-looking balls, one of which is heavier than the other 7 (all of which weigh the same). Using an old-fashioned mechanical set of scales you must identify the heavier ball using the scale as few times as possible. The scale is constructed using two bowls and an arm enabling the bowls to either balance or have one bowl rising while the other (and heavier bowl) falling. You can&#39;t just add one ball at a time thinking its one weighing, however, you may put any number of balls in each bowl... All you need to solve the puzzle is to use a bit of common sense.&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #635141; font-family: Arial, Helvetica, sans-serif; line-height: 25px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #635141; font-family: Arial, Helvetica, sans-serif; line-height: 25px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #635141; font-family: Arial, Helvetica, sans-serif; line-height: 25px;&quot;&gt;&lt;b&gt;Solution:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #635141; font-family: Arial, Helvetica, sans-serif; line-height: 25px;&quot;&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #635141; font-family: Arial, Helvetica, sans-serif; line-height: 25px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 14px; font-weight: normal;&quot;&gt;You can identify the heavier ball in only 2 weighings!!!!&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #635141; font-family: Arial, Helvetica, sans-serif; line-height: 25px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 14px; font-weight: normal;&quot;&gt;To achieve this in only 2 weighings, you first put 3 balls in each bowl on the scale, e.g. {1,2,3} against {4,5,6}. Should the scale balance, you have only 2 balls remaining which you can compare by putting each in a separate bowl on the scale, e.g. {7} against {8}. Should the scale not balance, however, take the 3 balls from the heavier bowl on the scale (e.g. 1,2,3). Pick any 2 balls and compare these against each other, e.g. {1} against {2}. If the scale balances, you know it is ball 3 is the heavier. Is the scale moving, you know it&#39;s the ball on the heavier side.&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://cplusplusexpert.blogspot.com/feeds/7922708272083277190/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cplusplusexpert.blogspot.com/2011/06/puzzle-3-8-ball-problem.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8416878285227016778/posts/default/7922708272083277190'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8416878285227016778/posts/default/7922708272083277190'/><link rel='alternate' type='text/html' href='http://cplusplusexpert.blogspot.com/2011/06/puzzle-3-8-ball-problem.html' title='Puzzle 3: The 8 ball problem'/><author><name>Mazhar Rana</name><uri>http://www.blogger.com/profile/16905297996229740326</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgb1siJLeJDitIpWccxizJVnC6RlHZMp82-CN6RQMkl3zNtGmPmVWI_JXjonRI0e6U8pCFcVBuysmHN2R0MS69KqS6MjPVm0B9RmJ6PdR2jEeAUSymZGODdks2pwcHeqY0/s220/Cover_Photo1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8416878285227016778.post-8092516882477768831</id><published>2011-06-04T18:50:00.000+05:30</published><updated>2011-06-04T18:50:24.782+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Puzzels"/><title type='text'>Puzzle 2 : 100 coins and 7 Bags</title><content type='html'>&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;times new roman&#39;;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;font-size: large;&quot;&gt;A dealer has 100 coins and only 7 money bags. He has to divide the coins over the seven bags so that he can make any number of coins simply by handing over a few bags. How must he divide the money over the seven money bags?&lt;/div&gt;&lt;div style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;font-size: large;&quot;&gt;Solution:&lt;/div&gt;&lt;div style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;Bag 1 = 01 ( 2^0 )&lt;br /&gt;
Bag 2 = 02 ( 2^1 )&lt;br /&gt;
Bag 3 = 04 ( 2^2 )&lt;br /&gt;
Bag 4 = 08 ( 2^3 )&lt;br /&gt;
Bag 5 = 16 ( 2^4 )&lt;br /&gt;
Bag 6 = 32 ( 2^5 )&lt;br /&gt;
Bag 7 = 37 ( 100 - ( 1 + 2 + 4 + 8 + 16 + 32 ) )&lt;br /&gt;
&lt;br /&gt;
Now suppose some one ask for 1 coin he can give Bag 1, for 2 he can give Bag 2, for three he can give Bag 1+ Bag 2,....for 53 coins he can give Bag 6(32) + Bag 5(16) + Bag 3(4) +Bag 1(1) and so on...</content><link rel='replies' type='application/atom+xml' href='http://cplusplusexpert.blogspot.com/feeds/8092516882477768831/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cplusplusexpert.blogspot.com/2011/06/puzzle-2-100-coins-and-7-bags.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8416878285227016778/posts/default/8092516882477768831'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8416878285227016778/posts/default/8092516882477768831'/><link rel='alternate' type='text/html' href='http://cplusplusexpert.blogspot.com/2011/06/puzzle-2-100-coins-and-7-bags.html' title='Puzzle 2 : 100 coins and 7 Bags'/><author><name>Mazhar Rana</name><uri>http://www.blogger.com/profile/16905297996229740326</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgb1siJLeJDitIpWccxizJVnC6RlHZMp82-CN6RQMkl3zNtGmPmVWI_JXjonRI0e6U8pCFcVBuysmHN2R0MS69KqS6MjPVm0B9RmJ6PdR2jEeAUSymZGODdks2pwcHeqY0/s220/Cover_Photo1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8416878285227016778.post-4030094020007389292</id><published>2011-04-20T15:13:00.002+05:30</published><updated>2011-04-20T15:15:43.071+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Puzzels"/><title type='text'>Puzzle 1</title><content type='html'>&lt;h3 style=&quot;margin-bottom: 5.6pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;color: #444444; font-family: inherit;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;Solve this by using any arithmetic operation:&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;&lt;h3 style=&quot;margin-bottom: 5.6pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;color: #444444; font-family: inherit; font-size: 10pt; font-weight: normal;&quot;&gt;1&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; 1&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; 1 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 6&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;&lt;h3 style=&quot;margin-bottom: 5.6pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;color: #444444; font-family: inherit; font-size: 10pt; font-weight: normal;&quot;&gt;2&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; 2&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; 2 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 6&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;&lt;h3 style=&quot;margin-bottom: 5.6pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;color: #444444; font-family: inherit; font-size: 10pt; font-weight: normal;&quot;&gt;3&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; 3&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; 3 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 6&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;&lt;h3 style=&quot;margin-bottom: 5.6pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;color: #444444; font-family: inherit; font-size: 10pt; font-weight: normal;&quot;&gt;4&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; 4&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; 4 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 6&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;&lt;h3 style=&quot;margin-bottom: 5.6pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;color: #444444; font-family: inherit; font-size: 10pt; font-weight: normal;&quot;&gt;5&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; 5&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; 5 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 6&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;&lt;h3 style=&quot;margin-bottom: 5.6pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;color: #444444; font-family: inherit; font-size: 10pt; font-weight: normal;&quot;&gt;6&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; 6&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; 6 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 6&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;&lt;h3 style=&quot;margin-bottom: 5.6pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;color: #444444; font-family: inherit; font-size: 10pt; font-weight: normal;&quot;&gt;7&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; 7&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; 7 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 6&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;&lt;h3 style=&quot;margin-bottom: 5.6pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;color: #444444; font-family: inherit; font-size: 10pt; font-weight: normal;&quot;&gt;8&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; 8&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; 8 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 6&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;&lt;h3 style=&quot;margin-bottom: 5.6pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;color: #444444; font-family: inherit; font-size: 10pt; font-weight: normal;&quot;&gt;9&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; 9&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; 9 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = 6&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;&lt;div&gt;&lt;span style=&quot;color: #444444; font-family: inherit; font-size: 10pt; font-weight: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #444444; font-family: inherit;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;Solution:&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #444444; font-family: inherit;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h3 style=&quot;color: black; font-size: medium; font-weight: normal; margin-bottom: 5.6pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;color: #444444; font-family: inherit; font-size: 10pt; font-weight: normal;&quot;&gt;( 1 &amp;nbsp; &amp;nbsp;+&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;1&amp;nbsp;&amp;nbsp; &amp;nbsp; + &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;1&amp;nbsp;)!&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;= 6&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;&lt;h3 style=&quot;color: black; font-size: medium; font-weight: normal; margin-bottom: 5.6pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;color: #444444; font-family: inherit; font-size: 10pt; font-weight: normal;&quot;&gt;2&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;+ &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;2&amp;nbsp;&amp;nbsp; &amp;nbsp; + &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;2&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;= 6&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;&lt;h3 style=&quot;color: black; font-size: medium; font-weight: normal; margin-bottom: 5.6pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;color: #444444; font-family: inherit; font-size: 10pt; font-weight: normal;&quot;&gt;3&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;* &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;3&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;- &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;3&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;= 6&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;&lt;h3 style=&quot;color: black; margin-bottom: 5.6pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;color: #444444; font-family: inherit;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;√&lt;/span&gt;&lt;/b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;4&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-weight: normal;&quot;&gt;&amp;nbsp;&amp;nbsp; + &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #444444; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;√&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #444444;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-weight: normal;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;4&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-weight: normal;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; + &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #444444; font-size: 16px; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;√&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #444444;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-weight: normal;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;4&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt; font-weight: normal;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;= 6&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;&lt;h3 style=&quot;color: black; font-size: medium; font-weight: normal; margin-bottom: 5.6pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;color: #444444; font-family: inherit; font-size: 10pt; font-weight: normal;&quot;&gt;5&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;+ &amp;nbsp; &amp;nbsp;(&amp;nbsp;&amp;nbsp;5&amp;nbsp;&amp;nbsp; &amp;nbsp; / &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;5&amp;nbsp;)&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;= 6&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;&lt;h3 style=&quot;color: black; font-size: medium; font-weight: normal; margin-bottom: 5.6pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;color: #444444; font-family: inherit; font-size: 10pt; font-weight: normal;&quot;&gt;6&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;+ &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;6&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;- &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;6&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;= 6&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;&lt;h3 style=&quot;color: black; font-size: medium; font-weight: normal; margin-bottom: 5.6pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;color: #444444; font-family: inherit; font-size: 10pt; font-weight: normal;&quot;&gt;7&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;- &amp;nbsp; &amp;nbsp; (&amp;nbsp;7&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;/ &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;7&amp;nbsp;&amp;nbsp;) &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;= 6&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;&lt;h3 style=&quot;color: black; font-size: medium; font-weight: normal; margin-bottom: 5.6pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;color: #444444; font-family: inherit; font-size: 10pt; font-weight: normal;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #444444; font-size: 16px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;√&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #444444; font-size: 13px;&quot;&gt;8&amp;nbsp;&amp;nbsp; + &amp;nbsp; &amp;nbsp; 3&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #444444; font-size: 15px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;√&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #444444; font-size: 13px;&quot;&gt;&amp;nbsp;&amp;nbsp;8&amp;nbsp;&amp;nbsp; &amp;nbsp;+ &amp;nbsp; 3&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #444444; font-size: 15px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;√&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #444444; font-size: 13px;&quot;&gt;&amp;nbsp;8 &amp;nbsp; &amp;nbsp; = 6&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;&lt;h3 style=&quot;color: black; font-size: medium; font-weight: normal; margin-bottom: 5.6pt; margin-left: 0in; margin-right: 0in; margin-top: 0in; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;color: #444444; font-family: inherit; font-size: 10pt; font-weight: normal;&quot;&gt;9&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;+ &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;9&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;/ &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #444444; font-size: 16px;&quot;&gt;&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small;&quot;&gt;√&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #444444; font-size: 13px;&quot;&gt;&amp;nbsp;&amp;nbsp;9&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;= 6&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;&lt;div style=&quot;color: #444444; font-size: 10pt; font-weight: normal;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;color: #444444; font-family: inherit; font-size: 10pt; font-weight: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cplusplusexpert.blogspot.com/feeds/4030094020007389292/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cplusplusexpert.blogspot.com/2011/04/puzzle-1.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8416878285227016778/posts/default/4030094020007389292'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8416878285227016778/posts/default/4030094020007389292'/><link rel='alternate' type='text/html' href='http://cplusplusexpert.blogspot.com/2011/04/puzzle-1.html' title='Puzzle 1'/><author><name>Mazhar Rana</name><uri>http://www.blogger.com/profile/16905297996229740326</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgb1siJLeJDitIpWccxizJVnC6RlHZMp82-CN6RQMkl3zNtGmPmVWI_JXjonRI0e6U8pCFcVBuysmHN2R0MS69KqS6MjPVm0B9RmJ6PdR2jEeAUSymZGODdks2pwcHeqY0/s220/Cover_Photo1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8416878285227016778.post-3019588911586732825</id><published>2011-04-20T14:59:00.000+05:30</published><updated>2011-04-20T14:59:04.411+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Algorithm Speed"/><title type='text'>Linked List Puzzle</title><content type='html'>How does one find a loop in a singly linked list in O(n) time using constant memory? You cannot modify the list in any way (and constant memory means the amount of memory required for the solution cannot be a function of n.).&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;Solution&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
I first figured this out when I was asked the question in a interview, so there’s verification that one question in the book was from a real interview. The best part of this problem is that I actually needed to write the code out for it a little while ago to detect a bug.&lt;br /&gt;
One way to detect a loop is to iterate over the list with 2 pointers at the same time where one is iterating at double speed. If the 2 pointers are ever equal after they iterate once and before they both reach an end, there’s a loop.&lt;br /&gt;
Now for another puzzle.. I think the next question I had to answer was something along the lines of “OK, How do you remove a loop in a linked list with the same constraints?” The latter question definitely seems harder, but in the sequence of questions I’d already answered for the interviewer, the solution was pretty obvious. I’ll leave that solution to someone else today.</content><link rel='replies' type='application/atom+xml' href='http://cplusplusexpert.blogspot.com/feeds/3019588911586732825/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cplusplusexpert.blogspot.com/2011/04/linked-list-puzzle.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8416878285227016778/posts/default/3019588911586732825'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8416878285227016778/posts/default/3019588911586732825'/><link rel='alternate' type='text/html' href='http://cplusplusexpert.blogspot.com/2011/04/linked-list-puzzle.html' title='Linked List Puzzle'/><author><name>Mazhar Rana</name><uri>http://www.blogger.com/profile/16905297996229740326</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgb1siJLeJDitIpWccxizJVnC6RlHZMp82-CN6RQMkl3zNtGmPmVWI_JXjonRI0e6U8pCFcVBuysmHN2R0MS69KqS6MjPVm0B9RmJ6PdR2jEeAUSymZGODdks2pwcHeqY0/s220/Cover_Photo1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8416878285227016778.post-66231434996356802</id><published>2011-04-09T16:01:00.000+05:30</published><updated>2011-04-09T16:01:25.372+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Algorithm Speed"/><title type='text'>Algorithm Speed in Practice</title><content type='html'>It&amp;#39;s unlikely that you&amp;#39;ll spend much time during your career writing sort  routines. The ones in the libraries available to you will probably outperform  anything you may write without substantial effort. However, the basic kinds of  algorithms we&amp;#39;ve described earlier pop up time and time again. Whenever you find  yourself writing a simple loop, you know that you have an &lt;i&gt;O&lt;/i&gt;(&lt;i&gt;n&lt;/i&gt;)  algorithm. If that loop contains an inner loop, then you&amp;#39;re looking at  &lt;i&gt;O&lt;/i&gt;(&lt;i&gt;m × n&lt;/i&gt;)&lt;i&gt;.&lt;/i&gt; You should be asking yourself how large these  values can get. If the numbers are bounded, then you&amp;#39;ll know how long the code  will take to run. If the numbers depend on external factors (such as the number  of records in an overnight batch run, or the number of names in a list of  people), then you might want to stop and consider the effect that large values  may have on your running time or memory consumption.&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://cplusplusexpert.blogspot.com/2011/04/algorithm-speed-in-practice.html#more&quot;&gt;Read more »&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://cplusplusexpert.blogspot.com/feeds/66231434996356802/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cplusplusexpert.blogspot.com/2011/04/algorithm-speed-in-practice.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8416878285227016778/posts/default/66231434996356802'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8416878285227016778/posts/default/66231434996356802'/><link rel='alternate' type='text/html' href='http://cplusplusexpert.blogspot.com/2011/04/algorithm-speed-in-practice.html' title='Algorithm Speed in Practice'/><author><name>Mazhar Rana</name><uri>http://www.blogger.com/profile/16905297996229740326</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgb1siJLeJDitIpWccxizJVnC6RlHZMp82-CN6RQMkl3zNtGmPmVWI_JXjonRI0e6U8pCFcVBuysmHN2R0MS69KqS6MjPVm0B9RmJ6PdR2jEeAUSymZGODdks2pwcHeqY0/s220/Cover_Photo1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8416878285227016778.post-8815834714766130346</id><published>2011-04-09T15:58:00.000+05:30</published><updated>2011-04-09T15:58:41.602+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Algorithm Speed"/><title type='text'>The O() Notation</title><content type='html'>The &lt;i&gt;O&lt;/i&gt;() notation is a mathematical way of dealing with approximations.  When we write that a particular sort routine sorts &lt;i&gt;n&lt;/i&gt; records in  &lt;i&gt;O&lt;/i&gt;(&lt;i&gt;n&lt;/i&gt;&lt;sup&gt;2&lt;/sup&gt;) time, we are simply saying that the worst-case  time taken will vary as the square of &lt;i&gt;n.&lt;/i&gt; Double the number of records,  and the time will increase roughly fourfold. Think of the &lt;i&gt;O&lt;/i&gt; as meaning  &lt;i&gt;on the order of.&lt;/i&gt; The &lt;i&gt;O&lt;/i&gt;() notation puts an upper bound on the value  of the thing we&amp;#39;re measuring (time, memory, and so on). If we say a function  takes &lt;i&gt;O&lt;/i&gt;(&lt;i&gt;n&lt;/i&gt;&lt;sup&gt;2&lt;/sup&gt;) time, then we know that the upper bound of  the time it takes will not grow faster than &lt;i&gt;n&lt;/i&gt;&lt;sup&gt;2&lt;/sup&gt;. Sometimes we  come up with fairly complex &lt;i&gt;O&lt;/i&gt;() functions, but because the highest-order  term will dominate the value as &lt;i&gt;n&lt;/i&gt; increases, the convention is to remove  all low-order terms, and not to bother showing any constant multiplying factors.  &lt;i&gt;O&lt;/i&gt;(&lt;i&gt;n&lt;/i&gt;&lt;sup&gt;2&lt;/sup&gt;/2&lt;i&gt;+&lt;/i&gt; 3&lt;i&gt;n&lt;/i&gt;) is the same as  &lt;i&gt;O&lt;/i&gt;(&lt;i&gt;n&lt;/i&gt;&lt;sup&gt;2&lt;/sup&gt;/2), which is equivalent to  &lt;i&gt;O&lt;/i&gt;(&lt;i&gt;n&lt;/i&gt;&lt;sup&gt;2&lt;/sup&gt;). This is actually&lt;br&gt;
&lt;a href=&quot;http://cplusplusexpert.blogspot.com/2011/04/o-notation.html#more&quot;&gt;Read more »&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://cplusplusexpert.blogspot.com/feeds/8815834714766130346/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cplusplusexpert.blogspot.com/2011/04/o-notation.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8416878285227016778/posts/default/8815834714766130346'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8416878285227016778/posts/default/8815834714766130346'/><link rel='alternate' type='text/html' href='http://cplusplusexpert.blogspot.com/2011/04/o-notation.html' title='The O() Notation'/><author><name>Mazhar Rana</name><uri>http://www.blogger.com/profile/16905297996229740326</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgb1siJLeJDitIpWccxizJVnC6RlHZMp82-CN6RQMkl3zNtGmPmVWI_JXjonRI0e6U8pCFcVBuysmHN2R0MS69KqS6MjPVm0B9RmJ6PdR2jEeAUSymZGODdks2pwcHeqY0/s220/Cover_Photo1.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_42HA4hdArKBZkdK6QhxQl5V5WXzHK4RoqqJORIhj3woUOtCXyS5F7_4Ga43L-kW14gAneQDYJXrB-QZXNIpY1Z5OI8OQUtsmewPH05ltOfcFxIohcWvoZcnIAIAI2TdkwkqFvvAzjDs/s72-c/Algo+Speed.JPG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8416878285227016778.post-1085020796159614480</id><published>2011-04-09T15:56:00.000+05:30</published><updated>2011-04-09T15:56:16.447+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Algorithm Speed"/><title type='text'>What Do We Mean by Estimating Algorithms?</title><content type='html'>Most nontrivial algorithms handle some kind of variable input—sorting  &lt;i&gt;n&lt;/i&gt; strings, inverting an &lt;i&gt;m × n&lt;/i&gt; matrix, or decrypting a message with  an &lt;i&gt;n&lt;/i&gt;-bit key. Normally, the size of this input will affect the algorithm:  the larger the input, the longer the running time or the more memory used.&lt;br /&gt;
If the relationship were always linear (so that the time increased in direct  proportion to the value of &lt;i&gt;n&lt;/i&gt;), this section wouldn&#39;t be important.  However, most significant algorithms are not linear. The good news is that many  are sublinear. A binary search, for example, doesn&#39;t need to look at every  candidate when finding a match. The bad news is that other algorithms are  considerably worse than linear; runtimes or memory requirements increase far  faster than &lt;i&gt;n.&lt;/i&gt; An algorithm that takes a minute to process ten items may  take a lifetime to process 100.&lt;br /&gt;
We find that whenever we write anything containing loops or recursive calls,  we subconsciously check the runtime and memory requirements. This is rarely a  formal process, but rather a quick confirmation that what we&#39;re doing is  sensible in the circumstances. However, we sometimes &lt;i&gt;do&lt;/i&gt; find ourselves  performing a more detailed analysis. That&#39;s when the &lt;i&gt;O&lt;/i&gt;() notation comes  in useful.</content><link rel='replies' type='application/atom+xml' href='http://cplusplusexpert.blogspot.com/feeds/1085020796159614480/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cplusplusexpert.blogspot.com/2011/04/what-do-we-mean-by-estimating.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8416878285227016778/posts/default/1085020796159614480'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8416878285227016778/posts/default/1085020796159614480'/><link rel='alternate' type='text/html' href='http://cplusplusexpert.blogspot.com/2011/04/what-do-we-mean-by-estimating.html' title='What Do We Mean by Estimating Algorithms?'/><author><name>Mazhar Rana</name><uri>http://www.blogger.com/profile/16905297996229740326</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgb1siJLeJDitIpWccxizJVnC6RlHZMp82-CN6RQMkl3zNtGmPmVWI_JXjonRI0e6U8pCFcVBuysmHN2R0MS69KqS6MjPVm0B9RmJ6PdR2jEeAUSymZGODdks2pwcHeqY0/s220/Cover_Photo1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8416878285227016778.post-4753843012952511080</id><published>2011-04-09T15:48:00.000+05:30</published><updated>2011-04-09T15:48:23.297+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Templates"/><title type='text'>Why Templates?</title><content type='html'>&lt;div class=&quot;docText&quot;&gt;C++ requires us to declare variables, functions, and most other  kinds of entities using specific types. However, a lot of code looks the same  for different types. Especially if you implement algorithms, such as &lt;span class=&quot;docEmphasis&quot;&gt;quicksort&lt;/span&gt;, or if you implement the behavior of data  structures, such as a linked list or a binary tree for different types, the code  looks the same despite the type used.&lt;/div&gt;&lt;div class=&quot;docText&quot;&gt;If your programming lan&lt;/div&gt;&lt;a href=&quot;http://cplusplusexpert.blogspot.com/2011/04/why-templates.html#more&quot;&gt;Read more »&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://cplusplusexpert.blogspot.com/feeds/4753843012952511080/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cplusplusexpert.blogspot.com/2011/04/why-templates.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8416878285227016778/posts/default/4753843012952511080'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8416878285227016778/posts/default/4753843012952511080'/><link rel='alternate' type='text/html' href='http://cplusplusexpert.blogspot.com/2011/04/why-templates.html' title='Why Templates?'/><author><name>Mazhar Rana</name><uri>http://www.blogger.com/profile/16905297996229740326</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgb1siJLeJDitIpWccxizJVnC6RlHZMp82-CN6RQMkl3zNtGmPmVWI_JXjonRI0e6U8pCFcVBuysmHN2R0MS69KqS6MjPVm0B9RmJ6PdR2jEeAUSymZGODdks2pwcHeqY0/s220/Cover_Photo1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8416878285227016778.post-2837308658099128081</id><published>2011-04-09T15:08:00.000+05:30</published><updated>2011-04-09T15:08:40.250+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Memory Allocation"/><title type='text'>What&#39;s the Best Buffer Growth Strategy?</title><content type='html'>&lt;div class=&quot;docText&quot;&gt;When a object( consider object of &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: monospace;&quot;&gt;&lt;i&gt;String &lt;/i&gt;in this discussion &lt;/span&gt;) runs out of room in its currently  allocated buffer, it needs to allocate a larger one. The key question is: How  big should the new buffer be? Note that the question is important because the  analysis we&amp;#39;re about to do holds for other structures and containers that use  allocated buffers, such as a standard &lt;tt&gt;vector&lt;/tt&gt;.&lt;/div&gt;&lt;div class=&quot;docText&quot;&gt;There are several popular buffer growth strategies. I&amp;#39;ll note  each strategy&amp;#39;s complexity in terms of the number of allocations required, and  the average number of times a given character must be copied, for a string of  eventual length &lt;span class=&quot;docEmphasis&quot;&gt;N.&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;&lt;br&gt;
&lt;ol class=&quot;docList&quot; type=&quot;a&quot;&gt;&lt;li&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt; &lt;div class=&quot;docText&quot;&gt;&lt;span class=&quot;docEmphasis&quot;&gt;Exact growth.&lt;/span&gt; In this strategy,  the new buffer is made exactly as large as required by the current operation.  For example, appending one character and then appending another will force two  allocations. First, a new buffer is allocated, with space for the existing  string and the first new character. Next, &lt;br&gt;
&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;a href=&quot;http://cplusplusexpert.blogspot.com/2011/04/whats-best-buffer-growth-strategy.html#more&quot;&gt;Read more »&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://cplusplusexpert.blogspot.com/feeds/2837308658099128081/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cplusplusexpert.blogspot.com/2011/04/whats-best-buffer-growth-strategy.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8416878285227016778/posts/default/2837308658099128081'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8416878285227016778/posts/default/2837308658099128081'/><link rel='alternate' type='text/html' href='http://cplusplusexpert.blogspot.com/2011/04/whats-best-buffer-growth-strategy.html' title='What&#39;s the Best Buffer Growth Strategy?'/><author><name>Mazhar Rana</name><uri>http://www.blogger.com/profile/16905297996229740326</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgb1siJLeJDitIpWccxizJVnC6RlHZMp82-CN6RQMkl3zNtGmPmVWI_JXjonRI0e6U8pCFcVBuysmHN2R0MS69KqS6MjPVm0B9RmJ6PdR2jEeAUSymZGODdks2pwcHeqY0/s220/Cover_Photo1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8416878285227016778.post-8329360067697314597</id><published>2011-04-09T14:22:00.002+05:30</published><updated>2011-04-09T14:22:51.146+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Inline Function"/><title type='text'>What About Accessors?</title><content type='html'>&lt;div class=&quot;docText&quot;&gt;There are people who will argue that one-line accessor  functions (like &quot;&lt;tt&gt;X&amp;amp; Y::f(){ return myX_; }&lt;/tt&gt;&quot;) are a reasonable  exception and could or should be automatically inlined. I understand the  reasoning, but be careful. At the very least, all inlined code increases  coupling. So, unless you&#39;re certain in advance that inlining will help, there&#39;s  no harm in deferring that decision to profiling time. If at that point, a  profiler does point out that inlining will help, at least you know that what  you&#39;re doing is worth doing, and you&#39;ve deferred the coupling and possible build  overhead until you know it will really matter. Not a bad deal, that.&lt;/div&gt;&lt;div class=&quot;docText&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;docNote&quot;&gt; &lt;div class=&quot;docNoteTitle&quot;&gt;&lt;/div&gt;&lt;br /&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;1&quot; cellspacing=&quot;0&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td valign=&quot;top&quot; width=&quot;60&quot;&gt;&lt;br /&gt;
&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;&lt;div class=&quot;docText&quot;&gt;&lt;span class=&quot;docEmphasis&quot;&gt;&lt;i&gt;Avoid inlining or detailed tuning until  performance profiles prove the need.&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cplusplusexpert.blogspot.com/feeds/8329360067697314597/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cplusplusexpert.blogspot.com/2011/04/what-about-accessors.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8416878285227016778/posts/default/8329360067697314597'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8416878285227016778/posts/default/8329360067697314597'/><link rel='alternate' type='text/html' href='http://cplusplusexpert.blogspot.com/2011/04/what-about-accessors.html' title='What About Accessors?'/><author><name>Mazhar Rana</name><uri>http://www.blogger.com/profile/16905297996229740326</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgb1siJLeJDitIpWccxizJVnC6RlHZMp82-CN6RQMkl3zNtGmPmVWI_JXjonRI0e6U8pCFcVBuysmHN2R0MS69KqS6MjPVm0B9RmJ6PdR2jEeAUSymZGODdks2pwcHeqY0/s220/Cover_Photo1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8416878285227016778.post-5051664756240677597</id><published>2011-04-09T14:16:00.001+05:30</published><updated>2011-04-09T15:09:48.542+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Inline Function"/><title type='text'>When and how should you decide to &#39;inline&#39; a function?</title><content type='html'>&lt;div class=&quot;docText&quot;&gt;The answer is the same as when to apply any other optimization:  after a profiler tells you to, and not a minute sooner. There are a few valid  exceptions to this guideline for cases in which you would reasonably  &lt;tt&gt;inline&lt;/tt&gt; right away, such as for an empty function that&amp;#39;s likely to stay  empty, or when you&amp;#39;re absolutely forced to—for example, when writing a  non-exported template.&lt;/div&gt;&lt;div class=&quot;docNote&quot;&gt;&lt;div class=&quot;docNoteTitle&quot;&gt;&lt;br&gt;
&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;docText&quot;&gt;Bottom line, inlining always costs &lt;br&gt;
&lt;/div&gt;&lt;a href=&quot;http://cplusplusexpert.blogspot.com/2011/04/when-and-how-should-you-decide-to.html#more&quot;&gt;Read more »&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://cplusplusexpert.blogspot.com/feeds/5051664756240677597/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cplusplusexpert.blogspot.com/2011/04/when-and-how-should-you-decide-to.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8416878285227016778/posts/default/5051664756240677597'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8416878285227016778/posts/default/5051664756240677597'/><link rel='alternate' type='text/html' href='http://cplusplusexpert.blogspot.com/2011/04/when-and-how-should-you-decide-to.html' title='When and how should you decide to &#39;inline&#39; a function?'/><author><name>Mazhar Rana</name><uri>http://www.blogger.com/profile/16905297996229740326</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgb1siJLeJDitIpWccxizJVnC6RlHZMp82-CN6RQMkl3zNtGmPmVWI_JXjonRI0e6U8pCFcVBuysmHN2R0MS69KqS6MjPVm0B9RmJ6PdR2jEeAUSymZGODdks2pwcHeqY0/s220/Cover_Photo1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8416878285227016778.post-5242262605703055243</id><published>2011-04-09T14:05:00.002+05:30</published><updated>2011-04-09T15:10:15.498+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Inline Function"/><title type='text'>Does making a function inline increase efficiency?</title><content type='html'>&lt;div class=&quot;docText&quot;&gt;&lt;/div&gt;&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;&lt;h3 class=&quot;docSection1Title&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: small; font-weight: normal;&quot;&gt;Not necessarily.&lt;/span&gt;&lt;/h3&gt;&lt;div class=&quot;docText&quot;&gt;First off, if you tried to answer this question without first  asking what you want to optimize, you fell into a classic trap. The first  question has to be: &amp;quot;What do you mean by efficiency?&amp;quot; Does the above question  mean program size? Memory footprint? Execution time? Development speed? Build  time? Or something else?&lt;/div&gt;&lt;div class=&quot;docText&quot;&gt;Second, contrary to popular opinion, inlining can improve &lt;span class=&quot;docEmphasis&quot;&gt;or&lt;/span&gt; worsen any of those aspects of efficiency:&lt;/div&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;&lt;br&gt;
&lt;ol class=&quot;docList&quot; type=&quot;a&quot;&gt;&lt;li&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt; &lt;div class=&quot;docText&quot;&gt;&lt;span class=&quot;docEmphasis&quot;&gt;Program size.&lt;/span&gt; Many programmers&lt;br&gt;
&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;a href=&quot;http://cplusplusexpert.blogspot.com/2011/04/does-making-function-inline-increase.html#more&quot;&gt;Read more »&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://cplusplusexpert.blogspot.com/feeds/5242262605703055243/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cplusplusexpert.blogspot.com/2011/04/does-making-function-inline-increase.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8416878285227016778/posts/default/5242262605703055243'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8416878285227016778/posts/default/5242262605703055243'/><link rel='alternate' type='text/html' href='http://cplusplusexpert.blogspot.com/2011/04/does-making-function-inline-increase.html' title='Does making a function inline increase efficiency?'/><author><name>Mazhar Rana</name><uri>http://www.blogger.com/profile/16905297996229740326</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgb1siJLeJDitIpWccxizJVnC6RlHZMp82-CN6RQMkl3zNtGmPmVWI_JXjonRI0e6U8pCFcVBuysmHN2R0MS69KqS6MjPVm0B9RmJ6PdR2jEeAUSymZGODdks2pwcHeqY0/s220/Cover_Photo1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8416878285227016778.post-8152960300573732501</id><published>2011-04-09T13:03:00.003+05:30</published><updated>2011-04-09T15:10:35.543+05:30</updated><title type='text'>The Issue of Complexity</title><content type='html'>&lt;h4 style=&quot;font-size: 10pt; margin-bottom: 3px; margin-top: 15px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Arial, Helvetica; font-weight: normal;&quot;&gt;An oft-repeated criticism of C++ is that it is very complex. This is true. To get a balanced view, however, it&amp;#39;s important to understand four things:&lt;/span&gt;&lt;/h4&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;font-family: Arial, Arial, Helvetica; font-size: 10pt; margin-left: 0.25in; margin-top: 6px; text-indent: -0.25in;&quot;&gt;1.&lt;span style=&quot;font: normal normal normal 7pt/normal &amp;#39;Times New Roman&amp;#39;;&quot;&gt;       &lt;/span&gt;&lt;b&gt;Complexity is bad when it&lt;/b&gt; One fundamental principle of C++ is that you don&amp;#39;t pay for what &lt;br&gt;
&lt;/div&gt;&lt;a href=&quot;http://cplusplusexpert.blogspot.com/2011/04/issue-of-complexity.html#more&quot;&gt;Read more »&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://cplusplusexpert.blogspot.com/feeds/8152960300573732501/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cplusplusexpert.blogspot.com/2011/04/issue-of-complexity.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8416878285227016778/posts/default/8152960300573732501'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8416878285227016778/posts/default/8152960300573732501'/><link rel='alternate' type='text/html' href='http://cplusplusexpert.blogspot.com/2011/04/issue-of-complexity.html' title='The Issue of Complexity'/><author><name>Mazhar Rana</name><uri>http://www.blogger.com/profile/16905297996229740326</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgb1siJLeJDitIpWccxizJVnC6RlHZMp82-CN6RQMkl3zNtGmPmVWI_JXjonRI0e6U8pCFcVBuysmHN2R0MS69KqS6MjPVm0B9RmJ6PdR2jEeAUSymZGODdks2pwcHeqY0/s220/Cover_Photo1.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8416878285227016778.post-5389702169720974416</id><published>2011-04-09T12:09:00.001+05:30</published><updated>2011-04-09T15:10:55.020+05:30</updated><title type='text'>Advice From the C++ Experts: Be Const-Correct</title><content type='html'>&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; dir=&quot;ltr&quot; style=&quot;font-family: Arial, Arial, Helvetica;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;&lt;span style=&quot;font-family: Arial, Arial, Helvetica;&quot;&gt;&lt;/span&gt;&lt;br&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;font-size: 10pt; margin-top: 6px;&quot;&gt;&lt;span style=&quot;font-family: Arial, Arial, Helvetica;&quot;&gt;Be &lt;span class=&quot;Code&quot; style=&quot;font-family: &amp;#39;Courier New&amp;#39;; font-size: 10pt; margin-bottom: 0px; margin-top: 0px;&quot;&gt;const&lt;/span&gt;-correct: &lt;span class=&quot;Code&quot; style=&quot;font-family: &amp;#39;Courier New&amp;#39;; font-size: 10pt; margin-bottom: 0px; margin-top: 0px;&quot;&gt;const&lt;/span&gt; and &lt;span class=&quot;Code&quot; style=&quot;font-family: &amp;#39;Courier New&amp;#39;; font-size: 10pt; margin-bottom: 0px; margin-top: 0px;&quot;&gt;mutable&lt;/span&gt; are your friends.&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;font-size: 10pt; margin-top: 6px;&quot;&gt;&lt;span style=&quot;font-family: Arial, Arial, Helvetica;&quot;&gt;I still sometimes come across programmers who think &lt;span class=&quot;Code&quot; style=&quot;font-family: &amp;#39;Courier New&amp;#39;; font-size: 10pt; margin-bottom: 0px; margin-top: 0px;&quot;&gt;const&lt;/span&gt; isn&amp;#39;t worth the trouble. &amp;quot;Aw, &lt;span class=&quot;Code&quot; style=&quot;font-family: &amp;#39;Courier New&amp;#39;; font-size: 10pt; margin-bottom: 0px; margin-top: 0px;&quot;&gt;const&lt;/span&gt; is a pain to write everywhere,&amp;quot; I&amp;#39;ve heard some complain. &amp;quot;If I use it in one place, I have to use it all the time. And anyway, other people skip it, and their programs work fine. Some of the libraries that I use aren&amp;#39;t &lt;span class=&quot;Code&quot; style=&quot;font-family: &amp;#39;Courier New&amp;#39;; font-size: 10pt; margin-bottom: 0px; margin-top: 0px;&quot;&gt;const&lt;/span&gt;-correct either. Is &lt;span class=&quot;Code&quot; style=&quot;font-family: &amp;#39;Courier New&amp;#39;; font-size: 10pt; margin-bottom: 0px; margin-top: 0px;&quot;&gt;const&lt;/span&gt; worth it?&amp;quot;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;font-size: 10pt; margin-top: 6px;&quot;&gt;&lt;span style=&quot;font-family: Arial, Arial, Helvetica;&quot;&gt;We could imagine a&lt;/span&gt;&lt;br&gt;
&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;a href=&quot;http://cplusplusexpert.blogspot.com/2011/04/advice-from-c-experts-be-const-correct.html#more&quot;&gt;Read more »&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://cplusplusexpert.blogspot.com/feeds/5389702169720974416/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cplusplusexpert.blogspot.com/2011/04/advice-from-c-experts-be-const-correct.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8416878285227016778/posts/default/5389702169720974416'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8416878285227016778/posts/default/5389702169720974416'/><link rel='alternate' type='text/html' href='http://cplusplusexpert.blogspot.com/2011/04/advice-from-c-experts-be-const-correct.html' title='Advice From the C++ Experts: Be Const-Correct'/><author><name>Mazhar Rana</name><uri>http://www.blogger.com/profile/16905297996229740326</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgb1siJLeJDitIpWccxizJVnC6RlHZMp82-CN6RQMkl3zNtGmPmVWI_JXjonRI0e6U8pCFcVBuysmHN2R0MS69KqS6MjPVm0B9RmJ6PdR2jEeAUSymZGODdks2pwcHeqY0/s220/Cover_Photo1.jpg'/></author><thr:total>0</thr:total></entry></feed>