<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Graph Colouring With Simple Backtracking, Part One</title><link>http://blogs.msdn.com/b/ericlippert/archive/2010/07/12/graph-colouring-with-simple-backtracking-part-one.aspx</link><description>As regular readers know, I'm interested in learning how to change my C# programming style to emphasize more concepts from functional programming, like use of immutable rather than mutable data structures and use of declarative control flow like LINQ queries</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Graph Colouring With Simple Backtracking, Part One</title><link>http://blogs.msdn.com/b/ericlippert/archive/2010/07/12/graph-colouring-with-simple-backtracking-part-one.aspx#10038598</link><pubDate>Thu, 15 Jul 2010 13:09:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10038598</guid><dc:creator>Svick</dc:creator><description>&lt;p&gt;@nick-m&lt;/p&gt;
&lt;p&gt;If you need to find out whether an edge between two vertices exists, then sure.&lt;/p&gt;
&lt;p&gt;But you don&amp;#39;t need that in this problem, the class Graph doesn&amp;#39;t even have something like public bool IsEdge(int node1, int node2).&lt;/p&gt;
&lt;p&gt;So, if the only thing you need is to find out the list of all neighbours of certain vertex, adjacency list is faster or as fast (in the case of a complete graph) as adjacency matrix.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10038598" width="1" height="1"&gt;</description></item><item><title>re: Graph Colouring With Simple Backtracking, Part One</title><link>http://blogs.msdn.com/b/ericlippert/archive/2010/07/12/graph-colouring-with-simple-backtracking-part-one.aspx#10038532</link><pubDate>Thu, 15 Jul 2010 10:24:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10038532</guid><dc:creator>nick-m</dc:creator><description>&lt;p&gt;@Svick&lt;/p&gt;
&lt;p&gt;That implementation will do better for sparse graphs. For dense graphs we may as well use the matrix because we can determine if an edge exists in O(1) time, rather than O(degree)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10038532" width="1" height="1"&gt;</description></item><item><title>re: Graph Colouring With Simple Backtracking, Part One</title><link>http://blogs.msdn.com/b/ericlippert/archive/2010/07/12/graph-colouring-with-simple-backtracking-part-one.aspx#10038310</link><pubDate>Wed, 14 Jul 2010 21:29:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10038310</guid><dc:creator>AC</dc:creator><description>&lt;p&gt;&amp;lt;blockquote&amp;gt;&lt;/p&gt;
&lt;p&gt;There is some redundancy in the information provided to the constructor. We could have deduced the number of nodes by taking the maximum integer found in the list of edges, instead of requiring that it be passed. &lt;/p&gt;
&lt;p&gt;&amp;lt;/blockquote&amp;gt;&lt;/p&gt;
&lt;p&gt;I just wanted to point out that explicitly requesting the length up front is probably a good idea because it doesn&amp;#39;t assume that everything has an edge. Not having any edges is also information. Hawaii anyone?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10038310" width="1" height="1"&gt;</description></item><item><title>re: Graph Colouring With Simple Backtracking, Part One</title><link>http://blogs.msdn.com/b/ericlippert/archive/2010/07/12/graph-colouring-with-simple-backtracking-part-one.aspx#10038103</link><pubDate>Wed, 14 Jul 2010 13:35:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10038103</guid><dc:creator>Daniel Brückner</dc:creator><description>&lt;p&gt;I have to disagree with &amp;quot;There is some redundancy in the information provided to the constructor.&amp;quot; in the general case. The highest node number found in the list of edges will not be the highest node number of the graph if the node(s) with the highest node number(s) is(are) of degree zero. (Although for representing maps it should be quite safe to assume a non-zero degree for all nodes except the case of a single node.)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10038103" width="1" height="1"&gt;</description></item><item><title>re: Graph Colouring With Simple Backtracking, Part One</title><link>http://blogs.msdn.com/b/ericlippert/archive/2010/07/12/graph-colouring-with-simple-backtracking-part-one.aspx#10037839</link><pubDate>Wed, 14 Jul 2010 00:04:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10037839</guid><dc:creator>Gabe</dc:creator><description>&lt;p&gt;I think this highlights one of the advantages of pair programming. Even when making nearly-trivial classes like this, you implicitly must make dozens of design decisions. If you have to stop and think about what decisions you&amp;#39;re making, the code takes much longer to write, and you are more likely to end up making the wrong decision. If you have to ask somebody about a decision, you have to stop what you and somebody else are doing, explain the context to them, and hope they can give you a meaningful answer.&lt;/p&gt;
&lt;p&gt;With pair programming, there&amp;#39;s always somebody there who has the full context of the situation who can give you advice on the decision. Ideally, this person has already even thought about the decision while you were typing in some other code, and has good reasons for their answer.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10037839" width="1" height="1"&gt;</description></item><item><title>re: Graph Colouring With Simple Backtracking, Part One</title><link>http://blogs.msdn.com/b/ericlippert/archive/2010/07/12/graph-colouring-with-simple-backtracking-part-one.aspx#10037750</link><pubDate>Tue, 13 Jul 2010 20:05:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10037750</guid><dc:creator>Jeffrey L. Whitledge</dc:creator><description>&lt;p&gt;@Leon re: uint&lt;/p&gt;
&lt;p&gt;I can&amp;#39;t speak for Eric, of course, but...&lt;/p&gt;
&lt;p&gt;I once developed a system in which negative values made no sense as a parameter, so rather than validating that the parameter values were non-negative, I thought it would be a great idea to just use uint instead. I quickly discovered that whenever I used those values for anything (like calling BCL methods), they had be converted to signed integers. This meant that I had to validate that the values didn&amp;#39;t exceed the signed integer range on the top end, so I gained nothing. Also, every time the code was called, the ints that were being used (often received from BCL functions) had to be converted to uints. It didn&amp;#39;t take long before I changed all those uints back to ints and took all that unnecessary casting out. I still have to validate that the numbers are not negative, but the code is much cleaner!&lt;/p&gt;
&lt;div class="yellowbox"&gt;
&lt;p&gt;Couldn&amp;#39;t have said it better myself. You almost never need the range of a uint, and they are not CLS-compliant. The standard way to represent a small integer is with &amp;quot;int&amp;quot;, even if there are values in there that are out of range. A good rule of thumb: only use &amp;quot;uint&amp;quot; for situations where you are interoperating with unmanaged code that expects uints, or where the integer in question is clearly used as a set of bits, not a number. Always try to avoid it in public interfaces. - Eric &lt;/p&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10037750" width="1" height="1"&gt;</description></item><item><title>re: Graph Colouring With Simple Backtracking, Part One</title><link>http://blogs.msdn.com/b/ericlippert/archive/2010/07/12/graph-colouring-with-simple-backtracking-part-one.aspx#10037680</link><pubDate>Tue, 13 Jul 2010 14:47:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10037680</guid><dc:creator>Leon</dc:creator><description>&lt;p&gt;Is there any reason that you used int instead of uint for the &amp;#39;nodes&amp;#39; parameter and to represent the nodes themselves?&lt;/p&gt;
&lt;p&gt;Pros: &lt;/p&gt;
&lt;p&gt;-A user cannot pass a negative number of nodes or node by mistake&lt;/p&gt;
&lt;p&gt;-No extra work (except to type the extra u ;-) )&lt;/p&gt;
&lt;p&gt;Cons: ?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10037680" width="1" height="1"&gt;</description></item><item><title>re: Graph Colouring With Simple Backtracking, Part One</title><link>http://blogs.msdn.com/b/ericlippert/archive/2010/07/12/graph-colouring-with-simple-backtracking-part-one.aspx#10037610</link><pubDate>Tue, 13 Jul 2010 12:21:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10037610</guid><dc:creator>Jeff Yates</dc:creator><description>&lt;p&gt;In the 11th paragraph, you write:&lt;/p&gt;
&lt;p&gt;&amp;quot;Suppose we do the first one: simply build an undirected graph and require the user to add edges in pairs if they want an undirected graph. &amp;quot;&lt;/p&gt;
&lt;p&gt;I think the first &amp;quot;undirected&amp;quot; should be &amp;quot;directed&amp;quot;.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10037610" width="1" height="1"&gt;</description></item><item><title>re: Graph Colouring With Simple Backtracking, Part One</title><link>http://blogs.msdn.com/b/ericlippert/archive/2010/07/12/graph-colouring-with-simple-backtracking-part-one.aspx#10037603</link><pubDate>Tue, 13 Jul 2010 12:02:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10037603</guid><dc:creator>An American</dc:creator><description>&lt;p&gt;&amp;gt; I&amp;#39;ve spelled &amp;quot;Neighbours&amp;quot; the British/Canadian way. &amp;nbsp;(Tradeoff: correctness vs familiarity to Americans)&lt;/p&gt;
&lt;p&gt;You mean (Tradeoff: cuteness vs correctness) right?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10037603" width="1" height="1"&gt;</description></item><item><title>re: Graph Colouring With Simple Backtracking, Part One</title><link>http://blogs.msdn.com/b/ericlippert/archive/2010/07/12/graph-colouring-with-simple-backtracking-part-one.aspx#10037472</link><pubDate>Tue, 13 Jul 2010 04:01:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10037472</guid><dc:creator>Denis</dc:creator><description>&lt;p&gt;Yes, software developers do a lot of decisions-making and face interesting challenges every step of the way. However, I am still going to move on towards architecture and management. Tradeoff 1: intellectual gratification vs. job security. Tradeoff 2: being bossed around by pompous boys 10 years younger than you vs. leaving your comfort zone. Tradeoff 3: thinking how to do what you are ordered to do vs. thinking what needs to be done, and why.&lt;/p&gt;
&lt;p&gt;Except at Microsoft and a few other Big Guys, software development has become routine, anyway (Tradeoff: cutting edge of technology vs. service industry).&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10037472" width="1" height="1"&gt;</description></item></channel></rss>