Solved

Most efficient Structures for sorting

Posted on 2006-06-08
3
271 Views
Last Modified: 2010-04-16
What is the most efficient structure in C# for sorting between various types

For example I have

Strings
Integers
Booleans

As opposed to having them all scattered I want to sort my structure so that I have all strings then integers then booleans.

I was thinking a list would be the simplest solution.
0
Comment
Question by:directxBOB
3 Comments
 
LVL 5

Expert Comment

by:t_itanium
ID: 16867794
try to use the GetType property ...and sort according to it..

cheers
0
 
LVL 11

Accepted Solution

by:
anyoneis earned 250 total points
ID: 16867816
Do they have to go into the same structure? Why not have three separate structures, one for each type? The reason this comes to mind is that if you store all of these together, you are going to have to store objects, and that means you will be boxing and unboxing integers and booleans.

Of course, if they are in the same structure already, that won't be any additional overhead. And the sorting algorithm shouldn't have to box/unbox, so maybe that's not a problem.

What about a simple array of objects?

David
0
 
LVL 9

Assisted Solution

by:pallosp
pallosp earned 250 total points
ID: 16868236
If you store them in an ArrayList, the time complexity of the sorting is
   - 2*n*log2(n) GetType calls
   - n*log2(n) type comparisons
   - n*log2(n) value comparisons
   - 2*n*log2(n) boxings
If you use 3 generic lists for each type
   - n GetType calls and n boxings for distributing the elements into 3 lists
   - n/3 * log2(n/3) value comparisons for each list
   - n boxings for putting all together in 1 list

I think sorting using generic lists is 2-3 times faster.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
ConsoleSql 1 22
How to Get total minutes between two hours 4 27
Performance  Html.BeginForm vs jQuery 3 16
C# TextBox 11 16
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now