sorting

sorting algorithm where pairwise-comparison can return more information than -1, 0, +1

Most sort algorithms rely on a pairwise-comparison the determines whether A < B, A = B or A > B. I'm looking for algorithms (and for bonus points, code in Python) that take advantage of a pairwise-comparison function that can distinguish a lot less from a little less or a lot more from a little more. So perhaps instead of returning {-1,...

which sorting algorithms give near / approximate sort sooner?

Which sorting algorithms produce intermediate orderings which are good approximations? By "good approximation" I mean according to metrics such as Kendall's tau and Spearman's footrule for determining how "far" an ordered list is from another (in this case, the exact sort) The particular application I have in mind is where humans are d...

Sorting a tuple that contains lists

I have a similar question to this one but instead my tuple contains lists, as follows: mytuple = ( ["tomato", 3], ["say", 2], ["say", 5], ["I", 4], ["you", 1], ["tomato", 6], ) What's the most efficient way of sorting this? ...

Sorting a Ruby array

I am trying to sort large inputs in the fastest way in ascending order. The code is something like this: t=gets ti=t.to_i r=[] for i in(0..ti) k=gets r[i]=k.to_i end r.sort_by{|x| -x.last} This is giving me an error saying undefined method 'last' for nil:nilclass <nomethoderror> from tsort.rb: in sort_by from tsort.rb in 'each...

Use LINQ for arbitrary sorting

Let's say we have an entity that has attributes att1 and att2, where att1 can have values a,b,c and att2 can have values 1,2,3. Is it possible to use LINQ so that we can sort items in the collection by applying arbitrary sorting rule without implementing IComparable. I am facing an issue were business requires that on some screens items ...

Filter/Sort in the view or in the model?

Having a list of data object and something visual to represent each, where would you code the sorting/filtering logic? Why? Edit : All the answers so far are good, but I forgot to add another constraint. What if I don't want to reconstruct the view each time? ...

Reason for Sorting a Hash Table

I was asked by an employer to sort a hash table. I always thought that the usage of a hash table was in a way non-sort friendly. Am I wrong in thinking this, and if not can you point me to a good VB.Net(Yes Kill me now, but it's an old system) method of sorting a hash table. Thanks. ...

C# Help: Sorting a List of Objects in C#

public class CarSpecs { public CarSpecs() { } private String _CarName; public String CarName { get { return _CarName; } set { _CarName = value; } } private String _CarMaker; public String CarMaker { get { return _CarMaker;} set { _CarMaker = value; } } p...

How do you sort an EntitySet<T>

The MSDN documentation states that an EntitySet implements IBindingList (see 'Binding to EntitySets' at http://msdn.microsoft.com/en-us/library/bb546190.aspx) However, it can be clearly seen that an EntitySet does not implement this interface! So how do I sort? For context, I'm binding this set to a WPF ListView. For wider context o...

C# Help: Sorting a List of Objects in C#

Possible Duplicates: Sort objects using predefined list of sorted values C# Help: Sorting a List of Objects in C# Double Post http://stackoverflow.com/questions/925471/c-help-sorting-a-list-of-objects-in-c/925477#925477 public class CarSpecs { public CarSpecs() { } private String _CarName; publi...

WPF binding not notifying of changes

I have a WPF sorting/binding issue. (Disclaimer: I am very new to WPF and databinding so apologise if I am asking a really dumb question :-)) Firstly, I have a linqToSql entity class Contact with an EntitySet<Booking> property Bookings on it. If I directly bind this Bookings property to a ListView, the application seems to correctly no...

why unix sort command could sort a very large file?

the unix sort command can sort very large file like this cat large_file|sort how does the sort command implemented? why it doesn't cause excessive consumption of memory problem? ...

List.Sort IComparer performance

I'm trying to sort a pair of int arrays (int[] a; int[] b;) If I use Array.Sort(a,b) then the performance is great. However, I'd prefer to use a List<> and load the int pairs in a struct. I can get this to work using Array.Sort() with an overload that provides a simple comparer for the struct but it's about 4 times slower than the Arra...

how to sort by a computed value in django

Hey I want to sort objects based on a computed value in django... how do I do it? Here is an example User profile model based on stack overflow that explains my predicament: class Profile(models.Model): user = models.ForeignKey(User) def get_reputation(): ... return reputation reputation = property(get_rep...

Tree Datastructures

I've tried to understand what sorted trees are and binary trees and avl and and and ... I'm still not sure, what makes a sorted tree sorted? And what is the complexity (Big-Oh) between searching in a sorted and searching in an unsorted tree? Hope you can help me. ...

std::sort without functors

I have a question regarding the std::sort algorithm. Here is my test code: struct MyTest { int m_first; int m_second; MyTest(int first = 0, int second = 0) : m_first(first), m_second(second) { } }; int main(int argc,char *argv[]) { std::vector<MyTest> myVec; for(int i = 0; i < 10; ++i) { myVec.pus...

ASP.NET: ajaxToolkit's HoverMenuExtender slows down sorting in GridView

I have a GridView inside UpdatePanel and also a HoverMenuExtender declared. GridView also has Paging and Sorting enabled and PageSize is 25. Right now I'm working on a mockup of the actual application so I'm using a mock DataSet with only 20 records. Problem is when I try to sort gridView by clicking on a column it's VERY SLOW. It take...

How to Sort In-Memory XML with Microsoft XMLDOM?

Besides using XSLT... How to Sort In-Memory XML with Microsoft XMLDOM? ...

Why are my dates not sorting correctly?

I wonder if anyone has come across this issue before. I have a string converted to a date and sorted ascending. The date is sorting numerically but it is not sorting on the month. I wonder if anyone has had this issue and can shed some insight as to how to get the date to sort correctly. SELECT u.url_id, url, title, descripti...

How to sort a bunch of files alphabetically, recursively

On Ubuntu, I have a bunch of files in a tree all called 'output.txt'. For each file I want to sort the lines alphabetically with 'sort'. I considered find . -name output.txt -exec sort{} \; but this outputs the sorted lines to the console rather than updating the original files which is what I want. ...