dsa Forum Rss Feedhttp://www.codeplex.com/dsa/Thread/List.aspxdsa Forum Rss DescriptionNew Post: How should a new node with the same value be inserted?http://dsa.codeplex.com/discussions/404531<div style="line-height: normal;">
<p>Say a tree has an existing node with value 1. If another node of same value is to be added , which side should it go?</p>
<p>Your document states to go RIGHT : " where the left subtree of x contains nodes with values < x and the right subtree contains nodes whose values are >= x ."</p>
<p>Whereas an article from <a href="http://cslibrary.stanford.edu/110/BinaryTrees.html">
Stanford</a> states to go LEFT : "a<span>ll elements in its left subtree are less-or-equal to the node (<=), and all the elements in its right subtree are greater than the node (>)."</span></p>
<p>Provided code sample ignores duplicates. I am not sure which side to take?</p>
</div>antonydMon, 26 Nov 2012 00:55:41 GMTNew Post: How should a new node with the same value be inserted? 20121126125541ANew Post: Why does ICommonBinaryTreeNode have a TNode generic parameter?http://dsa.codeplex.com/discussions/404514<div style="line-height: normal;">
<p>Also, CommonBinaryTree<TNode,TValue> restricts the use of <strong>TNode</strong> to a ICommonBinaryTreeNode, i.e the node should ONLY have LEFT and RIGHT children. This also means that I cannot implement any generic node say TOP,BOTTOM and hence I am still
wondering the rationale behind <strong>TNode</strong> in <strong> ICommonBinaryTreeNode<TNode,TValue>.
</strong>Hope I am making some sense , please correct my understanding.</p>
</div>antonydSun, 25 Nov 2012 18:15:36 GMTNew Post: Why does ICommonBinaryTreeNode have a TNode generic parameter? 20121125061536PNew Post: Why does ICommonBinaryTreeNode have a TNode generic parameter?http://dsa.codeplex.com/discussions/404514<div style="line-height: normal;">
<p>A relatively easier implementation of this interface could be </p>
<p> </p>
<div style="color:black; background-color:white">
<pre><span style="color:blue">public</span> <span style="color:blue">interface</span> ICommonBinaryTreeNode<T>
{
ICommonBinaryTreeNode<T> Left { <span style="color:blue">get</span>; <span style="color:blue">set</span>; }
ICommonBinaryTreeNode<T> Right { <span style="color:blue">get</span>; <span style="color:blue">set</span>; }
TValue Value { <span style="color:blue">get</span>; <span style="color:blue">set</span>; }
}</pre>
</div>
<p>But, I understand the intention of the authors that the Left & Right children could a node of any other type. Can you cite an tree example that could take advantage of the generic parameter <Tnode> ?</p>
</div>antonydSun, 25 Nov 2012 17:12:42 GMTNew Post: Why does ICommonBinaryTreeNode have a TNode generic parameter? 20121125051242PNew Post: Error loading Dsa.test.csproj project in monodevelop.http://dsa.codeplex.com/discussions/404471<div style="line-height: normal;">
<p>If you are trying to see the code using monodevelop, then you could most likely run into an error when loading Dsa.test.csproj. This is because of a projectguid reference to mstest (though all projects are Nunit based). To overcome this problem , remove
this line from Dsa.Test.csproj </p>
<p><span><</span><span>ProjectTypeGuids</span><span>></span><span>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4....</span></p>
<p> </p>
<p><span>Just thought someone might benefit</span></p>
</div>antonydSun, 25 Nov 2012 00:14:26 GMTNew Post: Error loading Dsa.test.csproj project in monodevelop. 20121125121426ANew Post: Boundary conditionshttp://dsa.codeplex.com/Thread/View.aspx?ThreadId=231823<div style="line-height: normal;"><p>Hi moderators</p>
<p>I was going through your code project. I started with Algorithms/Numbers.cs. Some of the boundary cases have not been checked. Please go through the list and consider applying them.</p>
<p>I am enlisting a few here. More to come.</p>
<p>1. Fibonacci, GCD, Tobinary, ToOctal methods have to check for integer overflow if given the max value of integer.</p>
<p>2. ToBinary, ToOctal methods need to check what will happen if the number is zero (0).</p>
<p>Thanks</p></div>justINcoderThu, 21 Oct 2010 15:06:12 GMTNew Post: Boundary conditions 20101021030612PNew Post: The base class is missing.http://www.codeplex.com/dsa/Thread/View.aspx?ThreadId=34607<div style="line-height: normal;">Sorry for the inconvenience, it has been fixed...<br>
<br>
</div>lukadtThu, 11 Sep 2008 12:51:00 GMTNew Post: The base class is missing. 20080911125100PNew Post: The base class is missing.http://www.codeplex.com/dsa/Thread/View.aspx?ThreadId=34607<div style="line-height: normal;">I downloaded the latest code, and it complains that the base class is missing.<br>
</div>yuren1978Sat, 30 Aug 2008 13:20:40 GMTNew Post: The base class is missing. 20080830012040PNew Post: It is already in .net?http://www.codeplex.com/dsa/Thread/View.aspx?ThreadId=32372<div style="line-height: normal;">Quicksort is used in Array.Sort but our quicksort can be used on anything that implements IList<T>.<br>
<br>
As for doubly linked list, I think it does use a different implementation - it is there probably because it was one of the first data structures in there. I did some perf testing a while back and our doubly linked list was faster than LinkedList<T>.<br>
<br>
For now it will stay, unless we find a reason to get rid of it.
</div>gbarnettSun, 27 Jul 2008 20:58:48 GMTNew Post: It is already in .net? 20080727085848PNew Post: It is already in .net?http://www.codeplex.com/dsa/Thread/View.aspx?ThreadId=32372<div style="line-height: normal;">According to the front page: "<span id="ctl00_ctl00_Content_TabContentPanel_Content_wikiSourceLabel">Data
Structures and Algorithms (DSA) features implementations of data
structures and algorithms that are not implemented in any version of
.NET."<br>
<br>
But </span><span id="ctl00_ctl00_Content_TabContentPanel_Content_wikiSourceLabel">DoublyLinkedList is already implemented in .net? Or is it because it has a different implementation that would cause one to use </span><span id="ctl00_ctl00_Content_TabContentPanel_Content_wikiSourceLabel">DoublyLinkedList instead of </span><span id="ctl00_ctl00_Content_TabContentPanel_Content_wikiSourceLabel"></span>LinkedList<span><T>?<br>
<br>
A</span><span></span><span></span>lso, the Quick sort algorithm is also already implemented in .net in the form of Array.Sort(). It uses a unstable quick sort if I remember correctly.<br>
</div>genboxSun, 27 Jul 2008 19:16:13 GMTNew Post: It is already in .net? 20080727071613PNew Post: A question about Fibonacci's numbers generatorhttp://www.codeplex.com/dsa/Thread/View.aspx?ThreadId=30073<div style="line-height: normal;">Hi Gianluca, i'm glad you are giving us interesting feedback and focus on Fibonacci complexity. Binet's formula it's very surprising and interesting at the same time but in real world there are some built-in limits for the number of decimal places one can accurately compute (floating point limited precision). Sometimes these inaccuracies will make numbers round to the wrong values and carry to inappropriate result. The approach we adopted improves the classical algorithm definition using the memory during the computation in such a way that the values of two consecutive terms of the Fibonacci sequence are always stored in the memory thus avoiding unnecessary computing...<br>
Hear you soon, Luca<br>
</div>lukadtMon, 23 Jun 2008 14:27:37 GMTNew Post: A question about Fibonacci's numbers generator 20080623022737PNew Post: A question about Fibonacci's numbers generatorhttp://www.codeplex.com/dsa/Thread/View.aspx?ThreadId=30073<div style="line-height: normal;">I looked at the Fibonacci's generator and I would ask a question about it: why did you choose to implement the generator using the iterative formula instead of the closed form version? With the iterative formula f(n)=f(n-1)+f(n-2) one has to do 'n' passes to get the n-th fibonacci's number and in this case the complexity is obviously O(n). However, the iterative formula can be "rolled up" and rewritten in closed form (the so called Binet's formula), so it is required only the 'n' to get the n-th number and the complexity drops to O(1) (a constant time!).<br>
<br>
Here is the Binet's closed formula of the Fibonacci's series:<br>
f(n) = floor((1/2)+((g^n)/sqrt(5))); where 'g' is the golden ratio equal to g=(1+sqrt(5))/2;<br>
<br>
Bye!<br>
Gianluca<br>
<br>
</div>GianlucaGhettiniSun, 22 Jun 2008 13:19:28 GMTNew Post: A question about Fibonacci's numbers generator 20080622011928PNew Post: Stability of sorting algorithms...http://www.codeplex.com/dsa/Thread/View.aspx?ThreadId=30002<div style="line-height: normal;"><br>
<div style="border-right:medium none;padding-right:0.2em;padding-left:0.2em;border-top:#aaa 0.1em dotted;padding-bottom:0.2em;margin:1em 0em 2.5em 3em;border-left:medium none;padding-top:0.2em;border-bottom:#aaa 0.1em dotted;font-style:italic"><br>
GianlucaGhettini wrote:<br>
Yes, IComparable interface allows deeper control over sorting. In fact I use to reimplement this interface to get the right behavior from my sorting algorithm (i.e. sorting again over equal key objects to break the tie). However, I think that the stability is a very basic property of a sorting algorithm and it should not be left to reimplement over and over again.<br>
<br>
Gianluca<br>
<br>
<br>
</div>
<br>
There is a fine line between giving the programmer more control, and providing generalised solutions - all I can say is that we will look at it. <br>
<br>
Thanks for your feedback!<br>
<br>
Granville
</div>gbarnettSun, 22 Jun 2008 11:29:37 GMTNew Post: Stability of sorting algorithms... 20080622112937ANew Post: Stability of sorting algorithms...http://www.codeplex.com/dsa/Thread/View.aspx?ThreadId=30002<div style="line-height: normal;">Yes, IComparable interface allows deeper control over sorting. In fact I use to reimplement this interface to get the right behavior from my sorting algorithm (i.e. sorting again over equal key objects to break the tie). However, I think that the stability is a very basic property of a sorting algorithm and it should not be left to reimplement over and over again.<br>
<br>
Gianluca<br>
</div>GianlucaGhettiniSun, 22 Jun 2008 08:52:55 GMTNew Post: Stability of sorting algorithms... 20080622085255ANew Post: Stability of sorting algorithms...http://www.codeplex.com/dsa/Thread/View.aspx?ThreadId=30002<div style="line-height: normal;">Hi Gianluca,<br>
<br>
For now what I will say is that we will look into it BUT you can actually take a more atomic approach over sorting by implementing the IComparable interface on the complex types, this is what DSA sorting algorithms use to verify who is larger than who, less than etc.<br>
<br>
Thanks for the comment and I will add it to our unofficial to-look-at list.<br>
<br>
Thanks,<br>
<br>
Granville
</div>gbarnettSat, 21 Jun 2008 16:29:53 GMTNew Post: Stability of sorting algorithms... 20080621042953PNew Post: Stability of sorting algorithms...http://www.codeplex.com/dsa/Thread/View.aspx?ThreadId=30002<div style="line-height: normal;"><span>Hi, good job!!!<br>
I'm a Luca's friend and I'm currently programming in .NET (sometimes with Luca, at university).<br>
<br>
.NET is a very powerful and interesting framework, but IHMO I think it<br>
lacks control over sorting algorithms. What I'm trying to point out is<br>
about stability of a sorting algorithm.<br>
A sorting algorithm is stable if maintains the relative order of records<br>
with equal keys (i.e., values). That is, a sorting algorithm is stable<br>
if whenever there are two records R and S with the same key and with R<br>
appearing before S in the original list, R will appear before S in the<br>
sorted list.<br>
This property isn't critical when you are dealing with base types like<br>
integers or strings, but can be very useful when you are sorting more<br>
complex objects. I mean, suppose you have a simple array of integers,<br>
like this:<br>
[6 5 2 5 1 7 1]<br>
sorting it is straigthforward, we always obtain:<br>
[1 1 2 5 5 6 7]<br>
The first two integers of the sorted array are 1 1. Reversing the order<br>
of this two integers doesn't change the array. So, for example, when you<br>
are sorting a random array that contains two 1's, the 1 1 sequence<br>
appearing in the sorted array will always be the same, no matter if the<br>
algorithm you are using is stable or not.<br>
Now think you have an array of animals, and that you are sorting by<br>
number of legs. Now stability makes the difference:<br>
To figure out why, suppose you have this two arrays:<br>
<br>
[cow, snake, dog, cat, chicken, ant]<br>
<br>
and:<br>
<br>
[dog, ant, chicken, cow, cat]<br>
<br>
with an unstable algorithm you can obtain:<br>
<br>
[snake, chicken, cow, dog, cat, ant]<br>
<br>
and:<br>
<br>
[chicken, dog, cow, cat, ant]<br>
<br>
with a stable algorithm:<br>
<br>
[snake, chicken, cow, dog, cat, ant]<br>
<br>
and:<br>
<br>
[chicken, cow, dog, cat, ant]<br>
<br>
As you can see, the stable version of the algorithm always preserves the<br>
order of the sequence [cow, dog, cat] (although this order is arbitrary)<br>
in every array containings these animals, while the other MAY not.<br>
.NET doesn't allow the programmer to know if the sorting algorithm<br>
he/she's using is stable or not (some algorithms can be either stable or<br>
unstable).<br>
I'd like to deal with a stability-aware DSA framework!!! :)</span>
</div>GianlucaGhettiniFri, 20 Jun 2008 13:55:51 GMTNew Post: Stability of sorting algorithms... 20080620015551PNEW POST: Comments about Set<T> implementationhttp://www.codeplex.com/dsa/Thread/View.aspx?ThreadId=22630<div class="wikidoc">
I'll look into it<br /> <br />Thanks,<br /> <br />Granville<br /> <br /><div class="quote">
<br />mstrobel wrote:<br />Hi there,<br /> <br />I have some observations about the Set<T> class. First, a Set<T> wraps some other CollectionBase<T>, which it takes as a constructor parameter. Since there is no guarantee that the wrapped collection is a set of unique entities (it may be populated with several duplicates), then there is no guarantee that any Set<T> is actually a unique set. However, since Set<T> already implements CollectionBase<T>, I don't see why it's necessary to wrap another collection at all. Since all of the collection manipulation methods (Add, Remove, etc.) operate directly on the wrapped set, then why not simply have Set<T> extend a fully-functional collection type (e.g. a BinarySearchTree<T> with an IComparer<T> implementation that compares hashcodes) and override the Add method to include a uniqueness check?<br /> <br />Cheers,<br />Mike<br /> <br />
</div>
</div>gbarnettFri, 22 Feb 2008 12:07:50 GMTNEW POST: Comments about Set<T> implementation 20080222120750PNEW POST: Comments about Set<T> implementationhttp://www.codeplex.com/dsa/Thread/View.aspx?ThreadId=22630<div class="wikidoc">
Hi there,<br /> <br />I have some observations about the Set<T> class. First, a Set<T> wraps some other CollectionBase<T>, which it takes as a constructor parameter. Since there is no guarantee that the wrapped collection is a set of unique entities (it may be populated with several duplicates), then there is no guarantee that any Set<T> is actually a unique set. However, since Set<T> already implements CollectionBase<T>, I don't see why it's necessary to wrap another collection at all. Since all of the collection manipulation methods (Add, Remove, etc.) operate directly on the wrapped set, then why not simply have Set<T> extend a fully-functional collection type (e.g. a BinarySearchTree<T> with an IComparer<T> implementation that compares hashcodes) and override the Add method to include a uniqueness check?<br /> <br />Cheers,<br />Mike<br />
</div>mstrobelFri, 22 Feb 2008 02:10:41 GMTNEW POST: Comments about Set<T> implementation 20080222021041ANEW POST: Extension methods or static methods?http://www.codeplex.com/dsa/Thread/View.aspx?ThreadId=16793<div class="wikidoc">
True. I'll admit I didn't actually try the normal route until a week or so after starting this thread - but I would encourage the ext method way as it increases the synergy between the BCL and DSA.<br /> <br />Thanks Mike!<br /> <br /><div class="quote">
<br />mstrobel wrote:<br />Hi Granville,<br /> <br />I fully embrace extension methods. Not only do they allow for the same invocation style as instance methods, but they can also be called in the same way as regular static methods, like so:<br /> <br />public static class Algorithms<br />{<br /> public static IList<T> BubbleSort<T>(this IList<T> source) { ... }<br />}<br /> <br />var myList = new List<T> { 5, 2, 7, 1, 8 };<br />var sortedList1 = myList.BubbleSort();<br />var sortedList2 = Algorithms.BubbleSort(myList);<br /> <br />Since you get the best of both worlds, it makes little sense not to use extension methods :).<br /> <br />Cheers,<br />Mike<br /> <br />
</div>
</div>gbarnettThu, 21 Feb 2008 19:47:12 GMTNEW POST: Extension methods or static methods? 20080221074712PNEW POST: Efficiency of Heap.Removehttp://www.codeplex.com/dsa/Thread/View.aspx?ThreadId=22604<div class="wikidoc">
Good catch. I actually added all that stuff the other day off the top of my head so bare with me on that as its sort of a skim at the moment.<br /> <br />Thanks for the catch. <br /> <br />p.s. if you find any others that are inaccurate please let me know, like I said it was skim through the source but I think the addition of this is pretty decent.<br /> <br /><div class="quote">
<br />mstrobel wrote:<br />Hi there,<br /> <br />Great work on the library, and I like the addition of the new extension methods :).<br /> <br />I noticed that the documentation for the Heap.Remove method claims an asymptotic upper bound of O(log n). However, the first line of the method is a call to Array.IndexOf, which I believe is O(n), which is faster growing than O(log n). I haven't analyzed the method in detail, but removing that call should improve the efficiency of the method so that it actually is O(log n). I haven't looked at the efficiency of any other methods--this just happened to catch my eye as I was perusing the source code :).<br /> <br />Cheers,<br />Mike<br /> <br />
</div>
</div>gbarnettThu, 21 Feb 2008 19:45:38 GMTNEW POST: Efficiency of Heap.Remove 20080221074538PNEW POST: Extension methods or static methods?http://www.codeplex.com/dsa/Thread/View.aspx?ThreadId=16793<div class="wikidoc">
Hi Granville,<br /> <br />I fully embrace extension methods. Not only do they allow for the same invocation style as instance methods, but they can also be called in the same way as regular static methods, like so:<br /> <br />public static class Algorithms<br />{<br /> public static IList<T> BubbleSort<T>(this IList<T> source) { ... }<br />}<br /> <br />var myList = new List<T> { 5, 2, 7, 1, 8 };<br />var sortedList1 = myList.BubbleSort();<br />var sortedList2 = Algorithms.BubbleSort(myList);<br /> <br />Since you get the best of both worlds, it makes little sense not to use extension methods :).<br /> <br />Cheers,<br />Mike<br />
</div>mstrobelThu, 21 Feb 2008 17:34:13 GMTNEW POST: Extension methods or static methods? 20080221053413P